本文整理汇总了PHP中ParserOptions::setTemplateCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::setTemplateCallback方法的具体用法?PHP ParserOptions::setTemplateCallback怎么用?PHP ParserOptions::setTemplateCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserOptions
的用法示例。
在下文中一共展示了ParserOptions::setTemplateCallback方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$contLang = Language::factory('en');
$this->setMwGlobals(array('wgShowDBErrorBacktrace' => true, 'wgLanguageCode' => 'en', 'wgContLang' => $contLang, 'wgLang' => Language::factory('en'), 'wgMemc' => new EmptyBagOStuff(), 'wgAlwaysUseTidy' => false, 'wgCleanSignatures' => true));
$this->options = ParserOptions::newFromUserAndLang(new User(), $contLang);
$this->options->setTemplateCallback(array(__CLASS__, 'statelessFetchTemplate'));
$this->parser = new Parser();
MagicWord::clearCache();
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$contLang = Language::factory('en');
$this->setMwGlobals(['wgShowDBErrorBacktrace' => true, 'wgCleanSignatures' => true]);
$this->setUserLang('en');
$this->setContentLang($contLang);
// FIXME: This test should pass without setting global content language
$this->options = ParserOptions::newFromUserAndLang(new User(), $contLang);
$this->options->setTemplateCallback([__CLASS__, 'statelessFetchTemplate']);
$this->parser = new Parser();
MagicWord::clearCache();
}
示例3: 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;
}
}
示例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: 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;
}
示例6: getEngine
function getEngine()
{
if (!$this->engine) {
$parser = new Parser();
$options = new ParserOptions();
$options->setTemplateCallback(array($this, 'templateCallback'));
$parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
$class = "Scribunto_{$this->engineName}Engine";
$this->engine = new $class(self::$engineConfigurations[$this->engineName] + array('parser' => $parser));
$this->engine->setTitle($parser->getTitle());
}
return $this->engine;
}
示例7: execute
function execute()
{
global $wgParser, $wgUser;
$wgUser = new PPFuzzUser();
$wgUser->mName = 'Fuzz';
$wgUser->mFrom = 'name';
$wgUser->ppfz_test = $this;
$options = new ParserOptions();
$options->setTemplateCallback(array($this, 'templateHook'));
$options->setTimestamp(wfTimestampNow());
$this->output = call_user_func(array($wgParser, $this->entryPoint), $this->mainText, $this->title->getPrefixedText(), $options);
return $this->output;
}
示例8: wfSetParserOptions
function wfSetParserOptions()
{
global $wgParserOptions, $wgParser;
$wgParserOptions = new ParserOptions(null);
$wgParserOptions->setEditSection(false);
$wgParserOptions->setTemplateCallback(array('ParserOffline', 'fetchTemplate'));
$wgParser->Options($wgParserOptions);
#$wgParser->disableCache();
return $wgParserOptions;
}
示例9: testHandleRecordTag
function testHandleRecordTag()
{
global $wgDataTransclusionSources;
$data[] = array("name" => "foo", "id" => "3", "info" => '<test>&[[X]]\'', "url" => 'http://test.org/', "evil" => 'javascript:alert("evil")');
$spec = array('class' => 'FakeDataTransclusionSource', 'data' => $data, 'keyFields' => 'name,id', 'fieldNames' => 'id,name,info,url,evil', 'defaultKey' => 'id');
$wgDataTransclusionSources['FOO'] = $spec;
global $wgParser;
$title = Title::newFromText("Dummy");
$options = new ParserOptions();
$options->setTemplateCallback('DataTransclusionTest::getTemplate');
$text = 'xx <record source="FOO" id=3 extra="Hallo">Test</record> xx';
$wgParser->parse($text, $title, $options);
$html = $wgParser->getOutput()->getText();
$this->assertEquals('<p>xx FOO:<b>3</b>|foo|Hallo|<test>&[[X]]'|<a href="http://test.org/" class="external text" rel="nofollow">link</a>|[javascript:alert("evil") click me] xx' . "\n" . '</p>', $html);
// XXX: should be more lenient wrt whitespace
$templates = $wgParser->getOutput()->getTemplates();
$this->assertTrue(isset($templates[NS_TEMPLATE]['Test']));
}