From 26e705f808095cd9a1db05f1d7eba45f6a1f9f39 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 28 Apr 2014 18:59:20 +0200 Subject: [PATCH] Add $user param to Revision::newNullRevision This avoids the use of $wgUser in Revision constructor and makes the dependency on the global visible. Change-Id: Ib67bd706a3c4ef081f475406e9aa1094c42222ef --- includes/Revision.php | 10 +++++++++- includes/Title.php | 2 +- includes/WikiPage.php | 7 ++++--- includes/filerepo/file/LocalFile.php | 3 ++- includes/specials/SpecialImport.php | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index 7b3054052b..afbd3ace73 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1566,9 +1566,10 @@ class Revision implements IDBAccessObject { * @param int $pageId: ID number of the page to read from * @param string $summary Revision's summary * @param bool $minor Whether the revision should be considered as minor + * @param User|null $user User object to use or null for $wgUser * @return Revision|null Revision or null on error */ - public static function newNullRevision( $dbw, $pageId, $summary, $minor ) { + public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) { global $wgContentHandlerUseDB; wfProfileIn( __METHOD__ ); @@ -1591,8 +1592,15 @@ class Revision implements IDBAccessObject { __METHOD__ ); if ( $current ) { + if ( !$user ) { + global $wgUser; + $user = $wgUser; + } + $row = array( 'page' => $pageId, + 'user_text' => $user->getName(), + 'user' => $user->getId(), 'comment' => $summary, 'minor_edit' => $minor, 'text_id' => $current->rev_text_id, diff --git a/includes/Title.php b/includes/Title.php index 4dc03720dd..eec4dd65c9 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3859,7 +3859,7 @@ class Title { } # Save a null revision in the page's history notifying of the move - $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true ); + $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true, $wgUser ); if ( !is_object( $nullRevision ) ) { throw new MWException( 'No valid null revision produced in ' . __METHOD__ ); } diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 8e15ac9271..161125de51 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2407,7 +2407,7 @@ class WikiPage implements Page, IDBAccessObject { // insert null revision to identify the page protection change as edit summary $latest = $this->getLatest(); - $nullRevision = $this->insertProtectNullRevision( $revCommentMsg, $limit, $expiry, $cascade, $reason ); + $nullRevision = $this->insertProtectNullRevision( $revCommentMsg, $limit, $expiry, $cascade, $reason, $user ); if ( $nullRevision === null ) { return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() ); } @@ -2506,9 +2506,10 @@ class WikiPage implements Page, IDBAccessObject { * @param array $expiry Per restriction type expiration * @param int $cascade Set to false if cascading protection isn't allowed. * @param string $reason + * @param User|null $user * @return Revision|null Null on error */ - public function insertProtectNullRevision( $revCommentMsg, array $limit, array $expiry, $cascade, $reason ) { + public function insertProtectNullRevision( $revCommentMsg, array $limit, array $expiry, $cascade, $reason, $user = null ) { global $wgContLang; $dbw = wfGetDB( DB_MASTER ); @@ -2534,7 +2535,7 @@ class WikiPage implements Page, IDBAccessObject { )->inContentLanguage()->text(); } - $nullRev = Revision::newNullRevision( $dbw, $this->getId(), $editComment, true ); + $nullRev = Revision::newNullRevision( $dbw, $this->getId(), $editComment, true, $user ); if ( $nullRev ) { $nullRev->insertOn( $dbw ); diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index e3b73e359e..5bc7b5e66d 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1424,7 +1424,8 @@ class LocalFile extends File { $dbw, $descTitle->getArticleID(), $editSummary, - false + false, + $user ); if ( !is_null( $nullRevision ) ) { $nullRevision->insertOn( $dbw ); diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index aca8c9637c..891962bc1d 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -492,7 +492,7 @@ class ImportReporter extends ContextSource { $comment = $detail; // quick $dbw = wfGetDB( DB_MASTER ); $latest = $title->getLatestRevID(); - $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleID(), $comment, true ); + $nullRevision = Revision::newNullRevision( $dbw, $title->getArticleID(), $comment, true, $this->getUser() ); if ( !is_null( $nullRevision ) ) { $nullRevision->insertOn( $dbw ); $page = WikiPage::factory( $title ); -- 2.20.1