'talkpagename', 'talkpagenamee', 'subjectpagename',
'subjectpagenamee', 'pageid', 'revisionid', 'revisionday',
'revisionday2', 'revisionmonth', 'revisionmonth1', 'revisionyear',
- 'revisiontimestamp', 'revisionuser',
+ 'revisiontimestamp', 'revisionuser', 'cascadingsources',
);
foreach ( $noHashFunctions as $func ) {
$parser->setFunctionHook( $func, array( __CLASS__, $func ), SFH_NO_HASH );
if ( !$wgRestrictDisplayTitle ) {
$parser->mOutput->setDisplayTitle( $text );
- } elseif ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
+ } elseif ( $title instanceof Title && !$title->hasFragment() && $title->equals( $parser->mTitle ) ) {
$parser->mOutput->setDisplayTitle( $text );
}
* @return boolean true on successful match
*/
private static function matchAgainstMagicword( $magicword, $value ) {
- if ( strval( $value ) === '' ) {
+ $value = trim( strval( $value ) );
+ if ( $value === '' ) {
return false;
}
$mwObject = MagicWord::get( $magicword );
- return $mwObject->match( $value );
+ return $mwObject->matchStartToEnd( $value );
}
static function formatRaw( $num, $raw ) {
* Return the size of the given page, or 0 if it's nonexistent. This is an
* expensive parser function and can't be called too many times per page.
*
- * @todo FIXME: Title::getLength() documentation claims that it adds things
- * to the link cache, so the local cache here should be unnecessary, but
- * in fact calling getLength() repeatedly for the same $page does seem to
- * run one query for each call?
- * @todo Document parameters
- *
* @param $parser Parser
* @param $page String Name of page to check (Default: empty string)
* @param $raw String Should number be human readable with commas or just number
}
/**
- * Returns the requested protection level for the current page
+ * Returns the requested protection level for the current page. This
+ * is an expensive parser function and can't be called too many times
+ * per page, unless the protection levels for the given title have
+ * already been retrieved
*
* @param Parser $parser
* @param string $type
if ( !( $titleObject instanceof Title ) ) {
$titleObject = $parser->mTitle;
}
- $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
- # Title::getRestrictions returns an array, its possible it may have
- # multiple values in the future
- return implode( $restrictions, ',' );
+ if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
+ $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
+ # Title::getRestrictions returns an array, its possible it may have
+ # multiple values in the future
+ return implode( $restrictions, ',' );
+ }
+ return '';
}
/**
// Use title from parser to have correct pageid after edit
if ( $t->equals( $parser->getTitle() ) ) {
$t = $parser->getTitle();
+ return $t->getArticleID();
+ }
+
+ // These can't have ids
+ if ( !$t->canExist() || $t->isExternal() ) {
+ return 0;
+ }
+
+ // Check the link cache, maybe something already looked it up.
+ $linkCache = LinkCache::singleton();
+ $pdbk = $t->getPrefixedDBkey();
+ $id = $linkCache->getGoodLinkID( $pdbk );
+ if ( $id != 0 ) {
+ $parser->mOutput->addLink( $t, $id );
+ return $id;
+ }
+ if ( $linkCache->isBadLink( $pdbk ) ) {
+ $parser->mOutput->addLink( $t, 0 );
+ return $id;
}
- // fetch pageid from cache/database and return the value
- $pageid = $t->getArticleID();
- return $pageid ? $pageid : '';
+
+ // We need to load it from the DB, so mark expensive
+ if ( $parser->incrementExpensiveFunctionCount() ) {
+ $id = $t->getArticleID();
+ $parser->mOutput->addLink( $t, $id );
+ return $id;
+ }
+ return null;
}
/**
$rev = self::getCachedRevisionObject( $parser, $t );
return $rev ? $rev->getUserText() : '';
}
+
+ /**
+ * Returns the sources of any cascading protection acting on a specified page.
+ * Pages will not return their own title unless they transclude themselves.
+ * This is an expensive parser function and can't be called too many times per page,
+ * unless cascading protection sources for the page have already been loaded.
+ *
+ * @param Parser $parser
+ * @param string $title
+ *
+ * @return string
+ * @since 1.23
+ */
+ public static function cascadingsources( $parser, $title = '' ) {
+ $titleObject = Title::newFromText( $title );
+ if ( !( $titleObject instanceof Title ) ) {
+ $titleObject = $parser->mTitle;
+ }
+ if ( $titleObject->areCascadeProtectionSourcesLoaded()
+ || $parser->incrementExpensiveFunctionCount()
+ ) {
+ $names = array();
+ $sources = $titleObject->getCascadeProtectionSources();
+ foreach ( $sources[0] as $sourceTitle ) {
+ $names[] = $sourceTitle->getPrefixedText();
+ }
+ return implode( $names, '|' );
+ }
+ return '';
+ }
+
}