Page MenuHomePhabricator

Revision_Parser_Functions.patch

Authored By
bzimport
Nov 21 2014, 9:21 PM
Size
3 KB
Referenced Files
None
Subscribers
None

Revision_Parser_Functions.patch

Index: CoreParserFunctions.php
===================================================================
--- CoreParserFunctions.php (revision 49323)
+++ CoreParserFunctions.php (working copy)
@@ -66,6 +66,13 @@
$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( 'revisionid', array( __CLASS__, 'revisionid' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisiontimestamp',array( __CLASS__, 'revisiontimestamp'), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisionday', array( __CLASS__, 'revisionday' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisionday2', array( __CLASS__, 'revisionday2' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisionmonth', array( __CLASS__, 'revisionmonth' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisionyear', array( __CLASS__, 'revisionyear' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'revisionuser', array( __CLASS__, 'revisionuser' ), SFH_NO_HASH );
$parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
$parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) );
$parser->setFunctionHook( 'groupconvert', array( __CLASS__, 'groupconvert' ), SFH_NO_HASH );
@@ -413,6 +420,59 @@
return '';
return $t->getSubjectPage()->getPrefixedUrl();
}
+ /*
+ * Functions to get revision informations, corresponding to the magic words
+ * of the same names
+ */
+ static function revisionid( $parser, $title = null ) {
+ $t = Title::newFromText( $title );
+ if ( is_null($t) )
+ return '';
+ if($t->equals($parser->getTitle()))
+ return $parser->getRevisionId();
+ $a = new Article($t, 0);
+ return $a->getRevIdFetched();
+ }
+ static function revisiontimestamp( $parser, $title = null ) {
+ $t = Title::newFromText( $title );
+ if ( is_null($t) )
+ return '';
+ if($t->equals($parser->getTitle()))
+ return $parser->getRevisionTimestamp();
+ $a = new Article($t, 0);
+ return $a->getTimestamp();
+ }
+ static function revisionday( $parser, $title = null ) {
+ $timestamp = self::revisiontimestamp( $parser, $title);
+ if ( $timestamp == '' ) return '';
+ return intval( substr( $timestamp, 6, 2 ) );
+ }
+ static function revisionday2( $parser, $title = null ) {
+ $timestamp = self::revisiontimestamp( $parser, $title);
+ if ( $timestamp == '' ) return '';
+ return substr( $timestamp, 6, 2 );
+ }
+ static function revisionmonth( $parser, $title = null ) {
+ $timestamp = self::revisiontimestamp( $parser, $title);
+ if ( $timestamp == '' ) return '';
+ return intval( substr( $timestamp, 4, 2 ) );
+ }
+ static function revisionyear( $parser, $title = null ) {
+ $timestamp = self::revisiontimestamp( $parser, $title);
+ if ( $timestamp == '' ) return '';
+ return substr( $timestamp, 0, 4 );
+ }
+ static function revisionuser( $parser, $title = null ) {
+ $t = Title::newFromText( $title );
+ if ( is_null($t) )
+ return '';
+ if($t->equals($parser->getTitle())){
+ global $wgUser;
+ return $wgUser->getName();
+ }
+ $a = new Article($t, 0);
+ return $a->getUserText();
+ }
/**
* Return the number of pages in the given category, or 0 if it's nonexis-

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675
Default Alt Text
Revision_Parser_Functions.patch (3 KB)

Event Timeline