コード例 #1
0
ファイル: Parser.php プロジェクト: h4ck3rm1k3/mediawiki
 /**
  * Helper function for parse() that transforms wiki markup into
  * HTML. Only called for $mOutputType == self::OT_HTML.
  *
  * @private
  *
  * @param $text string
  * @param $isMain bool
  * @param $frame bool
  *
  * @return string
  */
 function internalParse($text, $isMain = true, $frame = false)
 {
     wfProfileIn(__METHOD__);
     $origText = $text;
     # Hook to suspend the parser in this state
     if (!wfRunHooks('ParserBeforeInternalParse', array(&$this, &$text, &$this->mStripState))) {
         wfProfileOut(__METHOD__);
         return $text;
     }
     # if $frame is provided, then use $frame for replacing any variables
     if ($frame) {
         # use frame depth to infer how include/noinclude tags should be handled
         # depth=0 means this is the top-level document; otherwise it's an included document
         if (!$frame->depth) {
             $flag = 0;
         } else {
             $flag = Parser::PTD_FOR_INCLUSION;
         }
         $dom = $this->preprocessToDom($text, $flag);
         $text = $frame->expand($dom);
     } else {
         # if $frame is not provided, then use old-style replaceVariables
         $text = $this->replaceVariables($text);
     }
     wfRunHooks('InternalParseBeforeSanitize', array(&$this, &$text, &$this->mStripState));
     $text = Sanitizer::removeHTMLtags($text, array(&$this, 'attributeStripCallback'), false, array_keys($this->mTransparentTagHooks));
     wfRunHooks('InternalParseBeforeLinks', array(&$this, &$text, &$this->mStripState));
     # Tables need to come after variable replacement for things to work
     # properly; putting them before other transformations should keep
     # exciting things like link expansions from showing up in surprising
     # places.
     $text = $this->doTableStuff($text);
     $text = preg_replace('/(^|\\n)-----*/', '\\1<hr />', $text);
     $text = $this->doDoubleUnderscore($text);
     $text = $this->doHeadings($text);
     if ($this->mOptions->getUseDynamicDates()) {
         $df = DateFormatter::getInstance();
         $text = $df->reformat($this->mOptions->getDateFormat(), $text);
     }
     $text = $this->replaceInternalLinks($text);
     $text = $this->doAllQuotes($text);
     $text = $this->replaceExternalLinks($text);
     # replaceInternalLinks may sometimes leave behind
     # absolute URLs, which have to be masked to hide them from replaceExternalLinks
     $text = str_replace($this->mUniqPrefix . 'NOPARSE', '', $text);
     $text = $this->doMagicLinks($text);
     $text = $this->formatHeadings($text, $origText, $isMain);
     wfProfileOut(__METHOD__);
     return $text;
 }