MediaWiki r49575 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r49574‎ | r49575 (on ViewVC)‎ | r49576 >
Date:21:46, 16 April 2009
Author:catrope
Status:reverted (Comments)
Tags:
Comment:
(bug 6092) Add parser function equivalents of {{REVISIONID}}, {{REVISIONTIMESTAMP}} (and friends) and {{REVISIONUSER}} magic words. These parser functions are marked as expensive and cache their results
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -66,6 +66,13 @@
6767 $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__, 'talkpagenamee' ), SFH_NO_HASH );
6868 $parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH );
6969 $parser->setFunctionHook( 'subjectpagenamee', array( __CLASS__, 'subjectpagenamee' ), SFH_NO_HASH );
 70+ $parser->setFunctionHook( 'revisionid', array( __CLASS__, 'revisionid' ), SFH_NO_HASH );
 71+ $parser->setFunctionHook( 'revisiontimestamp',array( __CLASS__, 'revisiontimestamp'), SFH_NO_HASH );
 72+ $parser->setFunctionHook( 'revisionday', array( __CLASS__, 'revisionday' ), SFH_NO_HASH );
 73+ $parser->setFunctionHook( 'revisionday2', array( __CLASS__, 'revisionday2' ), SFH_NO_HASH );
 74+ $parser->setFunctionHook( 'revisionmonth', array( __CLASS__, 'revisionmonth' ), SFH_NO_HASH );
 75+ $parser->setFunctionHook( 'revisionyear', array( __CLASS__, 'revisionyear' ), SFH_NO_HASH );
 76+ $parser->setFunctionHook( 'revisionuser', array( __CLASS__, 'revisionuser' ), SFH_NO_HASH );
7077 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
7178 $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
7279 $parser->setFunctionHook( 'groupconvert', array( __CLASS__, 'groupconvert' ), SFH_NO_HASH );
@@ -411,6 +418,90 @@
412419 return '';
413420 return $t->getSubjectPage()->getPrefixedUrl();
414421 }
 422+ /*
 423+ * Functions to get revision informations, corresponding to the magic words
 424+ * of the same names
 425+ */
 426+ static function revisionid( $parser, $title = null ) {
 427+ static $cache = array ();
 428+ $t = Title::newFromText( $title );
 429+ if ( is_null( $t ) )
 430+ return '';
 431+ if ( $t->equals( $parser->getTitle() ) ) {
 432+ // Let the edit saving system know we should parse the page
 433+ // *after* a revision ID has been assigned.
 434+ $parser->mOutput->setFlag( 'vary-revision' );
 435+ wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
 436+ return $parser->getRevisionId();
 437+ }
 438+ if ( isset( $cache[$t->getPrefixedText()] ) )
 439+ return $cache[$t->getPrefixedText()];
 440+ elseif ( $parser->incrementExpensiveFunctionCount() ) {
 441+ $a = new Article( $t );
 442+ return $cache[$t->getPrefixedText()] = $a->getRevIdFetched();
 443+ }
 444+ return '';
 445+ }
 446+ static function revisiontimestamp( $parser, $title = null ) {
 447+ static $cache = array ();
 448+ $t = Title::newFromText( $title );
 449+ if ( is_null( $t ) )
 450+ return '';
 451+ if ( $t->equals( $parser->getTitle() ) ) {
 452+ // Let the edit saving system know we should parse the page
 453+ // *after* a revision ID has been assigned. This is for null edits.
 454+ $parser->mOutput->setFlag( 'vary-revision' );
 455+ wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} or related parser function used, setting vary-revision...\n" );
 456+ return $parser->getRevisionTimestamp();
 457+ }
 458+ if ( isset( $cache[$t->getPrefixedText()] ) )
 459+ return $cache[$t->getPrefixedText()];
 460+ elseif ( $parser->incrementExpensiveFunctionCount() ) {
 461+ $a = new Article( $t );
 462+ return $cache[$t->getPrefixedText()] = $a->getTimestamp();
 463+ }
 464+ return '';
 465+ }
 466+ static function revisionday( $parser, $title = null ) {
 467+ $timestamp = self::revisiontimestamp( $parser, $title );
 468+ if ( $timestamp == '' ) return '';
 469+ return intval( substr( $timestamp, 6, 2 ) );
 470+ }
 471+ static function revisionday2( $parser, $title = null ) {
 472+ $timestamp = self::revisiontimestamp( $parser, $title );
 473+ if ( $timestamp == '' ) return '';
 474+ return substr( $timestamp, 6, 2 );
 475+ }
 476+ static function revisionmonth( $parser, $title = null ) {
 477+ $timestamp = self::revisiontimestamp( $parser, $title );
 478+ if ( $timestamp == '' ) return '';
 479+ return intval( substr( $timestamp, 4, 2 ) );
 480+ }
 481+ static function revisionyear( $parser, $title = null ) {
 482+ $timestamp = self::revisiontimestamp( $parser, $title );
 483+ if ( $timestamp == '' ) return '';
 484+ return substr( $timestamp, 0, 4 );
 485+ }
 486+ static function revisionuser( $parser, $title = null ) {
 487+ static $cache = array();
 488+ $t = Title::newFromText( $title );
 489+ if ( is_null( $t ) )
 490+ return '';
 491+ if ( $t->equals( $parser->getTitle() ) ) {
 492+ // Let the edit saving system know we should parse the page
 493+ // *after* a revision ID has been assigned. This is for null edits.
 494+ $parser->mOutput->setFlag( 'vary-revision' );
 495+ wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" );
 496+ return $parser->getRevisionUser();
 497+ }
 498+ if ( isset( $cache[$t->getPrefixedText()] ) )
 499+ return $cache[$t->getPrefixedText()];
 500+ elseif ( $parser->incrementExpensiveFunctionCount() ) {
 501+ $a = new Article( $t );
 502+ return $cache[$t->getPrefixedText()] = $a->getUserText();
 503+ }
 504+ return '';
 505+ }
415506
416507 /**
417508 * Return the number of pages in the given category, or 0 if it's nonexis-
Index: trunk/phase3/RELEASE-NOTES
@@ -165,6 +165,8 @@
166166 to allow extensions to update caches in similar way as MediaWiki invalidates
167167 a cached MonoBook sidebar
168168 * Special:AllPages: Move hardcoded styles from code to CSS
 169+* (bug 6092) Add parser function equivalents of {{REVISIONID}},
 170+ {{REVISIONTIMESTAMP}} (and friends) and {{REVISIONUSER}} magic words
169171
170172 === Bug fixes in 1.15 ===
171173 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

Rev.Commit summaryAuthorDate
r51424Reverted r49575, {{revisionid:...}} due to unresolved CR comments and the gen...tstarling17:09, 3 June 2009

Past revisions this follows-up on

Rev.Commit summaryAuthorDate
r16659* (bug 6092) Introduce magic words {{REVISIONDAY}}, {{REVISIONDAY2}, {{REVISI...collinj17:20, 26 September 2006

Comments

#Comment by Melancholie (talk | contribs)   05:31, 17 April 2009

Is there now a magic word + parser function, or does the magic word just get "imported"? See https://bugzilla.wikimedia.org/show_bug.cgi?id=6092#c23

#Comment by Catrope (talk | contribs)   09:39, 17 April 2009

See the bug, comment 24.

#Comment by Happy-melon (talk | contribs)   13:25, 20 April 2009

What have I got to do with it?? :D

#Comment by Melancholie (talk | contribs)   05:32, 17 April 2009

{{REVISIONUSER}} (<nowiki> ;-)

#Comment by Spidern (talk | contribs)   03:06, 21 April 2009

Oh , you silly person you.

#Comment by Zzyzx11 (talk | contribs)   03:12, 21 April 2009

How in the world did I get into this conversation?

#Comment by Zzyzx11 (talk | contribs)   03:24, 21 April 2009

I mean is way better than me... especially when that user saved the entire Wikipedia on 20130523091750 :D

#Comment by Voice of All (talk | contribs)   07:02, 21 April 2009
#Comment by Brion VIBBER (talk | contribs)   00:31, 29 April 2009

There's a lot of code duplication here; I'd recommend refactoring the code a bit so it's easier to maintain.

#Comment by Kronoxt (talk | contribs)   01:19, 15 May 2009

Are you talking about me?? Hoe I got implicated in that... anyways.

#Comment by Kronoxt (talk | contribs)   02:12, 15 May 2009

&EDIT : **How I got involved in that

#Comment by Shinjiman (talk | contribs)   15:29, 1 June 2009

Me too, how I got involved in that?

#Comment by Splarka (talk | contribs)   08:19, 30 May 2009

Hey, Someone should make sure this can't be used as Template:CURRENTUSER by giving an invalid/bad/deleted/hidden title.

#Comment by Capmo (talk | contribs)   07:08, 4 June 2009

Hey, it took me 20min to understand why you were all talking about me, lol! Especially , you naughty boy!

#Comment by Pinky (talk | contribs)   01:27, 16 June 2009

test ~~~

Status & tagging log