本文整理汇总了PHP中Parser::getTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::getTitle方法的具体用法?PHP Parser::getTitle怎么用?PHP Parser::getTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::getTitle方法的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: renderGallery
/**
* Parser hook handler for {{#articletype}}
*
* @param Parser $parser : Parser instance available to render
* wikitext into html, or parser methods.
*
* @return string: HTML to insert in the page.
*/
public static function renderGallery($input, array $args, Parser $parser, PPFrame $frame)
{
$parser->getOutput()->addModules('ext.promoter.gallery');
$pageName = $parser->getTitle()->getText();
try {
$renderedAds = array();
$adChooser = new AdChooser($pageName, !$parser->getUser()->isLoggedIn());
$ads = $adChooser->getAds();
foreach ($ads as $ad) {
$renderedAds[] = Ad::fromName($ad['name'])->renderHtml();
}
} catch (AdCampaignExistenceException $e) {
wfDebugLog('Promoter', $e->getMessage());
//@todo i18n
return '<span class="error">No campaign for this page</span>';
} catch (MWException $e) {
wfDebugLog('Promoter', $e->getMessage());
return '<span class="error text-danger">An error occurred [' . $e->getMessage() . ']</span>';
}
$html = '<div class="promotion-gallery hidden hidden-print">' . '<h5 class="sr-only">זוהי גלריה המקדמת ערכים שונים באתר.</h5>' . '<div class="gallery-controls">' . '<span class="sr-only">בכל רגע מוצגות 3 ידיעות בגלריה. ניתן להציג ידיעה נוספת או לחזור לאחור באמצעות הכפתורים הבאים, או באמצעות מקשי החיצים כאשר הפוקוס הוא על הגלריה</span>' . '<a href="#" class="owl-prev"><span class="fa fa-chevron-right fa-lg" title="הקודם"></span><span class="sr-only">הצגת הידיעה הקודמת</span></a>' . '<a href="#" class="owl-next"><span class="fa fa-chevron-left fa-lg" title="הבא"></span><span class="sr-only">הצגת הידיעה הבאה</span></a>' . '</div>';
if ($args['title']) {
$html .= '<div class="header">' . $args['title'] . '</div>';
}
$html .= '<div class="owl-carousel clearfix" tabindex="0">' . implode('', $renderedAds) . '</div>' . '</div>';
return $html;
}
示例3: getParserEngine
/**
* Get an engine instance for the given parser, and cache it in the parser
* so that subsequent calls to this function for the same parser will return
* the same engine.
*
* @param Parser $parser
* @return ScribuntoEngineBase
*/
public static function getParserEngine(Parser $parser)
{
if (empty($parser->scribunto_engine)) {
$parser->scribunto_engine = self::newDefaultEngine(array('parser' => $parser));
$parser->scribunto_engine->setTitle($parser->getTitle());
}
return $parser->scribunto_engine;
}
示例4: clearStorage
/**
* Clear all stored data for a given parser.
*
* @param Parser $parser
*/
public static function clearStorage(Parser $parser)
{
$output = $parser->getOutput();
$title = $parser->getTitle();
if (!isset($output) || !isset($title)) {
return;
}
$output->mSMWData = new SMWSemanticData(new SMWDIWikiPage($title->getDBkey(), $title->getNamespace(), $title->getInterwiki()));
}
示例5: parse
/**
* Hooks into ParserAfterTidy.
*
* @param Parser $parser
* @param String $text
* @return Boolean
*/
static function parse(&$parser, &$text)
{
global $wgexLingoUseNamespaces;
$title = $parser->getTitle();
// parse if
if (!isset($parser->mDoubleUnderscores['noglossary']) && (!$title || !isset($wgexLingoUseNamespaces[$title->getNamespace()]) || $wgexLingoUseNamespaces[$title->getNamespace()])) {
LingoParser::parse($parser, $text);
}
return true;
}
示例6: sprintbtn
/**
* @param Parser $parser
* @return string
*/
public static function sprintbtn($parser)
{
$html = '';
$title = $parser->getTitle();
$link = $title->getFullURL('printable=yes');
$link = '#';
$parser->getOutput()->addModules('ext.stools.foo');
$html .= $parser->insertStripItem('<a id="print-button" href="' . $link . '" type="button" class="btn btn-primary"><i class="fa fa-print"></i> ' . wfMessage('stools-button-print')->plain() . '</a>');
return $html;
}
示例7: 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;
}
示例8: render
/**
* Method for handling the ask concept function.
*
* @todo The possible use of this in an HTML or Specal page context needs to be revisited. The code mentions it, but can this actually happen?
* @todo The escaping of symbols in concept queries needs to be revisited.
*
* @since 1.5.3
*
* @param Parser $parser
*/
public static function render(Parser &$parser)
{
global $wgContLang, $wgTitle;
$title = $parser->getTitle();
$pconc = new SMWDIProperty('_CONC');
if ($title->getNamespace() != SMW_NS_CONCEPT) {
$result = smwfEncodeMessages(array(wfMsgForContent('smw_no_concept_namespace')));
SMWOutputs::commitToParser($parser);
return $result;
} elseif (count(SMWParseData::getSMWdata($parser)->getPropertyValues($pconc)) > 0) {
$result = smwfEncodeMessages(array(wfMsgForContent('smw_multiple_concepts')));
SMWOutputs::commitToParser($parser);
return $result;
}
// process input:
$params = func_get_args();
array_shift($params);
// We already know the $parser ...
// Use first parameter as concept (query) string.
$concept_input = str_replace(array('>', '<'), array('>', '<'), array_shift($params));
// second parameter, if any, might be a description
$concept_docu = array_shift($params);
// NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
$query = SMWQueryProcessor::createQuery($concept_input, SMWQueryProcessor::getProcessedParams(array('limit' => 20, 'format' => 'list')), SMWQueryProcessor::CONCEPT_DESC);
$concept_text = $query->getDescription()->getQueryString();
if (!is_null(SMWParseData::getSMWData($parser))) {
$diConcept = new SMWDIConcept($concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth());
SMWParseData::getSMWData($parser)->addPropertyObjectValue($pconc, $diConcept);
}
// display concept box:
$rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink');
SMWOutputs::requireResource('ext.smw.style');
// TODO: escape output, preferably via Html or Xml class.
$result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description', $title->getText()) . (count($query->getErrors()) > 0 ? ' ' . smwfEncodeMessages($query->getErrors()) : '') . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . ($concept_docu ? "<p>{$concept_docu}</p>" : '') . '<pre>' . str_replace('[', '[', $concept_text) . "</pre>\n</div>";
if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
global $wgOut;
SMWOutputs::commitToOutputPage($wgOut);
} else {
SMWOutputs::commitToParser($parser);
}
return $result;
}
示例9: renderSeriesLink
/**
* Renders the #serieslink parser function.
*
* @param Parser $parser
* @return string the unique tag which must be inserted into the stripped text
*/
public static function renderSeriesLink(&$parser)
{
global $wgTitle;
$params = func_get_args();
array_shift($params);
// We don't need the parser.
// remove the target parameter should it be present
foreach ($params as $key => $value) {
$elements = explode('=', $value, 2);
if ($elements[0] === 'target') {
unset($params[$key]);
}
}
// set the origin parameter
// This will block it from use as iterator parameter. Oh well.
$params[] = "origin=" . $parser->getTitle()->getArticleId();
// hack to remove newline from beginning of output, thanks to
// http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function
return $parser->insertStripItem(SFUtils::createFormLink($parser, 'SeriesEdit', $params), $parser->mStripState);
}
示例10: render
/**
* @param Parser $parser
* @return string
*/
public static function render($parser)
{
$user = $parser->getUser();
$title = $parser->getTitle();
if (!$title || !$title->exists()) {
return '';
}
$author = self::getPageAuthor($title);
if (!$author) {
return '';
}
$html = '<span class="author-rating-wrapper">';
// Add user link
$html .= $parser->insertStripItem(' <a target="_blank" href="' . $author->getUserPage()->getFullURL() . '">' . $author->getName() . '</a>');
$html .= ' <i style="display: none;" class="fa fa-thumbs-o-up author-thumbs-up" title="' . wfMessage('authorrating-rate-title')->plain() . '"></i>';
$html .= ' <span class="label label-success">?</span>';
$html .= '</span>';
$parser->getOutput()->addModules('ext.authorrating.foo');
return array($html, 'markerType' => 'nowiki');
}
示例11: wfSampleGetProp
function wfSampleGetProp($input, array $args, Parser $parser, PPFrame $frame)
{
$pageId = $parser->getTitle()->getArticleId();
if (isset($args['page'])) {
$title = Title::newFromText($args['page']);
if (!$title || $title->getArticleId() === 0) {
// In a real extension, this would be i18n-ized.
return '<span class="error">Invalid page ' . htmlspecialchars($args['page']) . ' specified.</span>';
}
// Do for some page other then current one.
$dbr = wfGetDB(DB_SLAVE);
$propValue = $dbr->selectField('page_props', 'pp_value', array('pp_page' => $title->getArticleId(), 'pp_propname' => "SimpleSetPropExtension"), __METHOD__);
if ($propValue === false) {
// No prop stored for this page
// In a real extension, this would be i18n-ized.
return '<span class="error">No prop set for page ' . htmlspecialchars($args['page']) . ' specified.</span>';
}
// We found the prop. Unserialize (First level of serialization)
$prop = unserialize($propValue);
if (!$parser->isValidHalfParsedText($prop)) {
// Probably won't ever happen.
return '<span class="error">Error retrieving prop</span>';
} else {
// Everything should be good.
return $parser->unserializeHalfParsedText($prop);
}
} else {
// Second case, current page.
// Can't query db, because could be set earlier in the page and not saved yet.
// So have to use the parserOutput object.
$prop = unserialize($parser->getOutput()->getProperty('SimpleSetPropExtension'));
if (!$parser->isValidHalfParsedText($prop)) {
// Probably won't ever happen.
return '<span class="error">Error retrieving prop</span>';
} else {
// Everything should be good.
return $parser->unserializeHalfParsedText($prop);
}
}
}
示例12: renderHeadCount
function renderHeadCount(Parser &$parser, $page = '', $level = '')
{
if (empty($page)) {
$title = $parser->getTitle();
} else {
$title = Title::newFromText($page);
if (!$title->exists()) {
return "'''{$title} does not exist.'''";
}
}
$rev = Revision::newFromTitle($title);
if ($rev === null) {
return "'''Could not retrieve revision from {$title}.'''";
}
$content = $rev->getContent(Revision::RAW);
if ($content === null) {
return "'''Could not extract text from {$title}.'''";
}
$level = empty($level) ? 2 : intval($level);
$header = str_repeat('=', $level);
$serialized = $content->serialize();
$count = preg_match_all("/^{$header}" . "[^=]+" . "{$header}\$/m", $serialized);
return $count == false ? 0 : $count;
}
示例13: 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;
}
示例14: doVariants
/**
* Modify $this->internals and $colours according to language variant linking rules
* @param array $colours
*/
protected function doVariants(&$colours)
{
global $wgContLang, $wgContentHandlerUseDB;
$linkBatch = new LinkBatch();
$variantMap = array();
// maps $pdbkey_Variant => $keys (of link holders)
$output = $this->parent->getOutput();
$linkCache = LinkCache::singleton();
$threshold = $this->parent->getOptions()->getStubThreshold();
$titlesToBeConverted = '';
$titlesAttrs = array();
// Concatenate titles to a single string, thus we only need auto convert the
// single string to all variants. This would improve parser's performance
// significantly.
foreach ($this->internals as $ns => $entries) {
if ($ns == NS_SPECIAL) {
continue;
}
foreach ($entries as $index => $entry) {
$pdbk = $entry['pdbk'];
// we only deal with new links (in its first query)
if (!isset($colours[$pdbk]) || $colours[$pdbk] === 'new') {
$titlesAttrs[] = array($index, $entry['title']);
// separate titles with \0 because it would never appears
// in a valid title
$titlesToBeConverted .= $entry['title']->getText() . "";
}
}
}
// Now do the conversion and explode string to text of titles
$titlesAllVariants = $wgContLang->autoConvertToAllVariants(rtrim($titlesToBeConverted, ""));
$allVariantsName = array_keys($titlesAllVariants);
foreach ($titlesAllVariants as &$titlesVariant) {
$titlesVariant = explode("", $titlesVariant);
}
// Then add variants of links to link batch
$parentTitle = $this->parent->getTitle();
foreach ($titlesAttrs as $i => $attrs) {
/** @var Title $title */
list($index, $title) = $attrs;
$ns = $title->getNamespace();
$text = $title->getText();
foreach ($allVariantsName as $variantName) {
$textVariant = $titlesAllVariants[$variantName][$i];
if ($textVariant === $text) {
continue;
}
$variantTitle = Title::makeTitle($ns, $textVariant);
if (is_null($variantTitle)) {
continue;
}
// Self-link checking for mixed/different variant titles. At this point, we
// already know the exact title does not exist, so the link cannot be to a
// variant of the current title that exists as a separate page.
if ($variantTitle->equals($parentTitle) && !$title->hasFragment()) {
$this->internals[$ns][$index]['selflink'] = true;
continue 2;
}
$linkBatch->addObj($variantTitle);
$variantMap[$variantTitle->getPrefixedDBkey()][] = "{$ns}:{$index}";
}
}
// process categories, check if a category exists in some variant
$categoryMap = array();
// maps $category_variant => $category (dbkeys)
$varCategories = array();
// category replacements oldDBkey => newDBkey
foreach ($output->getCategoryLinks() as $category) {
$categoryTitle = Title::makeTitleSafe(NS_CATEGORY, $category);
$linkBatch->addObj($categoryTitle);
$variants = $wgContLang->autoConvertToAllVariants($category);
foreach ($variants as $variant) {
if ($variant !== $category) {
$variantTitle = Title::makeTitleSafe(NS_CATEGORY, $variant);
if (is_null($variantTitle)) {
continue;
}
$linkBatch->addObj($variantTitle);
$categoryMap[$variant] = array($category, $categoryTitle);
}
}
}
if (!$linkBatch->isEmpty()) {
// construct query
$dbr = wfGetDB(DB_SLAVE);
$fields = array('page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest');
if ($wgContentHandlerUseDB) {
$fields[] = 'page_content_model';
}
$varRes = $dbr->select('page', $fields, $linkBatch->constructSet('page', $dbr), __METHOD__);
$linkcolour_ids = array();
// for each found variants, figure out link holders and replace
foreach ($varRes as $s) {
$variantTitle = Title::makeTitle($s->page_namespace, $s->page_title);
$varPdbk = $variantTitle->getPrefixedDBkey();
$vardbk = $variantTitle->getDBkey();
//.........这里部分代码省略.........
示例15: BugzillaRender
function BugzillaRender($input, array $args, Parser $parser, $frame = null)
{
global $wgBugzillaRESTURL;
// We don't want the page to be cached
// TODO: Not sure if we need this
$parser->disableCache();
// TODO: Figure out to have the parser not do anything to our output
// mediawiki docs are wrong :-(
// error_log(print_r($parser->mStripState, true));
// $parser->mStripState->addItem( 'nowiki', 'NOWIKI', true);
// 'noparse' => true, 'isHTML' => true, 'markerType' => 'nowiki' );
$input = $parser->recursiveTagParse($input, $frame);
// Create a new bugzilla object
$bz = Bugzilla::create($args, $input, $parser->getTitle());
// Show the desired output (or an error if there was one)
return $bz->render();
}