示例#1
0
文件: ApiHelp.php 项目: paladox/2
 /**
  * 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();
 }
 public function getDoc()
 {
     $this->hasDoc = true;
     return parent::getDoc();
 }