r107776 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107775‎ | r107776 | r107777 >
Date:15:31, 1 January 2012
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Display all errors in showForm() instead of only the first one
* First do some checks and then delete the target page instead of the opposite so we don't delete a page for no purpose if a problem arises
* Changed some empty() checks to count()
* Use Title::quickUserCan() to see whether to show the checkbox to delete the page or not instead of User::isAllowed()
Modified paths:
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -68,7 +68,7 @@
6969
7070 # Check rights
7171 $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
72 - if( !empty( $permErrors ) ) {
 72+ if ( count( $permErrors ) ) {
7373 // Auto-block user's IP if the account was "hard" blocked
7474 $user->spreadAnyEditBlock();
7575 throw new PermissionsError( 'move', $permErrors );
@@ -89,16 +89,16 @@
9090 && $user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
9191 $this->doSubmit();
9292 } else {
93 - $this->showForm( '' );
 93+ $this->showForm( array() );
9494 }
9595 }
9696
9797 /**
9898 * Show the form
9999 *
100 - * @param $err Mixed: error message. May either be a string message name or
101 - * array message name and parameters, like the second argument to
102 - * OutputPage::wrapWikiMsg().
 100+ * @param $err Array: error messages. Each item is an error message.
 101+ * It may either be a string message name or array message name and
 102+ * parameters, like the second argument to OutputPage::wrapWikiMsg().
103103 */
104104 function showForm( $err ) {
105105 global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
@@ -117,22 +117,21 @@
118118 # Show the current title as a default
119119 # when the form is first opened.
120120 $newTitle = $this->oldTitle;
121 - }
122 - else {
123 - if( empty($err) ) {
124 - # If a title was supplied, probably from the move log revert
125 - # link, check for validity. We can then show some diagnostic
126 - # information and save a click.
127 - $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
128 - if( $newerr ) {
129 - $err = $newerr[0];
130 - }
 121+ } elseif ( !count( $err ) ) {
 122+ # If a title was supplied, probably from the move log revert
 123+ # link, check for validity. We can then show some diagnostic
 124+ # information and save a click.
 125+ $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
 126+ if( is_array( $newerr ) ) {
 127+ $err = $newerr;
131128 }
132129 }
133130
134131 $user = $this->getUser();
135132
136 - if ( !empty($err) && $err[0] == 'articleexists' && $user->isAllowed( 'delete' ) ) {
 133+ if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
 134+ && $newTitle->quickUserCan( 'delete', $user )
 135+ ) {
137136 $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
138137 $movepagebtn = wfMsg( 'delete_and_move' );
139138 $submitVar = 'wpDeleteAndMove';
@@ -143,7 +142,7 @@
144143 Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
145144 "</td>
146145 </tr>";
147 - $err = '';
 146+ $err = array();
148147 } else {
149148 if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
150149 $out->wrapWikiMsg( "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>", 'moveuserpage-warning' );
@@ -155,10 +154,12 @@
156155 $confirm = false;
157156 }
158157
159 - if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $user->isAllowed( 'reupload-shared' ) ) {
 158+ if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
 159+ && $user->isAllowed( 'reupload-shared' )
 160+ ) {
160161 $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
161162 $submitVar = 'wpMoveOverSharedFile';
162 - $err = '';
 163+ $err = array();
163164 }
164165
165166 $oldTalk = $this->oldTitle->getTalkPage();
@@ -189,17 +190,33 @@
190191 $out->addWikiMsg( 'movepagetalktext' );
191192 }
192193
193 - $token = htmlspecialchars( $user->getEditToken() );
 194+ if ( count( $err ) ) {
 195+ $out->addHTML( "<div class='error'>\n" );
 196+ $action_desc = $this->msg( 'action-move' )->plain();
 197+ $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
194198
195 - if ( !empty($err) ) {
196 - $out->addSubtitle( $this->msg( 'formerror' ) );
197 - if( $err[0] == 'hookaborted' ) {
198 - $hookErr = $err[1];
199 - $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
200 - $out->addHTML( $errMsg );
 199+ if ( count( $err ) ) {
 200+ $errMsg = $err[0];
 201+ $errMsgName = array_shift( $errMsg );
 202+ if ( $errMsgName == 'hookaborted' ) {
 203+ $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
 204+ } else {
 205+ $out->addWikiMsgArray( $errMsg, $errMsgName );
 206+ }
201207 } else {
202 - $out->wrapWikiMsg( "<p><strong class=\"error\">\n$1\n</strong></p>", $err );
 208+ $errStr = array();
 209+ foreach( $err as $errMsg ) {
 210+ if( $errMsg[0] == 'hookaborted' ) {
 211+ $errStr[] = $errMsg[1];
 212+ } else {
 213+ $errMsgName = array_shift( $errMsg );
 214+ $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
 215+ }
 216+ }
 217+
 218+ $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
203219 }
 220+ $out->addHTML( "</div>\n" );
204221 }
205222
206223 if ( $this->oldTitle->isProtected( 'move' ) ) {
@@ -336,7 +353,7 @@
337354 "</td>
338355 </tr>" .
339356 Xml::closeElement( 'table' ) .
340 - Html::hidden( 'wpEditToken', $token ) .
 357+ Html::hidden( 'wpEditToken', $user->getEditToken() ) .
341358 Xml::closeElement( 'fieldset' ) .
342359 Xml::closeElement( 'form' ) .
343360 "\n"
@@ -359,12 +376,29 @@
360377 $ot = $this->oldTitle;
361378 $nt = $this->newTitle;
362379
 380+ # don't allow moving to pages with # in
 381+ if ( !$nt || $nt->getFragment() != '' ) {
 382+ $this->showForm( array( array( 'badtitletext' ) ) );
 383+ return;
 384+ }
 385+
 386+ # Show a warning if the target file exists on a shared repo
 387+ if ( $nt->getNamespace() == NS_FILE
 388+ && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
 389+ && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
 390+ && wfFindFile( $nt ) )
 391+ {
 392+ $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
 393+ return;
 394+
 395+ }
 396+
363397 # Delete to make way if requested
364398 if ( $this->deleteAndMove ) {
365399 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
366400 if ( count( $permErrors ) ) {
367401 # Only show the first error
368 - $this->showForm( $permErrors[0] );
 402+ $this->showForm( $permErrors );
369403 return;
370404 }
371405
@@ -381,29 +415,11 @@
382416 $error = ''; // passed by ref
383417 $page = WikiPage::factory( $nt );
384418 if ( !$page->doDeleteArticle( $reason, false, 0, true, $error, $user ) ) {
385 - $this->showForm( array( 'cannotdelete', wfEscapeWikiText( $nt->getPrefixedText() ) ) );
 419+ $this->showForm( array( array( 'cannotdelete', wfEscapeWikiText( $nt->getPrefixedText() ) ) ) );
386420 return;
387421 }
388 -
389422 }
390423
391 - # don't allow moving to pages with # in
392 - if ( !$nt || $nt->getFragment() != '' ) {
393 - $this->showForm( 'badtitletext' );
394 - return;
395 - }
396 -
397 - # Show a warning if the target file exists on a shared repo
398 - if ( $nt->getNamespace() == NS_FILE
399 - && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
400 - && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
401 - && wfFindFile( $nt ) )
402 - {
403 - $this->showForm( array('file-exists-sharedrepo') );
404 - return;
405 -
406 - }
407 -
408424 if ( $user->isAllowed( 'suppressredirect' ) ) {
409425 $createRedirect = $this->leaveRedirect;
410426 } else {
@@ -413,8 +429,7 @@
414430 # Do the actual move.
415431 $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
416432 if ( $error !== true ) {
417 - # @todo FIXME: Show all the errors in a list, not just the first one
418 - $this->showForm( reset( $error ) );
 433+ $this->showForm( $error );
419434 return;
420435 }
421436

Follow-up revisions

RevisionCommit summaryAuthorDate
r108806Per Aaron, fix for r107776: correct count() checkialex13:28, 13 January 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   01:22, 10 January 2012
198 	if ( count( $err ) ) {

Should this be "if ( count == 1 )" ?

#Comment by IAlex (talk | contribs)   13:29, 13 January 2012

Fixed in r108806.

Status & tagging log