本文整理汇总了PHP中ParserOptions类的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions类的具体用法?PHP ParserOptions怎么用?PHP ParserOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParserOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
function setUp()
{
parent::setUp();
$parser = new Parser();
$options = new ParserOptions();
$options->setTemplateCallback(array($this, 'templateCallback'));
$parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
try {
$engine = new Scribunto_LuaSandboxEngine(array('parser' => $parser) + $this->sandboxOpts);
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
$this->engines['LuaSandbox'] = $engine;
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$this->markTestSkipped("LuaSandbox interpreter not available");
return;
}
try {
$engine = new Scribunto_LuaStandaloneEngine(array('parser' => $parser) + $this->standaloneOpts);
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
$this->engines['LuaStandalone'] = $engine;
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$this->markTestSkipped("LuaStandalone interpreter not available");
return;
}
}
示例2: wfSetParserOptions
function wfSetParserOptions()
{
global $wgParserOptions, $wgParser;
$wgParserOptions = new ParserOptions(null);
$wgParserOptions->setEditSection(false);
$wgParser->Options($wgParserOptions);
return $wgParserOptions;
}
示例3: msgWikiNoEdit
/**
* Like msgWiki() but it ensures edit section links are never shown.
*
* Needed for Mediawiki 1.19 & 1.20 due to bug 36975:
* https://bugzilla.wikimedia.org/show_bug.cgi?id=36975
*
* @param $message Name of wikitext message to return
*/
function msgWikiNoEdit($message)
{
global $wgOut;
global $wgParser;
$popts = new ParserOptions();
$popts->setEditSection(false);
$text = wfMessage($message)->text();
return $wgParser->parse($text, $wgOut->getTitle(), $popts)->getText();
}
示例4: runTemplateTransclusion
/**
* Helper method for processing a template transclusion by simulating template
* expensions using a callback to avoid having to integrate DB read/write
* process in order to access a Template
*
* @note Part of the routine has been taken from MW's ExtraParserTest
*
* @return text
*/
private function runTemplateTransclusion(Title $title, $text, $return)
{
$parser = new \Parser();
$options = new \ParserOptions();
$options->setTemplateCallback(function ($title, $parser = false) use($return) {
$text = $return;
$deps = array();
return array('text' => $text, 'finalTitle' => $title, 'deps' => $deps);
});
return $parser->preprocess($text, $title, $options);
}
开发者ID:WolfgangFahl,项目名称:SemanticMediaWiki,代码行数:20,代码来源:InTextAnnotationParserTemplateTransclusionTest.php
示例5: 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);
}
}
示例6: makeEngine
private function makeEngine($class, $opts)
{
$parser = new Parser();
$options = new ParserOptions();
$options->setTemplateCallback(array($this, 'templateCallback'));
$parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
$engine = new $class(array('parser' => $parser) + $opts);
$parser->scribunto_engine = $engine;
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
return $engine;
}
示例7: genParserOptions
function genParserOptions()
{
global $wgUser;
$this->mParserOptions = ParserOptions::newFromUser($wgUser);
$this->mParserOptions->setDateFormat(MW_DATE_DEFAULT);
$this->mParserOptions->setEditSection(false);
}
示例8: index
public function index()
{
$title = Title::newFromText('Version', NS_SPECIAL);
$popts = ParserOptions::newFromContext(RequestContext::getMain());
$this->wg->Title = $title;
$this->specialPage->setHeaders();
$softwareListPrepped = array();
foreach ($this->version->getSoftwareList() as $key => $val) {
$softwareListPrepped[$this->wg->Parser->parse($key, $title, $popts)->getText()] = $this->wg->Parser->parse($val, $title, $popts)->getText();
}
$this->setVal('copyRightAndAuthorList', $this->wg->Parser->parse($this->version->getCopyrightAndAuthorList(), $title, $popts)->getText());
$this->setVal('softwareInformation', $this->wg->Parser->parse($this->version->softwareInformation(), $title, $popts)->getText());
$this->setVal('extensionCredit', $this->wg->Parser->parse($this->version->getExtensionCredits(), $title, $popts)->getText());
$this->setVal('ip', str_replace('--', ' - ', htmlspecialchars($this->getContext()->getRequest()->getIP())));
$this->setVal('wikiaCodeMessage', wfMessage('wikia-version-code')->escaped());
$this->setVal('wikiaCodeVersion', $this->version->getWikiaCodeVersion());
$this->setVal('wikiaConfigMessage', wfMessage('wikia-version-config')->escaped());
$this->setVal('wikiaConfigVersion', $this->version->getWikiaConfigVersion());
$this->setVal('versionLicenseMessage', wfMessage('version-license')->escaped());
$this->setVal('versionLicenseInfoMessage', wfMessage('version-license-info')->parse());
$this->setVal('versionSoftwareMessage', wfMessage('version-software')->escaped());
$this->setVal('versionSoftwareProductMessage', wfMessage('version-software-product')->escaped());
$this->setVal('versionSoftwareVersionMessage', wfMessage('version-software-version')->escaped());
$this->setVal('versionSoftwareList', $softwareListPrepped);
}
示例9: getMessagesFormatted
function getMessagesFormatted($severity = self::MESSAGE_WARNING, $header = null)
{
global $wgTitle, $wgUser;
$ret = '';
foreach ($this->mMessages as $message) {
if ($message[1] <= $severity) {
$ret .= '* ' . $message[0] . "\n";
}
}
if ($ret != '') {
if (!$this->mParser) {
$parser = new Parser();
}
if ($header == null) {
$header = '';
} elseif ($header != '') {
$header = Html::rawElement('div', array('class' => 'heading'), $header);
}
$ret = Html::rawElement('div', array('class' => 'messages'), $header . "\n" . $ret);
$ret = $parser->parse($ret, $wgTitle, ParserOptions::newFromUser($wgUser));
} else {
$ret = null;
}
return $ret;
}
示例10: genParserOptions
function genParserOptions()
{
global $wgUser;
$this->mParserOptions = ParserOptions::newFromUser($wgUser);
$this->mParserOptions->setDateFormat('default');
$this->mParserOptions->setEditSection(false);
}
示例11: initialise
function initialise(&$memCached, $useDB, $expiry, $memcPrefix)
{
$fname = 'MessageCache::initialise';
wfProfileIn($fname);
$this->mUseCache = !is_null($memCached);
$this->mMemc =& $memCached;
$this->mDisable = !$useDB;
$this->mExpiry = $expiry;
$this->mDisableTransform = false;
$this->mMemcKey = $memcPrefix . ':messages';
$this->mKeys = false;
# initialised on demand
$this->mInitialised = true;
wfProfileIn($fname . '-parseropt');
$this->mParserOptions = ParserOptions::newFromUser($u = NULL);
wfProfileOut($fname . '-parseropt');
wfProfileIn($fname . '-parser');
$this->mParser = new Parser();
wfProfileOut($fname . '-parser');
# When we first get asked for a message,
# then we'll fill up the cache. If we
# can return a cache hit, this saves
# some extra milliseconds
$this->mDeferred = true;
wfProfileOut($fname);
}
示例12: sandboxParse
function sandboxParse($wikiText){
global $wgUser;
$myParser = new Parser();
$myParserOptions = ParserOptions::newFromUser( $wgUser );
$result = $myParser->parse($wikiText, $this->getTitle(), $myParserOptions);
return $result->getText();
}
示例13: setUp
function setUp()
{
global $wgContLang, $wgUser, $wgLanguageCode;
$wgContLang = Language::factory($wgLanguageCode);
$this->popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
$this->pcache = ParserCache::singleton();
}
示例14: getJsonFormatForArticle
/**
* @param \Article $article
* @return JsonFormatNode
*/
public function getJsonFormatForArticle(\Article $article)
{
$measurement = \Wikia\Measurements\Time::start([__CLASS__, __METHOD__]);
$html = $article->getPage()->getParserOutput(\ParserOptions::newFromContext($this->requestContext))->getText();
$measurement->stop();
return $this->htmlParser->parse($html);
}
示例15: checkOptions
public function checkOptions()
{
if ($this->hasOption('save-failed')) {
$this->saveFailed = $this->getOption('save-failed');
}
$this->stripParametersEnabled = $this->hasOption('strip-parameters');
$this->showParsedOutput = $this->hasOption('show-parsed-output');
$this->showDiff = $this->hasOption('show-diff');
if ($this->showDiff) {
$bin = $this->getOption('diff-bin', getenv('DIFF'));
if ($bin != '') {
global $wgDiff;
$wgDiff = $bin;
}
}
$user = new User();
$this->options = ParserOptions::newFromUser($user);
if ($this->hasOption('tidy')) {
global $wgUseTidy;
if (!$wgUseTidy) {
$this->error('Tidy was requested but $wgUseTidy is not set in LocalSettings.php', true);
}
$this->options->setTidy(true);
}
$this->failed = 0;
}