(bug 31363) Expand description URLs for thumbnails to canonical form
[lhc/web/wiklou.git] / includes / FileDeleteForm.php
index 030330b..ca195d8 100644 (file)
@@ -32,27 +32,24 @@ class FileDeleteForm {
                global $wgOut, $wgRequest, $wgUser;
                $this->setHeaders();
 
-               if( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
                $permission_errors = $this->title->getUserPermissionsErrors('delete', $wgUser);
-               if (count($permission_errors)>0) {
+               if ( count( $permission_errors ) > 0 ) {
                        $wgOut->showPermissionsErrorPage( $permission_errors );
                        return;
                }
 
+               if ( wfReadOnly() ) {
+                       throw new ReadOnlyError;
+               }
+
                $this->oldimage = $wgRequest->getText( 'oldimage', false );
                $token = $wgRequest->getText( 'wpEditToken' );
                # Flag to hide all contents of the archived revisions
                $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('suppressrevision');
 
-               if( $this->oldimage && !self::isValidOldSpec($this->oldimage) ) {
-                       $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) );
-                       return;
-               }
-               if( $this->oldimage )
+               if( $this->oldimage ) {
                        $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage );
+               }
 
                if( !self::haveDeletableFile($this->file, $this->oldfile, $this->oldimage) ) {
                        $wgOut->addHTML( $this->prepareMessage( 'filedelete-nofile' ) );
@@ -74,8 +71,12 @@ class FileDeleteForm {
 
                        $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress );
 
-                       if( !$status->isGood() )
+                       if( !$status->isGood() ) {
+                               $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
+                               $wgOut->addHTML( '<span class="error">' );
                                $wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) );
+                               $wgOut->addHTML( '</span>' );
+                       }
                        if( $status->ok ) {
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                                $wgOut->addHTML( $this->prepareMessage( 'filedelete-success' ) );
@@ -118,25 +119,21 @@ class FileDeleteForm {
                } else {
                        $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
                        $article = new Article( $title );
-                       $error = '';
                        $dbw = wfGetDB( DB_MASTER );
                        try {
-                               if( wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) {
-                                       // delete the associated article first
-                                       if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
-                                               global $wgRequest;
-                                               if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
-                                                       $article->doWatch();
-                                               } elseif( $title->userIsWatching() ) {
-                                                       $article->doUnwatch();
-                                               }
-                                               $status = $file->delete( $reason, $suppress );
-                                               if( $status->ok ) {
-                                                       $dbw->commit();
-                                                       wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) );
-                                               } else {
-                                                       $dbw->rollback();
-                                               }
+                               // delete the associated article first
+                               if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
+                                       global $wgRequest;
+                                       if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
+                                               WatchAction::doWatch( $title, $wgUser );
+                                       } elseif ( $title->userIsWatching() ) {
+                                               WatchAction::doUnwatch( $title, $wgUser );
+                                       }
+                                       $status = $file->delete( $reason, $suppress );
+                                       if( $status->ok ) {
+                                               $dbw->commit();
+                                       } else {
+                                               $dbw->rollback();
                                        }
                                }
                        } catch ( MWException $e ) {
@@ -145,7 +142,7 @@ class FileDeleteForm {
                                throw $e;
                        }
                }
-               if( $status->isGood() ) 
+               if( $status->isGood() )
                        wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
 
                return $status;
@@ -197,7 +194,7 @@ class FileDeleteForm {
                                "</td>
                        </tr>
                        {$suppress}";
-               if( $wgUser->isLoggedIn() ) {   
+               if( $wgUser->isLoggedIn() ) {
                        $form .= "
                        <tr>
                                <td></td>
@@ -220,9 +217,8 @@ class FileDeleteForm {
                        Xml::closeElement( 'form' );
 
                        if ( $wgUser->isAllowed( 'editinterface' ) ) {
-                               $skin = $wgUser->getSkin();
                                $title = Title::makeTitle( NS_MEDIAWIKI, 'Filedelete-reason-dropdown' );
-                               $link = $skin->link(
+                               $link = Linker::link(
                                        $title,
                                        wfMsgHtml( 'filedelete-edit-reasonlist' ),
                                        array(),
@@ -240,7 +236,7 @@ class FileDeleteForm {
        private function showLogEntries() {
                global $wgOut;
                $wgOut->addHTML( '<h2>' . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
-               LogEventsList::showLogExtract( $wgOut, 'delete', $this->title->getPrefixedText() );
+               LogEventsList::showLogExtract( $wgOut, 'delete', $this->title );
        }
 
        /**
@@ -257,15 +253,15 @@ class FileDeleteForm {
                        return wfMsgExt(
                                "{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
                                'parse',
-                               $this->title->getText(),
+                               wfEscapeWikiText( $this->title->getText() ),
                                $wgLang->date( $this->getTimestamp(), true ),
                                $wgLang->time( $this->getTimestamp(), true ),
-                               wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
+                               wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT ) );
                } else {
                        return wfMsgExt(
                                $message,
                                'parse',
-                               $this->title->getText()
+                               wfEscapeWikiText( $this->title->getText() )
                        );
                }
        }
@@ -274,18 +270,12 @@ class FileDeleteForm {
         * Set headers, titles and other bits
         */
        private function setHeaders() {
-               global $wgOut, $wgUser;
+               global $wgOut;
                $wgOut->setPageTitle( wfMsg( 'filedelete', $this->title->getText() ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setSubtitle( wfMsg(
                        'filedelete-backlink',
-                       $wgUser->getSkin()->link(
-                               $this->title,
-                               null,
-                               array(),
-                               array(),
-                               array( 'known', 'noclasses' )
-                       )
+                       Linker::linkKnown( $this->title )
                ) );
        }