MediaWiki  REL1_24
RollbackAction.php
Go to the documentation of this file.
00001 <?php
00028 class RollbackAction extends FormlessAction {
00029 
00030     public function getName() {
00031         return 'rollback';
00032     }
00033 
00034     public function getRestriction() {
00035         return 'rollback';
00036     }
00037 
00038     public function onView() {
00039         $details = null;
00040 
00041         $request = $this->getRequest();
00042         $user = $this->getUser();
00043 
00044         $result = $this->page->doRollback(
00045             $request->getVal( 'from' ),
00046             $request->getText( 'summary' ),
00047             $request->getVal( 'token' ),
00048             $request->getBool( 'bot' ),
00049             $details,
00050             $this->getUser()
00051         );
00052 
00053         if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
00054             throw new ThrottledError;
00055         }
00056 
00057         if ( isset( $result[0][0] ) &&
00058             ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' )
00059         ) {
00060             $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
00061             $errArray = $result[0];
00062             $errMsg = array_shift( $errArray );
00063             $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
00064 
00065             if ( isset( $details['current'] ) ) {
00067                 $current = $details['current'];
00068 
00069                 if ( $current->getComment() != '' ) {
00070                     $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
00071                         Linker::formatComment( $current->getComment() ) )->parse() );
00072                 }
00073             }
00074 
00075             return;
00076         }
00077 
00078         #NOTE: Permission errors already handled by Action::checkExecute.
00079 
00080         if ( $result == array( array( 'readonlytext' ) ) ) {
00081             throw new ReadOnlyError;
00082         }
00083 
00084         #XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
00085         #     Right now, we only show the first error
00086         foreach ( $result as $error ) {
00087             throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
00088         }
00089 
00091         $current = $details['current'];
00092         $target = $details['target'];
00093         $newId = $details['newid'];
00094         $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
00095         $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
00096 
00097         $old = Linker::revUserTools( $current );
00098         $new = Linker::revUserTools( $target );
00099         $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
00100             ->parseAsBlock() );
00101 
00102         if ( $user->getBoolOption( 'watchrollback' ) ) {
00103             $user->addWatch( $this->page->getTitle(), WatchedItem::IGNORE_USER_RIGHTS );
00104         }
00105 
00106         $this->getOutput()->returnToMain( false, $this->getTitle() );
00107 
00108         if ( !$request->getBool( 'hidediff', false ) &&
00109             !$this->getUser()->getBoolOption( 'norollbackdiff', false )
00110         ) {
00111             $contentHandler = $current->getContentHandler();
00112             $de = $contentHandler->createDifferenceEngine(
00113                 $this->getContext(),
00114                 $current->getId(),
00115                 $newId,
00116                 false,
00117                 true
00118             );
00119             $de->showDiff( '', '' );
00120         }
00121     }
00122 
00123     protected function getDescription() {
00124         return '';
00125     }
00126 }