本文整理汇总了PHP中ParserOutput类的典型用法代码示例。如果您正苦于以下问题:PHP ParserOutput类的具体用法?PHP ParserOutput怎么用?PHP ParserOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParserOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getParserOutput
/**
* Override getParserOutput, since we require $title to generate our output
*/
function getParserOutput(Title $title, $revId = null, ParserOptions $otpions = null, $generateHtml = true)
{
$po = new ParserOutput();
if ($generateHtml) {
$po->setText($this->generateHtml($title));
}
return $po;
}
示例2: testGetTemplates
public function testGetTemplates()
{
$title = Title::makeTitle(NS_TEMPLATE, 'Cite_news');
$parserOutput = new ParserOutput();
$parserOutput->addTemplate($title, 10, 100);
$searchDataExtractor = new ParserOutputSearchDataExtractor();
$this->assertEquals(['Template:Cite news'], $searchDataExtractor->getTemplates($parserOutput));
}
示例3: wfWikiAnswersPageTitle
/**
* @param OutputPage $out
* @param ParserOutput $parserOutput
* @return bool
*/
function wfWikiAnswersPageTitle(&$out, $parserOutput)
{
$answerObj = Answer::newFromTitle($out->getTitle());
if ($answerObj->isQuestion()) {
$parserOutput->setTitleText($parserOutput->getTitleText() . wfMsg('?'));
}
return true;
}
示例4: fillParserOutput
/**
* Set the HTML and add the appropriate styles
*
*
* @param Title $title
* @param int $revId
* @param ParserOptions $options
* @param bool $generateHtml
* @param ParserOutput $output
*/
protected function fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
{
if ($generateHtml) {
$output->setText($this->objectTable($this->getJsonData()));
$output->addModuleStyles('mediawiki.content.json');
} else {
$output->setText('');
}
}
示例5: __construct
public function __construct(Title $title, ParserOutput $stableOutput)
{
$this->title = $title;
# Stable version links
$this->sLinks = $stableOutput->getLinks();
$this->sTemplates = $stableOutput->getTemplates();
$this->sImages = $stableOutput->getImages();
$this->sCategories = $stableOutput->getCategories();
}
示例6: fillParserOutput
/**
* Set the HTML and add the appropriate styles
*
*
* @param Title $title
* @param int $revId
* @param ParserOptions $options
* @param bool $generateHtml
* @param ParserOutput $output
*/
protected function fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
{
if ($generateHtml) {
$html = Html::element('pre', array('class' => 'mw-code mw-yaml', 'dir' => 'ltr'), $this->getNativeData());
$output->setText($html);
} else {
$output->setText('');
}
}
示例7: fillParserOutput
protected function fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
{
// FIXME: WikiPage::doEditContent generates parser output before validation.
// As such, native data may be invalid (though output is discarded later in that case).
if ($generateHtml && $this->isValid()) {
$output->setText($this->renderNotebook($this->getNativeData()));
} else {
$output->setText('error');
}
}
示例8: outputPageParserOutput
/**
* OutputPageParserOutput hook handler
* @param OutputPage $out
* @param ParserOutput $parserOutput
* @return type
*/
public static function outputPageParserOutput(OutputPage &$out, ParserOutput $parserOutput)
{
$out->addModuleStyles('ext.articleEmblems');
if (isset($parserOutput->articleEmblems)) {
$emblems = array();
foreach ($parserOutput->articleEmblems as $emblem) {
$emblems[] = '<li class="articleEmblem">' . $emblem . '</li>';
}
$parserOutput->setText('<ul id="articleEmblems" class="noprint">' . implode($emblems) . '</ul>' . $parserOutput->getText());
}
return true;
}
示例9: testExtensionData
/**
* @covers ParserOutput::setExtensionData
* @covers ParserOutput::getExtensionData
*/
public function testExtensionData()
{
$po = new ParserOutput();
$po->setExtensionData("one", "Foo");
$this->assertEquals("Foo", $po->getExtensionData("one"));
$this->assertNull($po->getExtensionData("spam"));
$po->setExtensionData("two", "Bar");
$this->assertEquals("Foo", $po->getExtensionData("one"));
$this->assertEquals("Bar", $po->getExtensionData("two"));
$po->setExtensionData("one", null);
$this->assertNull($po->getExtensionData("one"));
$this->assertEquals("Bar", $po->getExtensionData("two"));
}
示例10: testMergeExternalParserOutputVars
/**
* @dataProvider getParserOutputVars
*/
public function testMergeExternalParserOutputVars($sourceVars, $externalVars, $expectedVars)
{
$parserOutputSource = new ParserOutput();
$parserOutputExternal = new ParserOutput();
foreach ($parserOutputSource::$varsToMerge as $var) {
$parserOutputSource->{$var} = $sourceVars[$var];
$parserOutputExternal->{$var} = $externalVars[$var];
}
$parserOutputSource->mergeExternalParserOutputVars($parserOutputExternal);
foreach ($parserOutputSource::$varsToMerge as $var) {
$this->assertSame($expectedVars[$var], $parserOutputSource->{$var});
}
}
示例11: LinksUpdate
/**
* Constructor
*
* @param Title $title Title of the page we're updating
* @param ParserOutput $parserOutput Output from a full parse of this page
* @param bool $recursive Queue jobs for recursive updates?
*/
function LinksUpdate($title, $parserOutput, $recursive = true)
{
global $wgAntiLockFlags;
if ($wgAntiLockFlags & ALF_NO_LINK_LOCK) {
$this->mOptions = array();
} else {
$this->mOptions = array('FOR UPDATE');
}
$this->mDb = wfGetDB(DB_MASTER);
if (!is_object($title)) {
throw new MWException("The calling convention to LinksUpdate::LinksUpdate() has changed. " . "Please see Article::editUpdates() for an invocation example.\n");
}
$this->mTitle = $title;
$this->mId = $title->getArticleID();
$this->mParserOutput = $parserOutput;
$this->mLinks = $parserOutput->getLinks();
$this->mImages = $parserOutput->getImages();
$this->mTemplates = $parserOutput->getTemplates();
$this->mExternals = $parserOutput->getExternalLinks();
$this->mCategories = $parserOutput->getCategories();
$this->mProperties = $parserOutput->getProperties();
# Convert the format of the interlanguage links
# I didn't want to change it in the ParserOutput, because that array is passed all
# the way back to the skin, so either a skin API break would be required, or an
# inefficient back-conversion.
$ill = $parserOutput->getLanguageLinks();
$this->mInterlangs = array();
foreach ($ill as $link) {
list($key, $title) = explode(':', $link, 2);
$this->mInterlangs[$key] = $title;
}
$this->mRecursive = $recursive;
$this->mTouchTmplLinks = false;
wfRunHooks('LinksUpdateConstructed', array(&$this));
}
示例12: testProperties
/**
* @covers ParserOutput::setProperty
* @covers ParserOutput::getProperty
* @covers ParserOutput::unsetProperty
* @covers ParserOutput::getProperties
*/
public function testProperties()
{
$po = new ParserOutput();
$po->setProperty('foo', 'val');
$properties = $po->getProperties();
$this->assertEquals($po->getProperty('foo'), 'val');
$this->assertEquals($properties['foo'], 'val');
$po->setProperty('foo', 'second val');
$properties = $po->getProperties();
$this->assertEquals($po->getProperty('foo'), 'second val');
$this->assertEquals($properties['foo'], 'second val');
$po->unsetProperty('foo');
$properties = $po->getProperties();
$this->assertEquals($po->getProperty('foo'), false);
$this->assertArrayNotHasKey('foo', $properties);
}
示例13: getOutputFromWikitext
/**
* This does all the heavy lifting for outputWikitext, except it returns the parser
* output instead of sending it straight to $wgOut. Makes things nice and simple for,
* say, embedding thread pages within a discussion system (LiquidThreads)
*
* @param $text string
* @param $cache boolean
* @param $parserOptions parsing options, defaults to false
* @return ParserOutput
*/
public function getOutputFromWikitext($text, $cache = true, $parserOptions = false)
{
global $wgParser, $wgEnableParserCache, $wgUseFileCache;
if (!$parserOptions) {
$parserOptions = $this->mPage->getParserOptions();
}
$time = -wfTime();
$this->mParserOutput = $wgParser->parse($text, $this->getTitle(), $parserOptions, true, true, $this->getRevIdFetched());
$time += wfTime();
# Timing hack
if ($time > 3) {
wfDebugLog('slow-parse', sprintf("%-5.2f %s", $time, $this->getTitle()->getPrefixedDBkey()));
}
if ($wgEnableParserCache && $cache && $this->mParserOutput->isCacheable()) {
$parserCache = ParserCache::singleton();
$parserCache->save($this->mParserOutput, $this, $parserOptions);
}
// Make sure file cache is not used on uncacheable content.
// Output that has magic words in it can still use the parser cache
// (if enabled), though it will generally expire sooner.
if (!$this->mParserOutput->isCacheable() || $this->mParserOutput->containsOldMagic()) {
$wgUseFileCache = false;
}
if ($this->isCurrent()) {
$this->mPage->doCascadeProtectionUpdates($this->mParserOutput);
}
return $this->mParserOutput;
}
示例14: testUpdate_pagelinks
public function testUpdate_pagelinks()
{
list($t, $po) = $this->makeTitleAndParserOutput("Testing", 111);
$po->addLink(Title::newFromText("Foo"));
$po->addLink(Title::newFromText("Special:Foo"));
// special namespace should be ignored
$po->addLink(Title::newFromText("linksupdatetest:Foo"));
// interwiki link should be ignored
$po->addLink(Title::newFromText("#Foo"));
// hash link should be ignored
$this->assertLinksUpdate($t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(array(NS_MAIN, 'Foo')));
$po = new ParserOutput();
$po->setTitleText($t->getPrefixedText());
$po->addLink(Title::newFromText("Bar"));
$this->assertLinksUpdate($t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(array(NS_MAIN, 'Bar')));
}
示例15: updateLinksTimestamp
/**
* Update links table freshness
*/
protected function updateLinksTimestamp()
{
if ($this->mId) {
// The link updates made here only reflect the freshness of the parser output
$timestamp = $this->mParserOutput->getCacheTime();
$this->mDb->update('page', array('page_links_updated' => $this->mDb->timestamp($timestamp)), array('page_id' => $this->mId), __METHOD__);
}
}