CoreMagicVariables/CoreParserFunction: unify revisionuser
Reduce code duplication by having the "magic variable" implementation of `revisionuser` invoke the corresponding "parser function" implementation with no arguments. This reduces code duplication and also supports consistent results from direct invocation of the parser function with no arguments in the future. Bug: T204370 Change-Id: I4200e4f05a8987b509349832d6d0b164acbe0dd8
This commit is contained in:
parent
5cb4693772
commit
2da6deaba4
2 changed files with 14 additions and 13 deletions
|
|
@ -107,6 +107,7 @@ class CoreMagicVariables {
|
|||
case 'subjectpagename':
|
||||
case 'subjectpagenamee':
|
||||
case 'pageid':
|
||||
case 'revisionuser':
|
||||
case 'revisionday':
|
||||
case 'revisionday2':
|
||||
case 'revisionmonth':
|
||||
|
|
@ -169,14 +170,6 @@ class CoreMagicVariables {
|
|||
}
|
||||
return (string)$value;
|
||||
}
|
||||
case 'revisionuser':
|
||||
// Inform the edit saving system that getting the canonical output after
|
||||
// revision insertion requires a parse that used the actual user ID
|
||||
self::setOutputFlag( $parser, $logger, ParserOutputFlags::VARY_USER, '{{REVISIONUSER}} used' );
|
||||
// Note that getRevisionUser() can return null; we need to
|
||||
// be sure to cast this to (an empty) string, since 'null'
|
||||
// means "magic variable not handled here".
|
||||
return (string)$parser->getRevisionUser();
|
||||
case 'revisionsize':
|
||||
return (string)$parser->getRevisionSize();
|
||||
case 'currentdayname':
|
||||
|
|
|
|||
|
|
@ -1554,12 +1554,20 @@ class CoreParserFunctions {
|
|||
if ( $t === null ) {
|
||||
return '';
|
||||
}
|
||||
// fetch revision from cache/database and return the value
|
||||
$rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_USER );
|
||||
if ( $rev === null ) {
|
||||
return '';
|
||||
// VARY_USER informs the edit saving system that getting the canonical
|
||||
// output after revision insertion requires a parse that used the
|
||||
// actual user ID.
|
||||
if ( $t->equals( $parser->getTitle() ) ) {
|
||||
// Fall back to Parser's "revision user" for the current title
|
||||
$parser->getOutput()->setOutputFlag( ParserOutputFlags::VARY_USER );
|
||||
// Note that getRevisionUser() can return null; we need to
|
||||
// be sure to cast this to (an empty) string, since returning
|
||||
// null means "magic variable not handled".
|
||||
return (string)$parser->getRevisionUser();
|
||||
}
|
||||
$user = $rev->getUser();
|
||||
// Fetch revision from cache/database and return the value.
|
||||
$rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_USER );
|
||||
$user = ( $rev !== null ) ? $rev->getUser() : null;
|
||||
return $user ? $user->getName() : '';
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue