From: Jackmcbarn Date: Thu, 2 Jan 2014 18:27:29 +0000 (-0500) Subject: Add CASCADINGSOURCES parser function X-Git-Tag: 1.31.0-rc.0~17363^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=073c4bf16f8d62aaebd44c7b6e6e6ac29d5f8e5b;p=lhc%2Fweb%2Fwiklou.git Add CASCADINGSOURCES parser function Add {{CASCADINGSOURCES}}, which gives a list of cascading-protected pages that cause a given page to be protected. This is an expensive parser function. Change-Id: I0e9556d53d9a78bc02848c775cb667294726cea1 --- diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 232f43e825..bf15bf34a7 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -149,6 +149,7 @@ class MagicWord { 'contentlanguage', 'numberofadmins', 'numberofviews', + 'cascadingsources', ); /* Array of caching hints for ParserCache */ diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index ca271129c4..4e7e663b6c 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -54,7 +54,7 @@ class CoreParserFunctions { '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 ); @@ -1118,4 +1118,32 @@ class CoreParserFunctions { $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. + * + * @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; + } + $names = array(); + if ( $parser->incrementExpensiveFunctionCount() ) { + $sources = $titleObject->getCascadeProtectionSources(); + foreach ( $sources[0] as $sourceTitle ) { + $names[] = $sourceTitle->getText(); + } + } + + return implode( $names, '|' ); + } + } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 27065e588d..b7586e4fae 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3031,6 +3031,9 @@ class Parser { case 'contentlanguage': global $wgLanguageCode; return $wgLanguageCode; + case 'cascadingsources': + $value = CoreParserFunctions::cascadingsources( $this ); + break; default: $ret = null; wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 344e2340af..177c8c62de 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -363,6 +363,7 @@ $magicWords = array( 'numberingroup' => array( 1, 'NUMBERINGROUP', 'NUMINGROUP' ), 'staticredirect' => array( 1, '__STATICREDIRECT__' ), 'protectionlevel' => array( 1, 'PROTECTIONLEVEL' ), + 'cascadingsources' => array( 1, 'CASCADINGSOURCES' ), 'formatdate' => array( 0, 'formatdate', 'dateformat' ), 'url_path' => array( 0, 'PATH' ), 'url_wiki' => array( 0, 'WIKI' ),