示例#1
0
 /**
  * @throws MWException
  * @param array $m
  * @return HTML|string
  */
 public function magicLinkCallback($m)
 {
     if (isset($m[1]) && $m[1] !== '') {
         # Skip anchor
         return $m[0];
     } elseif (isset($m[2]) && $m[2] !== '') {
         # Skip HTML element
         return $m[0];
     } elseif (isset($m[3]) && $m[3] !== '') {
         # Free external link
         return $this->makeFreeExternalLink($m[0], strlen($m[4]));
     } elseif (isset($m[5]) && $m[5] !== '') {
         # RFC or PMID
         if (substr($m[0], 0, 3) === 'RFC') {
             if (!$this->mOptions->getMagicRFCLinks()) {
                 return $m[0];
             }
             $keyword = 'RFC';
             $urlmsg = 'rfcurl';
             $cssClass = 'mw-magiclink-rfc';
             $id = $m[5];
         } elseif (substr($m[0], 0, 4) === 'PMID') {
             if (!$this->mOptions->getMagicPMIDLinks()) {
                 return $m[0];
             }
             $keyword = 'PMID';
             $urlmsg = 'pubmedurl';
             $cssClass = 'mw-magiclink-pmid';
             $id = $m[5];
         } else {
             throw new MWException(__METHOD__ . ': unrecognised match type "' . substr($m[0], 0, 20) . '"');
         }
         $url = wfMessage($urlmsg, $id)->inContentLanguage()->text();
         return Linker::makeExternalLink($url, "{$keyword} {$id}", true, $cssClass, [], $this->mTitle);
     } elseif (isset($m[6]) && $m[6] !== '' && $this->mOptions->getMagicISBNLinks()) {
         # ISBN
         $isbn = $m[6];
         $space = self::SPACE_NOT_NL;
         #  non-newline space
         $isbn = preg_replace("/{$space}/", ' ', $isbn);
         $num = strtr($isbn, ['-' => '', ' ' => '', 'x' => 'X']);
         return $this->getLinkRenderer()->makeKnownLink(SpecialPage::getTitleFor('Booksources', $num), "ISBN {$isbn}", ['class' => 'internal mw-magiclink-isbn', 'title' => false]);
     } else {
         return $m[0];
     }
 }