r103202 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103201‎ | r103202 | r103203 >
Date:18:08, 15 November 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Factorise common code in ImagePage::delete() and allow normal page deletion if $wgUploadMaintenance is true
* Moved $wgUploadMaintenance check after permissions and read only, so that the user doesn't think the error is temporary if he both doesn't have the permission and $wgUploadMaintenance is true
* Show normal error page when $wgUploadMaintenance and added a message for the error title
* Moved watchlist updating to FileDeletForm::execute(), it has nothing to do in doDelete() (would also be executed for api requests, etc.)
* Added $user parameter to FileDeletForm::doDelete() to pass the user doing the action
* Use WikiPage instead of Article
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/FileDeleteForm.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesQqq.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1481,6 +1481,7 @@
14821482 'filedelete-reason-dropdown',
14831483 'filedelete-edit-reasonlist',
14841484 'filedelete-maintenance',
 1485+ 'filedelete-maintenance-title',
14851486 ),
14861487 'mimesearch' => array(
14871488 'mimesearch',
Index: trunk/phase3/docs/hooks.txt
@@ -874,7 +874,7 @@
875875 $file: reference to the deleted file
876876 $oldimage: in case of the deletion of an old image, the name of the old file
877877 $article: in case all revisions of the file are deleted a reference to the
878 - article associated with the file.
 878+ WikiFilePage associated with the file.
879879 $user: user who performed the deletion
880880 $reason: reason
881881
Index: trunk/phase3/includes/ImagePage.php
@@ -789,19 +789,15 @@
790790 */
791791 public function delete() {
792792 global $wgUploadMaintenance;
793 - if ( $wgUploadMaintenance && $this->getTitle() && $this->getTitle()->getNamespace() == NS_FILE ) {
794 - global $wgOut;
795 - $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
796 - return;
797 - }
798793
799 - $this->loadFile();
800 - if ( !$this->mPage->getFile()->exists() || !$this->mPage->getFile()->isLocal() || $this->mPage->getFile()->getRedirected() ) {
 794+ $file = $this->mPage->getFile();
 795+ if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
801796 // Standard article deletion
802797 parent::delete();
803798 return;
804799 }
805 - $deleter = new FileDeleteForm( $this->mPage->getFile() );
 800+
 801+ $deleter = new FileDeleteForm( $file );
806802 $deleter->execute();
807803 }
808804
Index: trunk/phase3/includes/FileDeleteForm.php
@@ -39,7 +39,7 @@
4040 * pending authentication, confirmation, etc.
4141 */
4242 public function execute() {
43 - global $wgOut, $wgRequest, $wgUser;
 43+ global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance;
4444
4545 $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser );
4646 if ( count( $permissionErrors ) ) {
@@ -50,6 +50,10 @@
5151 throw new ReadOnlyError;
5252 }
5353
 54+ if ( $wgUploadMaintenance ) {
 55+ throw new ErrorPageError( 'filedelete-maintenance-title', 'filedelete-maintenance' );
 56+ }
 57+
5458 $this->setHeaders();
5559
5660 $this->oldimage = $wgRequest->getText( 'oldimage', false );
@@ -81,7 +85,7 @@
8286 $reason = $deleteReasonList;
8387 }
8488
85 - $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress );
 89+ $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser );
8690
8791 if( !$status->isGood() ) {
8892 $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
@@ -95,6 +99,12 @@
96100 // Return to the main page if we just deleted all versions of the
97101 // file, otherwise go back to the description page
98102 $wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() );
 103+
 104+ if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
 105+ WatchAction::doWatch( $title, $wgUser );
 106+ } elseif ( $this->title->userIsWatching() ) {
 107+ WatchAction::doUnwatch( $title, $wgUser );
 108+ }
99109 }
100110 return;
101111 }
@@ -111,13 +121,16 @@
112122 * @param $oldimage String: archive name
113123 * @param $reason String: reason of the deletion
114124 * @param $suppress Boolean: whether to mark all deleted versions as restricted
 125+ * @param $user User object performing the request
115126 */
116 - public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) {
117 - global $wgUser;
118 - $article = null;
119 - $status = Status::newFatal( 'error' );
 127+ public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress, User $user = null ) {
 128+ if ( $user === null ) {
 129+ global $wgUser;
 130+ $user = $wgUser;
 131+ }
120132
121133 if( $oldimage ) {
 134+ $page = null;
122135 $status = $file->deleteOld( $oldimage, $reason, $suppress );
123136 if( $status->ok ) {
124137 // Need to do a log item
@@ -129,18 +142,14 @@
130143 $log->addEntry( 'delete', $title, $logComment );
131144 }
132145 } else {
 146+ $status = Status::newFatal( 'error' );
133147 $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
134 - $article = new Article( $title );
 148+ $page = WikiPage::factory( $title );
135149 $dbw = wfGetDB( DB_MASTER );
136150 try {
137151 // delete the associated article first
138 - if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
139 - global $wgRequest;
140 - if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
141 - WatchAction::doWatch( $title, $wgUser );
142 - } elseif ( $title->userIsWatching() ) {
143 - WatchAction::doUnwatch( $title, $wgUser );
144 - }
 152+ $error = '';
 153+ if ( $page->doDeleteArticle( $reason, $suppress, $id, false, $error, $user ) ) {
145154 $status = $file->delete( $reason, $suppress );
146155 if( $status->ok ) {
147156 $dbw->commit();
@@ -154,9 +163,11 @@
155164 throw $e;
156165 }
157166 }
158 - if( $status->isGood() )
159 - wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
160167
 168+ if ( $status->isGood() ) {
 169+ wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) );
 170+ }
 171+
161172 return $status;
162173 }
163174
Index: trunk/phase3/languages/messages/MessagesQqq.php
@@ -2015,30 +2015,32 @@
20162016 {{Identical|Revert}}',
20172017
20182018 # File deletion
2019 -'filedelete-legend' => '{{Identical|Delete}}',
2020 -'filedelete-intro-old' => 'Message displayed when you try to delete a version of a file.
 2019+'filedelete-legend' => '{{Identical|Delete}}',
 2020+'filedelete-intro-old' => 'Message displayed when you try to delete a version of a file.
20212021 * $1 is the name of the media
20222022 * $2 is a date
20232023 * $3 is a hour
20242024 * $4 is a URL and must follow square bracket: [$4',
2025 -'filedelete-comment' => '{{Identical|Reason}}',
2026 -'filedelete-submit' => 'Delete button when deleting a file for admins
 2025+'filedelete-comment' => '{{Identical|Reason}}',
 2026+'filedelete-submit' => 'Delete button when deleting a file for admins
20272027
20282028 {{Identical|Delete}}',
2029 -'filedelete-success-old' => 'Message displayed when you succeed in deleting a version of a file.
 2029+'filedelete-success-old' => 'Message displayed when you succeed in deleting a version of a file.
20302030 * $1 is the name of the media
20312031 * $2 is a date
20322032 * $3 is a hour',
2033 -'filedelete-otherreason' => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion.
 2033+'filedelete-otherreason' => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion.
20342034
20352035 {{Identical|Other/additional reason}}',
2036 -'filedelete-reason-otherlist' => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below.
 2036+'filedelete-reason-otherlist' => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below.
20372037
20382038 {{Identical|Other reason}}',
2039 -'filedelete-reason-dropdown' => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.',
2040 -'filedelete-edit-reasonlist' => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]].
 2039+'filedelete-reason-dropdown' => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.',
 2040+'filedelete-edit-reasonlist' => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]].
20412041
20422042 {{Identical|Edit delete reasons}}',
 2043+'filedelete-maintenance' => 'Content of the error page when $wgUploadMaintenance is set to true.',
 2044+'filedelete-maintenance-title' => 'Title of the error page when $wgUploadMaintenance is set to true.',
20432045
20442046 # MIME search
20452047 'mimesearch' => 'Title of [[Special:MIMESearch]].',
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2365,23 +2365,24 @@
23662366 'filerevert-badversion' => 'There is no previous local version of this file with the provided timestamp.',
23672367
23682368 # File deletion
2369 -'filedelete' => 'Delete $1',
2370 -'filedelete-legend' => 'Delete file',
2371 -'filedelete-intro' => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.",
2372 -'filedelete-intro-old' => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].",
2373 -'filedelete-comment' => 'Reason:',
2374 -'filedelete-submit' => 'Delete',
2375 -'filedelete-success' => "'''$1''' has been deleted.",
2376 -'filedelete-success-old' => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.",
2377 -'filedelete-nofile' => "'''$1''' does not exist.",
2378 -'filedelete-nofile-old' => "There is no archived version of '''$1''' with the specified attributes.",
2379 -'filedelete-otherreason' => 'Other/additional reason:',
2380 -'filedelete-reason-otherlist' => 'Other reason',
2381 -'filedelete-reason-dropdown' => '*Common delete reasons
 2369+'filedelete' => 'Delete $1',
 2370+'filedelete-legend' => 'Delete file',
 2371+'filedelete-intro' => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.",
 2372+'filedelete-intro-old' => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].",
 2373+'filedelete-comment' => 'Reason:',
 2374+'filedelete-submit' => 'Delete',
 2375+'filedelete-success' => "'''$1''' has been deleted.",
 2376+'filedelete-success-old' => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.",
 2377+'filedelete-nofile' => "'''$1''' does not exist.",
 2378+'filedelete-nofile-old' => "There is no archived version of '''$1''' with the specified attributes.",
 2379+'filedelete-otherreason' => 'Other/additional reason:',
 2380+'filedelete-reason-otherlist' => 'Other reason',
 2381+'filedelete-reason-dropdown' => '*Common delete reasons
23822382 ** Copyright violation
23832383 ** Duplicated file',
2384 -'filedelete-edit-reasonlist' => 'Edit delete reasons',
2385 -'filedelete-maintenance' => 'Deletion and restoration of files temporarily disabled during maintenance.',
 2384+'filedelete-edit-reasonlist' => 'Edit delete reasons',
 2385+'filedelete-maintenance' => 'Deletion and restoration of files temporarily disabled during maintenance.',
 2386+'filedelete-maintenance-title' => 'Cannot delete file',
23862387
23872388 # MIME search
23882389 'mimesearch' => 'MIME search',

Follow-up revisions

RevisionCommit summaryAuthorDate
r103320Follow-up r103202: removed unused global declarationialex13:17, 16 November 2011
r107713Per GrafZahl, fix for r103202: forgot to change two instances of $title to $t...ialex08:29, 31 December 2011

Comments

#Comment by GrafZahl (talk | contribs)   23:46, 30 December 2011

"Undefined variable title", when trying to delete a file and changing the watched status.

Did you mean $this->title in lines 104 and 106?

#Comment by IAlex (talk | contribs)   08:30, 31 December 2011

Fixed in r107713.

Status & tagging log