From a4fafb006bad3360628566d6ff0b1d702bb8d393 Mon Sep 17 00:00:00 2001 From: Alex Z Date: Sat, 31 Jan 2009 22:25:01 +0000 Subject: [PATCH] (bug 8249) Followup to r46630, add parser function versions of the various PAGENAME magic words --- RELEASE-NOTES | 5 +- includes/parser/CoreParserFunctions.php | 88 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 77835019f4..8944615cae 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -73,8 +73,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN "mw-confirmemail-pending" * Local redirects to foreign images are now displayed on the ImagePage when viewing on the local wiki. -* The {{NAMESPACE}}, {{TALKSPACE}}, and {{SUBJECTSPACE}} magic words can now be - used as parser functions to return the desired namespace for a given title. +* (bug 8249) The magic words for namespaces and pagenames can now be used as + parser functions to return the desired namespace or normalized title/title part + for a given title. * Styled #mw-data-after-content in cologneblue.css to match the rest of the font (bug 17110) * (bug 7556) Time zone names in signatures lack i18n diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index fba3d5faf0..e12930b7eb 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -53,6 +53,18 @@ class CoreParserFunctions { $parser->setFunctionHook( 'talkspacee', array( __CLASS__, 'talkspacee' ), SFH_NO_HASH ); $parser->setFunctionHook( 'subjectspace', array( __CLASS__, 'subjectspace' ), SFH_NO_HASH ); $parser->setFunctionHook( 'subjectspacee', array( __CLASS__, 'subjectspacee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'pagename', array( __CLASS__, 'pagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'pagenamee', array( __CLASS__, 'pagenamee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'fullpagename', array( __CLASS__, 'fullpagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'fullpagenamee', array( __CLASS__, 'fullpagenamee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'basepagename', array( __CLASS__, 'basepagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'basepagenamee', array( __CLASS__, 'basepagenamee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subpagename', array( __CLASS__, 'subpagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subpagenamee', array( __CLASS__, 'subpagenamee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'talkpagename', array( __CLASS__, 'talkpagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__, 'talkpagenamee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH ); $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS ); if ( $wgAllowDisplayTitle ) { @@ -295,6 +307,82 @@ class CoreParserFunctions { return ''; return wfUrlencode( $t->getSubjectNsText() ); } + /* + * Functions to get and normalize pagenames, corresponding to the magic words + * of the same names + */ + static function pagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return wfEscapeWikiText( $t->getText() ); + } + static function pagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return $t->getPartialURL(); + } + static function fullpagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return wfEscapeWikiText( $t->getPrefixedText() ); + } + static function fullpagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return $t->getPrefixedURL(); + } + static function subpagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return $t->getSubpageText(); + } + static function subpagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return $t->getSubpageUrlForm(); + } + static function basepagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return $t->getBaseText(); + } + static function basepagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return wfUrlEncode( str_replace( ' ', '_', $t->getBaseText() ) ); + } + static function talkpagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() ); + } + static function talkpagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return $t->getTalkPage()->getPrefixedUrl(); + } + static function subjectpagename( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() ); + } + static function subjectpagenamee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return $t->getSubjectPage()->getPrefixedUrl(); + } /** * Return the number of pages in the given category, or 0 if it's nonexis- -- 2.20.1