예제 #1
0
 /**
  * Do various kinds of initialisation on the first call of the parser
  */
 function firstCallInit()
 {
     parent::__construct();
     if (!$this->mFirstCall) {
         return;
     }
     $this->mFirstCall = false;
     wfProfileIn(__METHOD__);
     $this->setHook('pre', array($this, 'renderPreTag'));
     CoreParserFunctions::register($this);
     CoreLinkFunctions::register($this);
     $this->initialiseVariables();
     wfRunHooks('ParserFirstCallInit', array(&$this));
     wfProfileOut(__METHOD__);
 }
예제 #2
0
 function replaceInternalLinksCallback($parser, $holders, $markers, $titleText, $paramText)
 {
     wfProfileIn(__METHOD__);
     $wt = isset($paramText) ? "[[{$titleText}|{$paramText}]]" : "[[{$titleText}]]";
     wfProfileIn(__METHOD__ . "-misc");
     # Don't allow internal links to pages containing
     # PROTO: where PROTO is a valid URL protocol; these
     # should be external links.
     if (preg_match('/^\\b(?:' . wfUrlProtocols() . ')/', $titleText)) {
         wfProfileOut(__METHOD__);
         return $wt;
     }
     # Make subpage if necessary
     if ($this->areSubpagesAllowed()) {
         $titleText = $this->maybeDoSubpageLink($titleText, $paramText);
     }
     # Check for a leading colon and strip it if it is there
     $leadingColon = $titleText[0] == ':';
     if ($leadingColon) {
         $titleText = substr($titleText, 1);
     }
     wfProfileOut(__METHOD__ . "-misc");
     # Make title object
     wfProfileIn(__METHOD__ . "-title");
     $title = Title::newFromText($this->mStripState->unstripNoWiki($titleText));
     if (!$title) {
         wfProfileOut(__METHOD__ . "-title");
         wfProfileOut(__METHOD__);
         return $wt;
     }
     $ns = $title->getNamespace();
     wfProfileOut(__METHOD__ . "-title");
     # Default for Namespaces is a default link
     # ToDo: Default for patterns is plain wikitext
     $return = true;
     if (isset($this->mLinkHooks[$ns])) {
         list($callback, $flags) = $this->mLinkHooks[$ns];
         if ($flags & SLH_PATTERN) {
             $args = array($parser, $holders, $markers, $titleText, &$paramText, &$leadingColon);
         } else {
             $args = array($parser, $holders, $markers, $title, $titleText, &$paramText, &$leadingColon);
         }
         # Workaround for PHP bug 35229 and similar
         if (!is_callable($callback)) {
             throw new MWException("Tag hook for namespace {$ns} is not callable\n");
         }
         $return = call_user_func_array($callback, $args);
     }
     if ($return === true) {
         # True (treat as plain link) was returned, call the defaultLinkHook
         $return = CoreLinkFunctions::defaultLinkHook($parser, $holders, $markers, $title, $titleText, $paramText, $leadingColon);
     }
     if ($return === false) {
         # False (no link) was returned, output plain wikitext
         # Build it again as the hook is allowed to modify $paramText
         $return = isset($paramText) ? "[[{$titleText}|{$paramText}]]" : "[[{$titleText}]]";
     }
     # Content was returned, return it
     wfProfileOut(__METHOD__);
     return $return;
 }