本文整理汇总了PHP中ParserOptions::newFromUserAndLang方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::newFromUserAndLang方法的具体用法?PHP ParserOptions::newFromUserAndLang怎么用?PHP ParserOptions::newFromUserAndLang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserOptions
的用法示例。
在下文中一共展示了ParserOptions::newFromUserAndLang方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
function setUp()
{
global $wgContLang, $wgUser, $wgLanguageCode;
$wgContLang = Language::factory($wgLanguageCode);
$this->popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
$this->pcache = ParserCache::singleton();
}
示例2: setUp
protected function setUp()
{
global $wgParserConf, $wgContLang;
parent::setUp();
$this->mOptions = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$name = isset($wgParserConf['preprocessorClass']) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM';
$this->mPreprocessor = new $name($this);
}
示例3: testBadFunctionTagHooks
/**
* @dataProvider provideBadNames
* @expectedException MWException
* @covers Parser::setFunctionTagHook
*/
public function testBadFunctionTagHooks($tag)
{
global $wgParserConf, $wgContLang;
$parser = new Parser($wgParserConf);
$parser->setFunctionTagHook($tag, array($this, 'functionTagCallback'), Parser::SFH_OBJECT_ARGS);
$parser->parse("Foo<{$tag}>Bar</{$tag}>Baz", Title::newFromText('Test'), ParserOptions::newFromUserAndLang(new User(), $wgContLang));
$this->fail('Exception not thrown.');
}
示例4: testPreloadTransform
/**
* @dataProvider dataPreloadTransform
*/
public function testPreloadTransform($text, $expected)
{
global $wgContLang;
$options = ParserOptions::newFromUserAndLang($this->context->getUser(), $wgContLang);
$content = $this->newContent($text);
$content = $content->preloadTransform($this->context->getTitle(), $options);
$this->assertEquals($expected, $content->getNativeData());
}
示例5: setUp
protected function setUp()
{
global $wgLanguageCode, $wgUser;
parent::setUp();
$langObj = Language::factory($wgLanguageCode);
$this->setMwGlobals(array('wgContLang' => $langObj, 'wgUseDynamicDates' => true));
$this->popts = ParserOptions::newFromUserAndLang($wgUser, $langObj);
$this->pcache = ParserCache::singleton();
}
示例6: setUp
protected function setUp()
{
global $wgContLang;
parent::setUp();
$this->mOptions = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$this->mPreprocessors = [];
foreach (self::$classNames as $className) {
$this->mPreprocessors[$className] = new $className($this);
}
}
示例7: 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();
}
示例8: setUp
protected function setUp()
{
global $wgContLang;
parent::setUp();
$this->testParserOptions = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$this->testParser = new Parser();
$this->testParser->Options($this->testParserOptions);
$this->testParser->clearState();
$this->title = Title::newFromText('Preload Test');
}
示例9: runForTitleInternal
public static function runForTitleInternal(Title $title, Revision $revision, $fname)
{
global $wgParser, $wgContLang;
wfProfileIn($fname . '-parse');
$options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$parserOutput = $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getId());
wfProfileOut($fname . '-parse');
wfProfileIn($fname . '-update');
$updates = $parserOutput->getSecondaryDataUpdates($title, false);
DataUpdate::runUpdates($updates);
wfProfileOut($fname . '-update');
}
示例10: 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();
}
示例11: setUp
/** setup a basic parser object */
protected function setUp()
{
parent::setUp();
$contLang = Language::factory('en');
$this->setMwGlobals(array('wgLanguageCode' => 'en', 'wgContLang' => $contLang));
$this->testParser = new Parser();
$this->testParser->Options(ParserOptions::newFromUserAndLang(new User(), $contLang));
# initialize parser output
$this->testParser->clearState();
# Needs a title to do magic word stuff
$title = Title::newFromText('Tests');
$title->mRedirect = false;
# Else it needs a db connection just to check if it's a redirect (when deciding the page language)
$this->testParser->setTitle($title);
}
示例12: makeParserOptions
/**
* Get parser options suitable for rendering and caching the article
*
* @param IContextSource|User|string $context One of the following:
* - IContextSource: Use the User and the Language of the provided
* context
* - User: Use the provided User object and $wgLang for the language,
* so use an IContextSource object if possible.
* - 'canonical': Canonical options (anonymous user with default
* preferences and content language).
*
* @throws MWException
* @return ParserOptions
*/
public function makeParserOptions($context)
{
global $wgContLang, $wgEnableParserLimitReporting;
if ($context instanceof IContextSource) {
$options = ParserOptions::newFromContext($context);
} elseif ($context instanceof User) {
// settings per user (even anons)
$options = ParserOptions::newFromUser($context);
} elseif ($context === 'canonical') {
// canonical settings
$options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
} else {
throw new MWException("Bad context for parser options: {$context}");
}
$options->enableLimitReport($wgEnableParserLimitReporting);
// show inclusion/loop reports
$options->setTidy(true);
// fix bad HTML
return $options;
}
示例13: prepareTextForEdit
/**
* Prepare text which is about to be saved.
* Returns a stdclass with source, pst and output members
* @return bool|object
*/
public function prepareTextForEdit($text, $revid = null, User $user = null)
{
global $wgParser, $wgContLang, $wgUser;
$user = is_null($user) ? $wgUser : $user;
// @TODO fixme: check $user->getId() here???
if ($this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
// Already prepared
return $this->mPreparedEdit;
}
$popts = ParserOptions::newFromUserAndLang($user, $wgContLang);
wfRunHooks('ArticlePrepareTextForEdit', array($this, $popts));
$edit = (object) array();
$edit->revid = $revid;
$edit->newText = $text;
$edit->pst = $wgParser->preSaveTransform($text, $this->mTitle, $user, $popts);
$edit->popts = $this->makeParserOptions('canonical');
$edit->output = $wgParser->parse($edit->pst, $this->mTitle, $edit->popts, true, true, $revid);
$edit->oldText = $this->getRawText();
$this->mPreparedEdit = $edit;
return $edit;
}
示例14: showDiff
/**
* Get a diff between the current contents of the edit box and the
* version of the page we're editing from.
*
* If this is a section edit, we'll replace the section as for final
* save and then make a comparison.
*/
function showDiff()
{
global $wgUser, $wgContLang, $wgParser, $wgOut;
$oldtext = $this->mArticle->getRawText();
$newtext = $this->mArticle->replaceSection($this->section, $this->textbox1, $this->summary, $this->edittime);
wfRunHooks('EditPageGetDiffText', array($this, &$newtext));
$popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
$newtext = $wgParser->preSaveTransform($newtext, $this->mTitle, $wgUser, $popts);
if ($oldtext !== false || $newtext != '') {
$oldtitle = wfMsgExt('currentrev', array('parseinline'));
$newtitle = wfMsgExt('yourtext', array('parseinline'));
$de = new DifferenceEngine($this->mArticle->getContext());
$de->setText($oldtext, $newtext);
$difftext = $de->getDiff($oldtitle, $newtitle);
$de->showDiffStyle();
} else {
$difftext = '';
}
$wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>');
}
示例15: showDiff
/**
* Get a diff between the current contents of the edit box and the
* version of the page we're editing from.
*
* If this is a section edit, we'll replace the section as for final
* save and then make a comparison.
*/
function showDiff()
{
global $wgUser, $wgContLang, $wgOut;
$oldtitlemsg = 'currentrev';
# if message does not exist, show diff against the preloaded default
if ($this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists()) {
$oldtext = $this->mTitle->getDefaultMessageText();
if ($oldtext !== false) {
$oldtitlemsg = 'defaultmessagetext';
$oldContent = $this->toEditContent($oldtext);
} else {
$oldContent = null;
}
} else {
$oldContent = $this->getCurrentContent();
}
$textboxContent = $this->toEditContent($this->textbox1);
$newContent = $this->mArticle->replaceSectionContent($this->section, $textboxContent, $this->summary, $this->edittime);
if ($newContent) {
ContentHandler::runLegacyHooks('EditPageGetDiffText', array($this, &$newContent));
wfRunHooks('EditPageGetDiffContent', array($this, &$newContent));
$popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
$newContent = $newContent->preSaveTransform($this->mTitle, $wgUser, $popts);
}
if ($oldContent && !$oldContent->isEmpty() || $newContent && !$newContent->isEmpty()) {
$oldtitle = wfMessage($oldtitlemsg)->parse();
$newtitle = wfMessage('yourtext')->parse();
if (!$oldContent) {
$oldContent = $newContent->getContentHandler()->makeEmptyContent();
}
if (!$newContent) {
$newContent = $oldContent->getContentHandler()->makeEmptyContent();
}
$de = $oldContent->getContentHandler()->createDifferenceEngine($this->mArticle->getContext());
$de->setContent($oldContent, $newContent);
$difftext = $de->getDiff($oldtitle, $newtitle);
$de->showDiffStyle();
} else {
$difftext = '';
}
$wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>');
}