(bug 5167) Add {{SUBPAGENAME}} variable
authorRob Church <robchurch@users.mediawiki.org>
Sat, 4 Mar 2006 23:29:46 +0000 (23:29 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sat, 4 Mar 2006 23:29:46 +0000 (23:29 +0000)
RELEASE-NOTES
includes/MagicWord.php
includes/Parser.php
includes/Title.php
languages/Language.php

index aa446db..425e405 100644 (file)
@@ -277,6 +277,7 @@ Parser:
 * (bug 4783) : Fix for "{{ns:0}} does not render"
 * Improved support for interwiki transclusion
 * (bug 1850) Image link to nonexistent file fixed.
+* (bug 5167) Add {{SUBPAGENAME}} variable
 
 Upload:
 * (bug 2527) Always set destination filename when new file is selected
index 9d0b3bf..55edbc8 100644 (file)
@@ -70,6 +70,7 @@ $magicWords = array(
        'MAG_FULLPAGENAME',
        'MAG_FULLPAGENAMEE',
        'MAG_RAW',
+       'MAG_SUBPAGENAME',
 );
 if ( ! defined( 'MEDIAWIKI_INSTALL' ) )
        wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) );
@@ -102,6 +103,7 @@ $wgVariableIDs = array(
        MAG_CURRENTWEEK,
        MAG_CURRENTDOW,
        MAG_REVISIONID,
+       MAG_SUBPAGENAME
 );
 if ( ! defined( 'MEDIAWIKI_INSTALL' ) )
        wfRunHooks( 'MagicWordwgVariableIDs', array( &$wgVariableIDs ) );
index 90b382a..8165de7 100644 (file)
@@ -2022,6 +2022,8 @@ class Parser
                                return $this->mTitle->getPrefixedText();
                        case MAG_FULLPAGENAMEE:
                                return $this->mTitle->getPrefixedURL();
+                       case MAG_SUBPAGENAME:
+                               return $this->mTitle->getSubpageText();
                        case MAG_REVISIONID:
                                return $this->mRevisionId;
                        case MAG_NAMESPACE:
index f2349bc..3f276f6 100644 (file)
@@ -676,6 +676,20 @@ class Title {
                return $text;
        }
 
+       /**
+        * Get the lowest-level subpage name, i.e. the rightmost part after /
+        * @return string Subpage name
+        */
+       function getSubpageText() {
+               global $wgNamespacesWithSubpages;
+               if( $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
+                       $parts = explode( '/', $this->mTextform );
+                       return( $parts[ count( $parts ) - 1 ] );
+               } else {
+                       return( $this->mTextform );
+               }
+       }
+
        /**
         * Get a URL-encoded title (not an actual URL) including interwiki
         * @return string the URL-encoded form
index f152146..aba1f93 100644 (file)
@@ -226,6 +226,7 @@ $wgLanguageNamesEn =& $wgLanguageNames;
        MAG_NAMESPACEE           => array( 1,    'NAMESPACEE'             ),
        MAG_FULLPAGENAME         => array( 1,    'FULLPAGENAME'           ),
        MAG_FULLPAGENAMEE        => array( 1,    'FULLPAGENAMEE'          ),
+       MAG_SUBPAGENAME                  => array( 0,    'SUBPAGENAME'                    ),
        MAG_MSG                  => array( 0,    'MSG:'                   ),
        MAG_SUBST                => array( 0,    'SUBST:'                 ),
        MAG_MSGNW                => array( 0,    'MSGNW:'                 ),