Merge "fix hardcoded quote in Special:DoubleRedirects/BrokenRedirects"
[lhc/web/wiklou.git] / includes / specials / SpecialRevisiondelete.php
index be432ac..305d13b 100644 (file)
@@ -133,7 +133,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        $this->ids = explode( ',', $ids );
                } else {
                        # Array input
-                       $this->ids = array_keys( $request->getArray('ids',array()) );
+                       $this->ids = array_keys( $request->getArray( 'ids', array() ) );
                }
                // $this->ids = array_map( 'intval', $this->ids );
                $this->ids = array_unique( array_filter( $this->ids ) );
@@ -147,6 +147,19 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                } else {
                        $this->typeName = $request->getVal( 'type' );
                        $this->targetObj = Title::newFromText( $request->getText( 'target' ) );
+                       if ( $this->targetObj && $this->targetObj->isSpecial( 'Log' ) ) {
+                               $result = wfGetDB( DB_SLAVE )->select( 'logging',
+                                       'log_type',
+                                       array( 'log_id' => $this->ids ),
+                                       __METHOD__,
+                                       array( 'DISTINCT' )
+                               );
+
+                               if ( $result->numRows() == 1 ) {
+                                       // If there's only one type, the target can be set to include it.
+                                       $this->targetObj = SpecialPage::getTitleFor( 'Log', $result->current()->log_type );
+                               }
+                       }
                }
 
                # For reviewing deleted files...
@@ -163,8 +176,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
                # No targets?
                if( !isset( self::$allowedTypes[$this->typeName] ) || count( $this->ids ) == 0 ) {
-                       $output->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
-                       return;
+                       throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
                }
                $this->typeInfo = self::$allowedTypes[$this->typeName];
                $this->mIsAllowed = $user->isAllowed( $this->typeInfo['permission'] );
@@ -179,7 +191,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
                $this->otherReason = $request->getVal( 'wpReason' );
                # We need a target page!
-               if( is_null($this->targetObj) ) {
+               if( is_null( $this->targetObj ) ) {
                        $output->addWikiMsg( 'undelete-header' );
                        return;
                }
@@ -192,7 +204,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
                        array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER )
                );
-               if( $user->isAllowed('suppressrevision') ) {
+               if( $user->isAllowed( 'suppressrevision' ) ) {
                        $this->checks[] = array( 'revdelete-hide-restricted',
                                'wpHideRestricted', Revision::DELETED_RESTRICTED );
                }
@@ -206,12 +218,14 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
                $qc = $this->getLogQueryCond();
                # Show relevant lines from the deletion log
-               $output->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
+               $deleteLogPage = new LogPage( 'delete' );
+               $output->addHTML( "<h2>" . $deleteLogPage->getName()->escaped() . "</h2>\n" );
                LogEventsList::showLogExtract( $output, 'delete',
                        $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) );
                # Show relevant lines from the suppression log
                if( $user->isAllowed( 'suppressionlog' ) ) {
-                       $output->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
+                       $suppressLogPage = new LogPage( 'suppress' );
+                       $output->addHTML( "<h2>" . $suppressLogPage->getName()->escaped() . "</h2>\n" );
                        LogEventsList::showLogExtract( $output, 'suppress',
                                $this->targetObj, '', array( 'lim' => 25, 'conds' => $qc ) );
                }
@@ -239,7 +253,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                                        array( 'action' => 'history' )
                                );
                                # Link to deleted edits
-                               if( $this->getUser()->isAllowed('undelete') ) {
+                               if( $this->getUser()->isAllowed( 'undelete' ) ) {
                                        $undelete = SpecialPage::getTitleFor( 'Undelete' );
                                        $links[] = Linker::linkKnown(
                                                $undelete,
@@ -284,11 +298,10 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $user = $this->getUser();
                if( !$oimage->userCan( File::DELETED_FILE, $user ) ) {
                        if( $oimage->isDeleted( File::DELETED_RESTRICTED ) ) {
-                               $this->getOutput()->permissionRequired( 'suppressrevision' );
+                               throw new PermissionsError( 'suppressrevision' );
                        } else {
-                               $this->getOutput()->permissionRequired( 'deletedtext' );
+                               throw new PermissionsError( 'deletedtext' );
                        }
-                       return;
                }
                if ( !$user->matchEditToken( $this->token, $archiveName ) ) {
                        $lang = $this->getLanguage();
@@ -343,7 +356,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $UserAllowed = true;
 
                if ( $this->typeName == 'logging' ) {
-                       $this->getOutput()->addWikiMsg( 'logdelete-selected', $this->getLanguage()->formatNum( count($this->ids) ) );
+                       $this->getOutput()->addWikiMsg( 'logdelete-selected', $this->getLanguage()->formatNum( count( $this->ids ) ) );
                } else {
                        $this->getOutput()->addWikiMsg( 'revdelete-selected',
                                $this->targetObj->getPrefixedText(), count( $this->ids ) );
@@ -358,8 +371,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        $item = $list->current();
                        if ( !$item->canView() ) {
                                if( !$this->submitClicked ) {
-                                       $this->getOutput()->permissionRequired( 'suppressrevision' );
-                                       return;
+                                       throw new PermissionsError( 'suppressrevision' );
                                }
                                $UserAllowed = false;
                        }
@@ -368,8 +380,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                }
 
                if( !$numRevisions ) {
-                       $this->getOutput()->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
-                       return;
+                       throw new ErrorPageError( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
                }
 
                $this->getOutput()->addHTML( "</ul>" );
@@ -506,11 +517,12 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
 
        /**
         * UI entry point for form submission.
+        * @throws PermissionsError
         * @return bool
         */
        protected function submit() {
                # Check edit token on submission
-               $token = $this->getRequest()->getVal('wpEditToken');
+               $token = $this->getRequest()->getVal( 'wpEditToken' );
                if( $this->submitClicked && !$this->getUser()->matchEditToken( $token ) ) {
                        $this->getOutput()->addWikiMsg( 'sessionfailure' );
                        return false;
@@ -525,9 +537,8 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        $comment = $this->otherReason;
                }
                # Can the user set this field?
-               if( $bitParams[Revision::DELETED_RESTRICTED]==1 && !$this->getUser()->isAllowed('suppressrevision') ) {
-                       $this->getOutput()->permissionRequired( 'suppressrevision' );
-                       return false;
+               if( $bitParams[Revision::DELETED_RESTRICTED] == 1 && !$this->getUser()->isAllowed( 'suppressrevision' ) ) {
+                       throw new PermissionsError( 'suppressrevision' );
                }
                # If the save went through, go to success message...
                $status = $this->save( $bitParams, $comment, $this->targetObj );
@@ -575,7 +586,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        }
                        $bitfield[$field] = $val;
                }
-               if( !isset($bitfield[Revision::DELETED_RESTRICTED]) ) {
+               if( !isset( $bitfield[Revision::DELETED_RESTRICTED] ) ) {
                        $bitfield[Revision::DELETED_RESTRICTED] = 0;
                }
                return $bitfield;
@@ -613,4 +624,3 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                );
        }
 }
-