| Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
| — | — | @@ -66,6 +66,13 @@ |
| 67 | 67 | $parser->setFunctionHook( 'talkpagenamee', array( __CLASS__, 'talkpagenamee' ), SFH_NO_HASH ); |
| 68 | 68 | $parser->setFunctionHook( 'subjectpagename', array( __CLASS__, 'subjectpagename' ), SFH_NO_HASH ); |
| 69 | 69 | $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 ); |
| 70 | 77 | $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS ); |
| 71 | 78 | $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) ); |
| 72 | 79 | $parser->setFunctionHook( 'groupconvert', array( __CLASS__, 'groupconvert' ), SFH_NO_HASH ); |
| — | — | @@ -411,6 +418,90 @@ |
| 412 | 419 | return ''; |
| 413 | 420 | return $t->getSubjectPage()->getPrefixedUrl(); |
| 414 | 421 | } |
| | 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 | + } |
| 415 | 506 | |
| 416 | 507 | /** |
| 417 | 508 | * Return the number of pages in the given category, or 0 if it's nonexis- |
| Index: trunk/phase3/RELEASE-NOTES |
| — | — | @@ -165,6 +165,8 @@ |
| 166 | 166 | to allow extensions to update caches in similar way as MediaWiki invalidates |
| 167 | 167 | a cached MonoBook sidebar |
| 168 | 168 | * 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 |
| 169 | 171 | |
| 170 | 172 | === Bug fixes in 1.15 === |
| 171 | 173 | * (bug 16968) Special:Upload no longer throws useless warnings. |