コード例 #1
0
 function execute($subpage)
 {
     global $wgRequest, $wgParser, $wgOut;
     $this->setHeaders();
     $this->isNewParser = is_callable(array($wgParser, 'preprocessToDom'));
     $titleStr = $wgRequest->getText('contexttitle');
     $title = Title::newFromText($titleStr);
     $selfTitle = $this->getTitle();
     if (!$title) {
         $title = $selfTitle;
     }
     $input = $wgRequest->getText('input');
     $this->generateXML = $this->isNewParser ? $wgRequest->getBool('generate_xml') : false;
     if (strlen($input)) {
         $this->removeComments = $wgRequest->getBool('removecomments', false);
         $this->removeNowiki = $wgRequest->getBool('removenowiki', false);
         $options = new ParserOptions();
         $options->setRemoveComments($this->removeComments);
         $options->setTidy(true);
         $options->setMaxIncludeSize(self::MAX_INCLUDE_SIZE);
         if ($this->generateXML) {
             $wgParser->startExternalParse($title, $options, OT_PREPROCESS);
             $dom = $wgParser->preprocessToDom($input);
             if (is_callable(array($dom, 'saveXML'))) {
                 $xml = $dom->saveXML();
             } else {
                 $xml = $dom->__toString();
             }
         }
         $output = $wgParser->preprocess($input, $title, $options);
     } else {
         $this->removeComments = $wgRequest->getBool('removecomments', true);
         $this->removeNowiki = $wgRequest->getBool('removenowiki', false);
         $output = false;
     }
     $wgOut->addWikiText(wfMsg('expand_templates_intro'));
     $wgOut->addHTML($this->makeForm($titleStr, $input));
     if ($output !== false) {
         global $wgUseTidy, $wgAlwaysUseTidy;
         if ($this->generateXML) {
             $wgOut->addHTML($this->makeOutput($xml, 'expand_templates_xml_output'));
         }
         $tmp = $this->makeOutput($output);
         if ($this->removeNowiki) {
             $tmp = preg_replace(array('_<nowiki>_', '_</nowiki>_', '_<nowiki */>_'), '', $tmp);
         }
         if ($wgUseTidy && $options->getTidy() || $wgAlwaysUseTidy) {
             $tmp = MWTidy::tidy($tmp);
         }
         $wgOut->addHTML($tmp);
         $this->showHtmlPreview($title, $output, $wgOut);
     }
 }
コード例 #2
0
 public function execute()
 {
     // Cache may vary on $wgUser because ParserOptions gets data from it
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     // Create title for parser
     $title_obj = Title::newFromText($params['title']);
     if (!$title_obj) {
         $title_obj = Title::newFromText('API');
         // default
     }
     $result = $this->getResult();
     // Parse text
     global $wgParser;
     $options = new ParserOptions();
     if ($params['includecomments']) {
         $options->setRemoveComments(false);
     }
     if ($params['generatexml']) {
         $wgParser->startExternalParse($title_obj, $options, OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($params['text']);
         if (is_callable(array($dom, 'saveXML'))) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         $xml_result = array();
         $result->setContent($xml_result, $xml);
         $result->addValue(null, 'parsetree', $xml_result);
     }
     $retval = $wgParser->preprocess($params['text'], $title_obj, $options);
     // Return result
     $retval_array = array();
     $result->setContent($retval_array, $retval);
     $result->addValue(null, $this->getModuleName(), $retval_array);
 }
コード例 #3
0
ファイル: extras.php プロジェクト: Tjorriemorrie/app
function sandboxParse($wikiText)
{
    global $wgTitle, $wgParser, $wgVersion;
    // temporarily replace the global parser
    $old_wgParser = $wgParser;
    $wgParser = new Parser();
    $myParserOptions = new ParserOptions();
    // Setup extension functions for new parser.  This allows things like ParserFunctions to work 1.11.1 or greater
    // THIS DOES NOT WORK IN 1.7.1 AT ALL!!!!
    if (version_compare($wgVersion, "1.11.1", '>=')) {
        /**
         * Wikia change - begin (@author: macbre)
         * Commented out due to BugId:6864
        foreach ( $wgExtensionFunctions as $func )
        {
        	$profName = __METHOD__.'-extensions-'.strval( $func );
        	wfProfileIn( $profName );
        	call_user_func( $func );
        	wfProfileOut( $profName );
        };
        * Wikia change - end
        */
        $myParserOptions->setRemoveComments(true);
    }
    // use some sensible defaults
    $myParserOptions->setTidy(true);
    // do the parsing
    wfRunHooks('custom_SandboxParse', array(&$wikiText));
    $wgTitle = empty($wgTitle) ? new Title() : $wgTitle;
    $result = $wgParser->parse($wikiText, $wgTitle, $myParserOptions);
    /* @var $result ParserOutput */
    $result = $result->getText();
    // restore the global parser
    $wgParser = $old_wgParser;
    // give the result
    return $result;
}