/**
  * initialize various variables and generate the template
  * @param OutputPage $out optional parameter: The OutputPage Obj.
  */
 public function outputPage(OutputPage $out = null)
 {
     // This might seem weird but now the meaning of 'mobile' is morphing to mean 'minerva skin'
     // FIXME: Explore disabling this via a user preference and see what explodes
     // Important: This must run before outputPage which generates script and style tags
     // If run later incompatible desktop code will leak into Minerva.
     $out = $this->getOutput();
     $out->setTarget('mobile');
     if ($this->isMobileMode) {
         // FIXME: Merge these hooks?
         // EnableMobileModules is deprecated; Use ResourceLoader instead,
         // see https://www.mediawiki.org/wiki/ResourceLoader#Mobile
         Hooks::run('EnableMobileModules', array($out, $this->getMode()));
         Hooks::run('BeforePageDisplayMobile', array(&$out));
     }
     parent::outputPage();
 }
예제 #2
0
 function outputPage(OutputPage $out)
 {
     $content = $out->mBodytext;
     //<div class="rellink relarticle mainarticle">Main article: Geography of Chicago</div>
     // remove links to disemb. and other (if no link inside)
     preg_match_all('/<div class="(rellink|detail|homonymie|dablink|detail principal)[^"]*?">.*?<\\/div>/s', $content, $matches);
     foreach ($matches[0] as $match) {
         // remove only html code without links or latex generated mathematics images
         if (!preg_match("/.*?<a.*?/s", $match) && !preg_match("/.*?<img class=\"tex\".*?/s", $match) && !preg_match("/.*?texhtml.*?/s", $match)) {
             $content = str_replace($match, "", $content);
         }
     }
     // remove return cariage after (sub-)title
     $content = str_replace("<p><br />", "<p>", $content);
     // remove empty paragraph
     $content = str_replace("<p><br /></p>", "", $content);
     $content = str_replace("<p></p>", "", $content);
     // other type of useless html
     $content = str_replace('<p><font class="metadata"><br /></font></p>', "", $content);
     // remove empty chapter/paragraph/...
     // <p><a name="Monotonicity" id="Monotonicity"></a></p>
     // <h3><span class="mw-headline">Monotonicity</span></h3>
     // <p><a name="Conservativity" id="Conservativity"></a></p>
     // <h3><span class="mw-headline">Conservativity</span></h3>
     // <h2 id="Altri_progetti"> <span class="mw-headline">Altri progetti</span></h2>
     // <h2 id="Collegamenti_esterni"> <span class="mw-headline">Collegamenti esterni</span></h2>
     $offset = 0;
     while (preg_match('/(<p><a name=\\"[^\\"]*\\" id=\\"[^\\"]*\\"><\\/a><\\/p>[\\n\\r\\t]<h|<h)([\\d])([^>]*>[ ]*<span[^>]+?>.*?<\\/span><\\/h[\\d]>[\\n\\r\\t]*)(<p><a name=\\"[^\\"]*\\" id=\\"[^\\"]*\\"><\\/a><\\/p>[\\n\\r\\t]<h|<h)([\\d])([^>]*>[ ]*<span class=\\"[^\\"]*\\">.*?<\\/span><\\/h[\\d]>)/', $content, $matches, PREG_OFFSET_CAPTURE, $offset) && count($matches)) {
         // set the offset for the future
         $offset = $matches[0][1] + 1;
         // exlude the case of under chapter
         if ($matches[2][0] >= $matches[5][0]) {
             // remove the empty paragraph
             $toRemove = $matches[1][0] . $matches[2][0] . $matches[3][0];
             $content = str_replace($toRemove, "", $content);
             // remove the index entry
             preg_match('/<p><a name=\\"([^\\"]*)\\"/', $toRemove, $match);
             $anchorName = $match[1];
             // new by it.mirror.kiwix.org
             if ($anchorName == "") {
                 preg_match('/id=\\"([^\\"]*)\\"/', $toRemove, $match);
                 $anchorName = $match[1];
             }
             // get sumary index number
             preg_match("/<li.*?#{$anchorName}.*?<span class=\"tocnumber\">([\\d\\.]*)<\\/span>.*?<\\/li>/", $content, $match);
             $indexNumber = $match[1];
             // remove index line
             $content = str_replace($match[0], "", $content);
             // update following summary indexes
             $indexNumbers = explode('.', $indexNumber);
             $last = $indexNumbers[count($indexNumbers) - 1];
             $prefix = substr($indexNumber, 0, strlen($indexNumber) - strlen($last));
             $last++;
             while (preg_match("/(<span class=\"tocnumber\">{$prefix})({$last})(<\\/span>)/", $content, $match)) {
                 $content = str_replace($match[0], $match[1] . ($last - 1) . $match[3], $content);
                 $last++;
             }
         }
     }
     // remove last empty chapter/paragraph/...
     // <h2> <span class="mw-headline">Enlaces externos</span></h2>
     //  <!-- end content -->
     $offset = 0;
     if (preg_match('/(<p><a name=\\"[^\\"]*\\" id=\\"[^\\"]*\\"><\\/a><\\/p>[\\n\\r\\t]<h|<h)([\\d])(>[ ]*<span[^>]+?>.*?<\\/span><\\/h[\\d]>[\\n\\r\\t]*)(\\<\\!\\-\\-\\ |\\<br\\/\\>\\<div\\ class\\=\\"kf\\"|\\<div\\ class\\=\\"kf\\")/', $content, $matches, PREG_OFFSET_CAPTURE, $offset) && count($matches)) {
         // set the offset for the future
         $offset = $matches[0][2] + 1;
         // remove the empty paragraph
         $toRemove = $matches[1][0] . $matches[2][0] . $matches[3][0];
         $content = str_replace($toRemove, "", $content);
         // remove the index entry
         preg_match('/id=\\"([^\\"]*)\\"/', $toRemove, $match);
         $anchorName = $match[1];
         // get sumary index number
         preg_match("/<li.*?#{$anchorName}.*?<span class=\"tocnumber\">([\\d\\.]*)<\\/span>.*?<\\/li>/", $content, $match);
         $indexNumber = $match[1];
         // remove index line
         $content = str_replace($match[0], "", $content);
         // update following summary indexes
         $indexNumbers = explode('.', $indexNumber);
         $last = $indexNumbers[count($indexNumbers) - 1];
         $prefix = substr($indexNumber, 0, strlen($indexNumber) - strlen($last));
         $last++;
         while (preg_match("/(<span class=\"tocnumber\">{$prefix})({$last})(<\\/span>)/", $content, $match)) {
             $content = str_replace($match[0], $match[1] . ($last - 1) . $match[3], $content);
             $last++;
         }
     }
     // remove timeline image map <img usemap="#1e85951432e89de2bc508a5b1c7eb174" src="/images/timeline/1e85951432e89de2bc508a5b1c7eb174.png">
     while (preg_match("/(<img )(usemap=\"\\#)([^\"]+)(\" )(src=\".*timeline.*\")/", $content, $match)) {
         // remove map call in img tag
         $content = str_replace($match[0], "<br/>" . $match[1] . $match[5], $content);
         $mapId = $match[3];
         // remove map itself
         if (preg_match("/<map name=\"{$mapId}\">.*?<\\/map>/s", $content, $match2)) {
             $content = str_replace($match2[0], "", $content);
         }
     }
     // remove <strong class="selflink">*</strong>
     while (preg_match("/(<strong class=\"selflink\">)(.*?)(<\\/strong>)/", $content, $match)) {
         $content = str_replace($match[0], $match[2], $content);
         $last++;
     }
     // remove imagemap "magnify link", for example:
     // <a href="../../../../articles/l/i/m/File%7ELimburg-Position.png_b699.html" style="position: absolute; top: 0px; left: 0px;">
     // <img alt="About this image" src="../../../../../extensions/ImageMap/desc-20.png" style="border: medium none ;"></a>
     while (preg_match("/<a href=[^>]*><img[^>]*About this image[^>]*><\\/a>/", $content, $match)) {
         $content = str_replace($match[0], "", $content);
         $last++;
     }
     // remove edit sections
     while (preg_match("/<span class=\"editsection\">\\[<a.*<\\/a>\\]<\\/span>/", $content, $match)) {
         $content = str_replace($match[0], "", $content);
         $last++;
     }
     // Remove empty links (red links) in imagemaps
     while (preg_match("/<area\\ .*href=\"\".*\\/>/", $content, $match)) {
         $content = str_replace($match[0], "", $content);
         $last++;
     }
     // print out
     $out->mBodytext = $content;
     SkinTemplate::outputPage($out);
 }