示例#1
0
 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
0
 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();
 }
 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;
     }
 }
 /**
  * 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);
 }
 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
0
 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
0
 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
0
function wfSetParserOptions()
{
    global $wgParserOptions, $wgParser;
    $wgParserOptions = new ParserOptions(null);
    $wgParserOptions->setEditSection(false);
    $wgParserOptions->setTemplateCallback(array('ParserOffline', 'fetchTemplate'));
    $wgParser->Options($wgParserOptions);
    #$wgParser->disableCache();
    return $wgParserOptions;
}
 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|&lt;test&gt;&amp;&#91;&#91;X&#93;&#93;&#39;|<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']));
 }