r28007 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28006‎ | r28007 | r28008 >
Date:09:08, 1 December 2007
Author:werdna
Status:old
Tags:
Comment:
* (bug 11346) Prevent users who cannot edit a page from changing its restrictions.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -28,6 +28,7 @@
2929 var $mReason = '';
3030 var $mCascade = false;
3131 var $mExpiry = null;
 32+ var $mPermErrors = array();
3233
3334 function __construct( &$article ) {
3435 global $wgRequest, $wgUser;
@@ -56,7 +57,7 @@
5758 }
5859
5960 // The form will be available in read-only to show levels.
60 - $this->disabled = !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $wgUser->isBlocked();
 61+ $this->disabled = ($this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect',$wgUser)) != array();
6162 $this->disabledAttrib = $this->disabled
6263 ? array( 'disabled' => 'disabled' )
6364 : array();
@@ -125,22 +126,11 @@
126127 # Show an appropriate message if the user isn't allowed or able to change
127128 # the protection settings at this time
128129 if( $this->disabled ) {
129 - if( $wgUser->isAllowed( 'protect' ) ) {
130 - if( $wgUser->isBlocked() ) {
131 - # Blocked
132 - $message = 'protect-locked-blocked';
133 - } else {
134 - # Database lock
135 - $message = 'protect-locked-dblock';
136 - }
137 - } else {
138 - # Permission error
139 - $message = 'protect-locked-access';
140 - }
 130+ $message = $wgOut->formatPermissionsErrorMessage( $this->mPermErrors );
141131 } else {
142 - $message = 'protect-text';
 132+ $message = wfMsg( 'protect-text', wfEscapeWikiText( $this->mTitle->getPrefixedText() ) );
143133 }
144 - $wgOut->addWikiText( wfMsg( $message, wfEscapeWikiText( $this->mTitle->getPrefixedText() ) ) );
 134+ $wgOut->addWikiText( $message );
145135
146136 $wgOut->addHTML( $this->buildForm() );
147137
@@ -394,4 +384,4 @@
395385 $logViewer->showList( $out );
396386 }
397387
398 -}
\ No newline at end of file
 388+}
Index: trunk/phase3/includes/Article.php
@@ -1709,7 +1709,7 @@
17101710 global $wgUser, $wgRestrictionTypes, $wgContLang;
17111711
17121712 $id = $this->mTitle->getArticleID();
1713 - if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
 1713+ if( array() != $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ) || wfReadOnly() || $id == 0 ) {
17141714 return false;
17151715 }
17161716
Index: trunk/phase3/includes/Title.php
@@ -1188,6 +1188,13 @@
11891189 }
11901190 }
11911191
 1192+ if ($action == 'protect')
 1193+ {
 1194+ if ($this->getUserPermissionsErrors('edit', $user) != array()) {
 1195+ $errors[] = array( 'protect-cantedit' ); // If they can't edit, they shouldn't protect.
 1196+ }
 1197+ }
 1198+
11921199 if( $action == 'create' ) {
11931200 if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
11941201 ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
@@ -1195,9 +1202,9 @@
11961203 }
11971204 } elseif( $action == 'move' && !( $this->isMovable() && $user->isAllowed( 'move' ) ) ) {
11981205 $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed');
1199 - } else if ( !$user->isAllowed( $action ) ) {
 1206+ } else if ( !$user->isAllowed( $action ) ) {
12001207 $return = null;
1201 - $groups = array();
 1208+ $groups = array();
12021209 global $wgGroupPermissions;
12031210 foreach( $wgGroupPermissions as $key => $value ) {
12041211 if( isset( $value[$action] ) && $value[$action] == true ) {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1941,6 +1941,7 @@
19421942 'protect-summary-cascade' => 'cascading',
19431943 'protect-expiring' => 'expires $1 (UTC)',
19441944 'protect-cascade' => 'Protect pages included in this page (cascading protection)',
 1945+'protect-cantedit' => 'You cannot change the protection levels of this page, because you do not have permission to edit it.',
19451946 'restriction-type' => 'Permission:',
19461947 'restriction-level' => 'Restriction level:',
19471948 'minimum-size' => 'Min size',
Index: trunk/phase3/RELEASE-NOTES
@@ -202,6 +202,7 @@
203203 * namespaceDupes.php no longer dies when coming across an illegal title
204204 * (bug 12143) Do not show a link to patrol new pages for non existent pages
205205 * (bug 12166) Fix XHTML validity for Special:Emailuser
 206+* (bug 11346) Users who cannot edit a page can now no longer unprotect it.
206207
207208 == Parser changes in 1.12 ==
208209

Status & tagging log