From 310e59e5594f449425c709f0947f34d0c5298b21 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sun, 14 May 2006 03:51:36 +0000 Subject: [PATCH] (bug 5845) Introduce BASEPAGENAME and BASEPAGENAMEE magic words --- RELEASE-NOTES | 1 + includes/MagicWord.php | 4 ++++ includes/Parser.php | 4 ++++ includes/Title.php | 15 +++++++++++++++ languages/Language.php | 2 ++ 5 files changed, 26 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ffef1058dc..f3dcc55532 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -261,6 +261,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 5935) Improvement to German localisation (de) * (bug 5937) Register links from gallery captions with the parent parser output object so that link tables receive those updates too +* (bug 5845) Introduce BASEPAGENAME and BASEPAGENAMEE magic words == Compatibility == diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 2c8b8bdbd4..79e04a2dc3 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -86,6 +86,8 @@ $magicWords = array( 'MAG_NEWSECTIONLINK', 'MAG_NUMBEROFPAGES', 'MAG_CURRENTVERSION', + 'MAG_BASEPAGENAME', + 'MAG_BASEPAGENAMEE', ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) ); @@ -134,6 +136,8 @@ $wgVariableIDs = array( MAG_NEWSECTIONLINK, MAG_NUMBEROFPAGES, MAG_CURRENTVERSION, + MAG_BASEPAGENAME, + MAG_BASEPAGENAMEE, ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordwgVariableIDs', array( &$wgVariableIDs ) ); diff --git a/includes/Parser.php b/includes/Parser.php index 5d272345b9..d2700c9574 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2098,6 +2098,10 @@ class Parser return $this->mTitle->getSubpageText(); case MAG_SUBPAGENAMEE: return $this->mTitle->getSubpageUrlForm(); + case MAG_BASEPAGENAME: + return $this->mTitle->getBaseText(); + case MAG_BASEPAGENAMEE: + return wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) ); case MAG_TALKPAGENAME: if( $this->mTitle->canTalk() ) { $talkPage = $this->mTitle->getTalkPage(); diff --git a/includes/Title.php b/includes/Title.php index 3197b46ec4..9b5b242804 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -691,6 +691,21 @@ class Title { return $text; } + /** + * Get the base name, i.e. the leftmost parts before the / + * @return string Base name + */ + function getBaseText() { + global $wgNamespacesWithSubpages; + if( isset( $wgNamespacesWithSubpages[ $this->mNamespace] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) { + $parts = explode( '/', $this->getText() ); + unset( $parts[ count( $parts ) - 1 ] ); + return implode( '/', $parts ); + } else { + return $this->getText(); + } + } + /** * Get the lowest-level subpage name, i.e. the rightmost part after / * @return string Subpage name diff --git a/languages/Language.php b/languages/Language.php index 0bf85b94ef..7e0fd78ab9 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -242,6 +242,8 @@ $wgLanguageNamesEn =& $wgLanguageNames; MAG_FULLPAGENAMEE => array( 1, 'FULLPAGENAMEE' ), MAG_SUBPAGENAME => array( 1, 'SUBPAGENAME' ), MAG_SUBPAGENAMEE => array( 1, 'SUBPAGENAMEE' ), + MAG_BASEPAGENAME => array( 1, 'BASEPAGENAME' ), + MAG_BASEPAGENAMEE => array( 1, 'BASEPAGENAMEE' ), MAG_TALKPAGENAME => array( 1, 'TALKPAGENAME' ), MAG_TALKPAGENAMEE => array( 1, 'TALKPAGENAMEE' ), MAG_SUBJECTPAGENAME => array( 1, 'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ), -- 2.20.1