r46662 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r46661 | r46662 (on ViewVC) | r46663 >
Date:22:25, 31 January 2009
Author:mrzman
Status:new (Comments)
Tags:
Comment:(bug 8249) Followup to r46630, add parser function versions of the various PAGENAME magic words
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
===================================================================
--- trunk/phase3/includes/parser/CoreParserFunctions.php	(revision 46661)
+++ trunk/phase3/includes/parser/CoreParserFunctions.php	(revision 46662)
@@ -53,6 +53,18 @@
 		$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 @@
 			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-
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 46661)
+++ trunk/phase3/RELEASE-NOTES	(revision 46662)
@@ -73,8 +73,9 @@
   "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
 

Comments

#Comment by Werdna (Talk | contribs)   00:09, 12 February 2009

As with r46662, don't these parser functions need to be localised and added to MagicWords.php?

See r46822 for an example of this...

#Comment by Mr.Z-man (Talk | contribs)   00:13, 12 February 2009

They're already there as the corresponding magic words already exist

#Comment by Werdna (Talk | contribs)   00:15, 12 February 2009

Oh, whoops.

Status & tagging log

  • 00:15, 12 February 2009 Werdna (Talk | contribs) changed the status of r46662 [removed: fixme added: new]
  • 00:09, 12 February 2009 Werdna (Talk | contribs) changed the status of r46662 [removed: new added: fixme]
Views
Toolbox