MediaWiki  master
RollbackAction.php
Go to the documentation of this file.
1 <?php
29 
30  public function getName() {
31  return 'rollback';
32  }
33 
34  public function getRestriction() {
35  return 'rollback';
36  }
37 
49  public function onView() {
50  // TODO: use $this->useTransactionalTimeLimit(); when POST only
52 
53  $request = $this->getRequest();
54  $user = $this->getUser();
55  $from = $request->getVal( 'from' );
56  $rev = $this->page->getRevision();
57  if ( $from === null || $from === '' ) {
58  throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
59  }
60  if ( $from !== $rev->getUserText() ) {
61  throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
62  $this->getTitle()->getPrefixedText(),
63  $from,
64  $rev->getUserText()
65  ] );
66  }
67 
68  $data = null;
69  $errors = $this->page->doRollback(
70  $from,
71  $request->getText( 'summary' ),
72  $request->getVal( 'token' ),
73  $request->getBool( 'bot' ),
74  $data,
75  $this->getUser()
76  );
77 
78  if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
79  throw new ThrottledError;
80  }
81 
82  if ( isset( $errors[0][0] ) &&
83  ( $errors[0][0] == 'alreadyrolled' || $errors[0][0] == 'cantrollback' )
84  ) {
85  $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
86  $errArray = $errors[0];
87  $errMsg = array_shift( $errArray );
88  $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
89 
90  if ( isset( $data['current'] ) ) {
92  $current = $data['current'];
93 
94  if ( $current->getComment() != '' ) {
95  $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
96  Linker::formatComment( $current->getComment() ) )->parse() );
97  }
98  }
99 
100  return;
101  }
102 
103  # NOTE: Permission errors already handled by Action::checkExecute.
104  if ( $errors == [ [ 'readonlytext' ] ] ) {
105  throw new ReadOnlyError;
106  }
107 
108  # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
109  # Right now, we only show the first error
110  foreach ( $errors as $error ) {
111  throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
112  }
113 
115  $current = $data['current'];
116  $target = $data['target'];
117  $newId = $data['newid'];
118  $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
119  $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
120 
121  $old = Linker::revUserTools( $current );
122  $new = Linker::revUserTools( $target );
123  $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
124  ->parseAsBlock() );
125 
126  if ( $user->getBoolOption( 'watchrollback' ) ) {
127  $user->addWatch( $this->page->getTitle(), User::IGNORE_USER_RIGHTS );
128  }
129 
130  $this->getOutput()->returnToMain( false, $this->getTitle() );
131 
132  if ( !$request->getBool( 'hidediff', false ) &&
133  !$this->getUser()->getBoolOption( 'norollbackdiff' )
134  ) {
135  $contentHandler = $current->getContentHandler();
136  $de = $contentHandler->createDifferenceEngine(
137  $this->getContext(),
138  $current->getId(),
139  $newId,
140  false,
141  true
142  );
143  $de->showDiff( '', '' );
144  }
145  return;
146  }
147 
148  protected function getDescription() {
149  return '';
150  }
151 
152  public function doesWrites() {
153  return true;
154  }
155 }
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:207
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:246
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
User interface for the rollback action.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1816
An error page which can definitely be safely rendered using the OutputPage.
const IGNORE_USER_RIGHTS
Definition: User.php:84
getContext()
Get the IContextSource in use here.
Definition: Action.php:178
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1601
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static formatComment($comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1181
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
An action which just does something, without showing a form first.
$from
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2458
wfTransactionalTimeLimit()
Set PHP's time limit to the larger of php.ini or $wgTransactionalTimeLimit.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:197
static revUserTools($rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1142
onView()
Temporarily unused message keys due to T88044/T136375:
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk page
Definition: hooks.txt:2376
Show an error when the user hits a rate limit.