Пример #1
0
 /**
  * Replace Special:ApiHelp links with links to api.php
  *
  * @param string $html
  * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
  * @param array $localModules Keys are modules to link within the current page, values are ignored
  * @return string
  */
 public static function fixHelpLinks($html, $helptitle = null, $localModules = array())
 {
     $formatter = new HtmlFormatter($html);
     $doc = $formatter->getDoc();
     $xpath = new DOMXPath($doc);
     $nodes = $xpath->query('//a[@href][not(contains(@class,\'apihelp-linktrail\'))]');
     foreach ($nodes as $node) {
         $href = $node->getAttribute('href');
         do {
             $old = $href;
             $href = rawurldecode($href);
         } while ($old !== $href);
         if (preg_match('!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m)) {
             if (isset($localModules[$m[1]])) {
                 $href = $m[2] === '' ? '#' . $m[1] : $m[2];
             } elseif ($helptitle !== null) {
                 $href = Title::newFromText(str_replace('$1', $m[1], $helptitle) . $m[2])->getFullURL();
             } else {
                 $href = wfAppendQuery(wfScript('api'), array('action' => 'help', 'modules' => $m[1])) . $m[2];
             }
             $node->setAttribute('href', $href);
             $node->removeAttribute('title');
         }
     }
     return $formatter->getText();
 }
 /**
  * Performs final transformations to mobile format and returns resulting HTML
  *
  * @param DOMElement|string|null $element ID of element to get HTML from or
  *   false to get it from the whole tree
  * @return string Processed HTML
  */
 public function getText($element = null)
 {
     if ($this->mainPage) {
         $element = $this->parseMainPage($this->getDoc());
     }
     $html = parent::getText($element);
     return $html;
 }