MediaWiki  1.33.0
RollbackAction.php
Go to the documentation of this file.
1 <?php
28 class RollbackAction extends FormAction {
29 
30  public function getName() {
31  return 'rollback';
32  }
33 
34  public function getRestriction() {
35  return 'rollback';
36  }
37 
38  protected function usesOOUI() {
39  return true;
40  }
41 
42  protected function getDescription() {
43  return '';
44  }
45 
46  public function doesWrites() {
47  return true;
48  }
49 
50  public function onSuccess() {
51  return false;
52  }
53 
54  public function onSubmit( $data ) {
55  return false;
56  }
57 
58  protected function alterForm( HTMLForm $form ) {
59  $form->setWrapperLegendMsg( 'confirm-rollback-top' );
60  $form->setSubmitTextMsg( 'confirm-rollback-button' );
61  $form->setTokenSalt( 'rollback' );
62 
63  $from = $this->getRequest()->getVal( 'from' );
64  if ( $from === null ) {
65  throw new BadRequestError( 'rollbackfailed', 'rollback-missingparam' );
66  }
67  foreach ( [ 'from', 'bot', 'hidediff', 'summary', 'token' ] as $param ) {
68  $val = $this->getRequest()->getVal( $param );
69  if ( $val !== null ) {
70  $form->addHiddenField( $param, $val );
71  }
72  }
73  }
74 
80  public function show() {
81  if ( $this->getUser()->getOption( 'showrollbackconfirmation' ) == false ||
82  $this->getRequest()->wasPosted() ) {
83  $this->handleRollbackRequest();
84  } else {
86  }
87  }
88 
89  public function handleRollbackRequest() {
91 
92  $request = $this->getRequest();
93  $user = $this->getUser();
94  $from = $request->getVal( 'from' );
95  $rev = $this->page->getRevision();
96  if ( $from === null ) {
97  throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
98  }
99  if ( !$rev ) {
100  throw new ErrorPageError( 'rollbackfailed', 'rollback-missingrevision' );
101  }
102  if ( $from !== $rev->getUserText() ) {
103  throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
104  $this->getTitle()->getPrefixedText(),
105  $from,
106  $rev->getUserText()
107  ] );
108  }
109 
110  $data = null;
111  $errors = $this->page->doRollback(
112  $from,
113  $request->getText( 'summary' ),
114  $request->getVal( 'token' ),
115  $request->getBool( 'bot' ),
116  $data,
117  $this->getUser()
118  );
119 
120  if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
121  throw new ThrottledError;
122  }
123 
124  if ( $this->hasRollbackRelatedErrors( $errors ) ) {
125  $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
126  $errArray = $errors[0];
127  $errMsg = array_shift( $errArray );
128  $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
129 
130  if ( isset( $data['current'] ) ) {
132  $current = $data['current'];
133 
134  if ( $current->getComment() != '' ) {
135  $this->getOutput()->addWikiMsg(
136  'editcomment',
137  Message::rawParam(
138  Linker::formatComment( $current->getComment() )
139  )
140  );
141  }
142  }
143 
144  return;
145  }
146 
147  # NOTE: Permission errors already handled by Action::checkExecute.
148  if ( $errors == [ [ 'readonlytext' ] ] ) {
149  throw new ReadOnlyError;
150  }
151 
152  # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
153  # Right now, we only show the first error
154  foreach ( $errors as $error ) {
155  throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
156  }
157 
159  $current = $data['current'];
160  $target = $data['target'];
161  $newId = $data['newid'];
162  $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
163  $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
164 
165  $old = Linker::revUserTools( $current );
166  $new = Linker::revUserTools( $target );
167  $this->getOutput()->addHTML(
168  $this->msg( 'rollback-success' )
169  ->rawParams( $old, $new )
170  ->params( $current->getUserText( Revision::FOR_THIS_USER, $user ) )
171  ->params( $target->getUserText( Revision::FOR_THIS_USER, $user ) )
172  ->parseAsBlock()
173  );
174 
175  if ( $user->getBoolOption( 'watchrollback' ) ) {
176  $user->addWatch( $this->page->getTitle(), User::IGNORE_USER_RIGHTS );
177  }
178 
179  $this->getOutput()->returnToMain( false, $this->getTitle() );
180 
181  if ( !$request->getBool( 'hidediff', false ) &&
182  !$this->getUser()->getBoolOption( 'norollbackdiff' )
183  ) {
184  $contentHandler = $current->getContentHandler();
185  $de = $contentHandler->createDifferenceEngine(
186  $this->getContext(),
187  $current->getId(),
188  $newId,
189  false,
190  true
191  );
192  $de->showDiff( '', '' );
193  }
194  }
195 
200  private function enableTransactionalTimelimit() {
201  // If Rollbacks are made POST-only, use $this->useTransactionalTimeLimit()
203  if ( !$this->getRequest()->wasPosted() ) {
208  $fname = __METHOD__;
209  $trxLimits = $this->context->getConfig()->get( 'TrxProfilerLimits' );
210  $trxProfiler = Profiler::instance()->getTransactionProfiler();
211  $trxProfiler->redefineExpectations( $trxLimits['POST'], $fname );
212  DeferredUpdates::addCallableUpdate( function () use ( $trxProfiler, $trxLimits, $fname
213  ) {
214  $trxProfiler->redefineExpectations( $trxLimits['PostSend-POST'], $fname );
215  } );
216  }
217  }
218 
219  private function showRollbackConfirmationForm() {
220  $form = $this->getForm();
221  if ( $form->show() ) {
222  $this->onSuccess();
223  }
224  }
225 
226  protected function getFormFields() {
227  return [
228  'intro' => [
229  'type' => 'info',
230  'vertical-label' => true,
231  'raw' => true,
232  'default' => $this->msg( 'confirm-rollback-bottom' )->parse()
233  ]
234  ];
235  }
236 
237  private function hasRollbackRelatedErrors( array $errors ) {
238  return isset( $errors[0][0] ) &&
239  ( $errors[0][0] == 'alreadyrolled' ||
240  $errors[0][0] == 'cantrollback'
241  );
242  }
243 }
ReadOnlyError
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Definition: ReadOnlyError.php:28
RollbackAction\showRollbackConfirmationForm
showRollbackConfirmationForm()
Definition: RollbackAction.php:219
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
RollbackAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: RollbackAction.php:58
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:62
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:198
RollbackAction\show
show()
Definition: RollbackAction.php:80
RollbackAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: RollbackAction.php:42
HTMLForm\setTokenSalt
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:999
FormAction
An action which shows a form and does something based on the input from the form.
Definition: FormAction.php:28
page
target page
Definition: All_system_messages.txt:1267
RollbackAction\handleRollbackRequest
handleRollbackRequest()
Definition: RollbackAction.php:89
RollbackAction\getFormFields
getFormFields()
Get an HTMLForm descriptor array.
Definition: RollbackAction.php:226
php
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
Revision\FOR_THIS_USER
const FOR_THIS_USER
Definition: Revision.php:55
RollbackAction\usesOOUI
usesOOUI()
Whether the form should use OOUI.
Definition: RollbackAction.php:38
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:179
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
Action\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:257
wfTransactionalTimeLimit
wfTransactionalTimeLimit()
Set PHP's time limit to the larger of php.ini or $wgTransactionalTimeLimit.
Definition: GlobalFunctions.php:2895
HTMLForm\addHiddenField
addHiddenField( $name, $value, array $attribs=[])
Add a hidden field to the output.
Definition: HTMLForm.php:909
RollbackAction\onSubmit
onSubmit( $data)
Process the form on POST submission.
Definition: RollbackAction.php:54
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ThrottledError
Show an error when the user hits a rate limit.
Definition: ThrottledError.php:27
RollbackAction\enableTransactionalTimelimit
enableTransactionalTimelimit()
Enables transactional time limit for POST and GET requests to RollbackAction.
Definition: RollbackAction.php:200
Linker\revUserTools
static revUserTools( $rev, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1086
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
FormAction\getForm
getForm()
Get the HTMLForm to control behavior.
Definition: FormAction.php:73
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:123
$request
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2636
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:218
RollbackAction\hasRollbackRelatedErrors
hasRollbackRelatedErrors(array $errors)
Definition: RollbackAction.php:237
RollbackAction\getRestriction
getRestriction()
Get the permission required to perform this action.
Definition: RollbackAction.php:34
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:247
Linker\formatComment
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:1122
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1371
RollbackAction
User interface for the rollback action.
Definition: RollbackAction.php:28
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1545
$rev
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:1769
as
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
BadRequestError
An error page that emits an HTTP 400 Bad Request status code.
Definition: BadRequestError.php:27
true
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:1985
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:208
RollbackAction\doesWrites
doesWrites()
Indicates whether this action may perform database writes.
Definition: RollbackAction.php:46
User\IGNORE_USER_RIGHTS
const IGNORE_USER_RIGHTS
Definition: User.php:78
RollbackAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Definition: RollbackAction.php:50
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:118
RollbackAction\getName
getName()
Return the name of the action this object responds to.
Definition: RollbackAction.php:30
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:133