Fixed r63018: made it possible to delte half-baked images w/o descriptions, clearer...
authorMax Semenik <maxsem@users.mediawiki.org>
Mon, 6 Feb 2012 15:21:10 +0000 (15:21 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Mon, 6 Feb 2012 15:21:10 +0000 (15:21 +0000)
RELEASE-NOTES-1.19
includes/FileDeleteForm.php
includes/WikiPage.php

index 8553df9..cbee2e2 100644 (file)
@@ -245,6 +245,7 @@ production.
 * (bug 34114) CSSMin::remap() doesn't respect its $embed parameter
 * Special:Contributions/newbies now shows the contributions for the user "newbies".
   New user contributions are obtained using the form or using ?contribs=newbie in URL.
+* It is now possible to delete images that have no corresponding description pages.
 
 === API changes in 1.19 ===
 * Made action=edit less likely to return "unknownerror", by returning the actual error
index d9f3e1b..2d9a63f 100644 (file)
@@ -117,7 +117,7 @@ class FileDeleteForm {
         * Really delete the file
         *
         * @param $title Title object
-        * @param $file File object
+        * @param File $file: file object
         * @param $oldimage String: archive name
         * @param $reason String: reason of the deletion
         * @param $suppress Boolean: whether to mark all deleted versions as restricted
@@ -142,15 +142,17 @@ class FileDeleteForm {
                                $log->addEntry( 'delete', $title, $logComment );
                        }
                } else {
-                       $status = Status::newFatal( 'error' );
+                       $status = Status::newFatal( 'cannotdelete',
+                               wfEscapeWikiText( $title->getPrefixedText() )
+                       );
                        $page = WikiPage::factory( $title );
                        $dbw = wfGetDB( DB_MASTER );
                        try {
                                // delete the associated article first
                                $error = '';
-                               if ( $page->doDeleteArticle( $reason, $suppress, 0, false, $error, $user ) ) {
+                               if ( $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user ) >= Page::DELETE_SUCCESS ) {
                                        $status = $file->delete( $reason, $suppress );
-                                       if( $status->ok ) {
+                                       if( $status->isOK() ) {
                                                $dbw->commit();
                                        } else {
                                                $dbw->rollback();
@@ -163,7 +165,7 @@ class FileDeleteForm {
                        }
                }
 
-               if ( $status->isGood() ) {
+               if ( $status->isOK() ) {
                        wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) );
                }
 
index 45d3ebf..d753f91 100644 (file)
@@ -2,7 +2,30 @@
 /**
  * Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
  */
-abstract class Page {}
+abstract class Page {
+       // doDeleteArticleReal() return values. Values less than zero indicate fatal errors,
+       // values greater than zero indicate that there were non-fatal problems.
+
+       /**
+        * Delete operation aborted by hook
+        */
+       const DELETE_HOOK_ABORTED = -1;
+
+       /**
+        * Deletion successful
+        */
+       const DELETE_SUCCESS = 0;
+
+       /**
+        * Page not found
+        */
+       const DELETE_NO_PAGE = 1;
+
+       /**
+        * No revisions found to delete
+        */
+       const DELETE_NO_REVISIONS = 2;
+}
 
 /**
  * Class representing a MediaWiki article and history.
@@ -1889,7 +1912,7 @@ class WikiPage extends Page {
        }
 
        /**
-        * Back-end article deletion
+        * Same as doDeleteArticleReal(), but returns more detailed success/failure status
         * Deletes the article with database consistency, writes logs, purges caches
         *
         * @param $reason string delete reason for deletion log
@@ -1901,11 +1924,34 @@ class WikiPage extends Page {
         * @param $id int article ID
         * @param $commit boolean defaults to true, triggers transaction end
         * @param &$error Array of errors to append to
-        * @param $user User The relevant user
+        * @param $user User The deleting user
         * @return boolean true if successful
         */
        public function doDeleteArticle(
                $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
+       ) {
+               return $this->doDeleteArticleReal( $reason, $suppress, $id, $commit, $error, $user )
+                       != Page::DELETE_SUCCESS;
+       }
+
+       /**
+        * Back-end article deletion
+        * Deletes the article with database consistency, writes logs, purges caches
+        *
+        * @param $reason string delete reason for deletion log
+        * @param $suppress bitfield
+        *      Revision::DELETED_TEXT
+        *      Revision::DELETED_COMMENT
+        *      Revision::DELETED_USER
+        *      Revision::DELETED_RESTRICTED
+        * @param $id int article ID
+        * @param $commit boolean defaults to true, triggers transaction end
+        * @param &$error Array of errors to append to
+        * @param $user User The deleting user
+        * @return int: One of Page::DELETE_* constants
+        */
+       public function doDeleteArticleReal(
+               $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
        ) {
                global $wgUser;
                $user = is_null( $user ) ? $wgUser : $user;
@@ -1913,14 +1959,14 @@ class WikiPage extends Page {
                wfDebug( __METHOD__ . "\n" );
 
                if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error ) ) ) {
-                       return false;
+                       return Page::DELETE_HOOK_ABORTED;
                }
                $dbw = wfGetDB( DB_MASTER );
                $t = $this->mTitle->getDBkey();
                $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
 
                if ( $t === '' || $id == 0 ) {
-                       return false;
+                       return Page::DELETE_NO_PAGE;
                }
 
                // Bitfields to further suppress the content
@@ -1976,7 +2022,7 @@ class WikiPage extends Page {
 
                if ( !$ok ) {
                        $dbw->rollback();
-                       return false;
+                       return Page::DELETE_NO_REVISIONS;
                }
 
                $this->doDeleteUpdates( $id );
@@ -1996,7 +2042,7 @@ class WikiPage extends Page {
                }
 
                wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
-               return true;
+               return Page::DELETE_SUCCESS;
        }
 
        /**