本文整理汇总了PHP中ParserOptions::setRemoveComments方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::setRemoveComments方法的具体用法?PHP ParserOptions::setRemoveComments怎么用?PHP ParserOptions::setRemoveComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserOptions
的用法示例。
在下文中一共展示了ParserOptions::setRemoveComments方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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: execute
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: sandboxParse
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;
}