MediaWiki  REL1_21
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 
00043                 $result = $this->page->doRollback(
00044                         $request->getVal( 'from' ),
00045                         $request->getText( 'summary' ),
00046                         $request->getVal( 'token' ),
00047                         $request->getBool( 'bot' ),
00048                         $details,
00049                         $this->getUser()
00050                 );
00051 
00052                 if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
00053                         throw new ThrottledError;
00054                 }
00055 
00056                 if ( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
00057                         $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
00058                         $errArray = $result[0];
00059                         $errMsg = array_shift( $errArray );
00060                         $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
00061 
00062                         if ( isset( $details['current'] ) ) {
00063                                 $current = $details['current'];
00064 
00065                                 if ( $current->getComment() != '' ) {
00066                                         $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
00067                                                 Linker::formatComment( $current->getComment() ) )->parse() );
00068                                 }
00069                         }
00070 
00071                         return;
00072                 }
00073 
00074                 #NOTE: Permission errors already handled by Action::checkExecute.
00075 
00076                 if ( $result == array( array( 'readonlytext' ) ) ) {
00077                         throw new ReadOnlyError;
00078                 }
00079 
00080                 #XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
00081                 #     Right now, we only show the first error
00082                 foreach ( $result as $error ) {
00083                         throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
00084                 }
00085 
00086                 $current = $details['current'];
00087                 $target = $details['target'];
00088                 $newId = $details['newid'];
00089                 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
00090                 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
00091 
00092                 $old = Linker::revUserTools( $current );
00093                 $new = Linker::revUserTools( $target );
00094                 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )->parseAsBlock() );
00095                 $this->getOutput()->returnToMain( false, $this->getTitle() );
00096 
00097                 if ( !$request->getBool( 'hidediff', false ) && !$this->getUser()->getBoolOption( 'norollbackdiff', false ) ) {
00098                         $contentHandler = $current->getContentHandler();
00099                         $de = $contentHandler->createDifferenceEngine( $this->getContext(), $current->getId(), $newId, false, true );
00100                         $de->showDiff( '', '' );
00101                 }
00102         }
00103 
00104         protected function getDescription() {
00105                 return '';
00106         }
00107 }