From 726f30786f9370942959813b8c4a46cf4ac75ed4 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 18 Sep 2012 22:44:58 +0200 Subject: [PATCH] Forward the User object from WikiPage to Revision. This affects the following methods of WikiPage: - getText() - getUser() - getCreator() - getUserText() - getComment() These are wrapper to methods in the Revision class that accept an optional User object as second parameter in the case FOR_THIS_USER is passed as first parameter. Change-Id: I81a2470378bc1134dd144743d376ba31f4fe13d1 --- includes/WikiPage.php | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/includes/WikiPage.php b/includes/WikiPage.php index bc8766def0..5a3a9e6a04 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -559,14 +559,16 @@ class WikiPage extends Page implements IDBAccessObject { * * @param $audience Integer: one of: * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions + * @param $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return String|bool The text of the current revision. False on failure */ - public function getText( $audience = Revision::FOR_PUBLIC ) { + public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { $this->loadLastEdit(); if ( $this->mLastRevision ) { - return $this->mLastRevision->getText( $audience ); + return $this->mLastRevision->getText( $audience, $user ); } return false; } @@ -608,14 +610,16 @@ class WikiPage extends Page implements IDBAccessObject { /** * @param $audience Integer: one of: * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions + * @param $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return int user ID for the user that made the last article revision */ - public function getUser( $audience = Revision::FOR_PUBLIC ) { + public function getUser( $audience = Revision::FOR_PUBLIC, User $user = null ) { $this->loadLastEdit(); if ( $this->mLastRevision ) { - return $this->mLastRevision->getUser( $audience ); + return $this->mLastRevision->getUser( $audience, $user ); } else { return -1; } @@ -625,14 +629,16 @@ class WikiPage extends Page implements IDBAccessObject { * Get the User object of the user who created the page * @param $audience Integer: one of: * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions + * @param $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return User|null */ - public function getCreator( $audience = Revision::FOR_PUBLIC ) { + public function getCreator( $audience = Revision::FOR_PUBLIC, User $user = null ) { $revision = $this->getOldestRevision(); if ( $revision ) { - $userName = $revision->getUserText( $audience ); + $userName = $revision->getUserText( $audience, $user ); return User::newFromName( $userName, false ); } else { return null; @@ -642,14 +648,16 @@ class WikiPage extends Page implements IDBAccessObject { /** * @param $audience Integer: one of: * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions + * @param $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return string username of the user that made the last article revision */ - public function getUserText( $audience = Revision::FOR_PUBLIC ) { + public function getUserText( $audience = Revision::FOR_PUBLIC, User $user = null ) { $this->loadLastEdit(); if ( $this->mLastRevision ) { - return $this->mLastRevision->getUserText( $audience ); + return $this->mLastRevision->getUserText( $audience, $user ); } else { return ''; } @@ -658,14 +666,16 @@ class WikiPage extends Page implements IDBAccessObject { /** * @param $audience Integer: one of: * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions + * @param $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return string Comment stored for the last article revision */ - public function getComment( $audience = Revision::FOR_PUBLIC ) { + public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) { $this->loadLastEdit(); if ( $this->mLastRevision ) { - return $this->mLastRevision->getComment( $audience ); + return $this->mLastRevision->getComment( $audience, $user ); } else { return ''; } -- 2.20.1