From c819ae88199c1f87bca467e2527997bc102dde0d Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Fri, 21 Jun 2013 16:01:52 +0200 Subject: [PATCH] Abort page restriction if no null revision can be created In practice, this should not currently be happening: null revision can not be created if no previous revision exists, which should not be the case where we call the function in doUpdateRestrictions. However, since newNullRevision can potentially return null (it's documented that way, perhaps some day in the future, additional code paths can lead to null), we should check for it. Also: after completing the restriction updates, the null revision is passed along to a hook, which is documented[1] to get a Revision object. Right now, in theory, this could be incorrect. 1: https://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete Change-Id: I89b0be823d9933d557470005c390a9102f931684 --- includes/WikiPage.php | 42 ++++++++++++++++-------------- languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 1 + maintenance/language/messages.inc | 1 + 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 1a46b3ed01..d4734c997f 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2362,24 +2362,6 @@ class WikiPage implements Page, IDBAccessObject { $cascade = false; } - // Update restrictions table - foreach ( $limit as $action => $restrictions ) { - if ( $restrictions != '' ) { - $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ), - array( 'pr_page' => $id, - 'pr_type' => $action, - 'pr_level' => $restrictions, - 'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0, - 'pr_expiry' => $encodedExpiry[$action] - ), - __METHOD__ - ); - } else { - $dbw->delete( 'page_restrictions', array( 'pr_page' => $id, - 'pr_type' => $action ), __METHOD__ ); - } - } - // Prepare a null revision to be added to the history $editComment = $wgContLang->ucfirst( wfMessage( @@ -2401,8 +2383,30 @@ class WikiPage implements Page, IDBAccessObject { )->inContentLanguage()->text(); } - // Insert a null revision $nullRevision = Revision::newNullRevision( $dbw, $id, $editComment, true ); + if ( $nullRevision === null ) { + return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() ); + } + + // Update restrictions table + foreach ( $limit as $action => $restrictions ) { + if ( $restrictions != '' ) { + $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ), + array( 'pr_page' => $id, + 'pr_type' => $action, + 'pr_level' => $restrictions, + 'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0, + 'pr_expiry' => $encodedExpiry[$action] + ), + __METHOD__ + ); + } else { + $dbw->delete( 'page_restrictions', array( 'pr_page' => $id, + 'pr_type' => $action ), __METHOD__ ); + } + } + + // Insert a null revision $nullRevId = $nullRevision->insertOn( $dbw ); $latest = $this->getLatest(); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 973c946074..556d7dd935 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1039,6 +1039,7 @@ It may have already been deleted by someone else.', 'cannotdelete-title' => 'Cannot delete page "$1"', 'delete-hook-aborted' => 'Deletion aborted by hook. It gave no explanation.', +'no-null-revision' => 'Could not create new null revision for page "$1"', 'badtitle' => 'Bad title', 'badtitletext' => 'The requested page title was invalid, empty, or an incorrectly linked inter-language or inter-wiki title. It may contain one or more characters that cannot be used in titles.', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 7582c6c1f5..8d9597f271 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -982,6 +982,7 @@ See also: 'cannotdelete-title' => 'Title of error page when the user cannot delete a page. Parameters: * $1 - the page name', 'delete-hook-aborted' => 'Error message shown when an extension hook prevents a page deletion, but does not provide an error message.', +'no-null-revision' => 'Error message shown when no null revision could be created to reflect a protection level change.', 'badtitle' => 'The page title when a user requested a page with invalid page name. The content will be {{msg-mw|badtitletext}}.', 'badtitletext' => 'The message shown when a user requested a page with invalid page name. The page title will be {{msg-mw|badtitle}}. diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 2cb94cf449..bc6219e0b5 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -403,6 +403,7 @@ $wgMessageStructure = array( 'cannotdelete', 'cannotdelete-title', 'delete-hook-aborted', + 'no-null-revision', 'badtitle', 'badtitletext', 'perfcached', -- 2.20.1