MediaWiki  1.30.0
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 
50  public function onView() {
51  // TODO: use $this->useTransactionalTimeLimit(); when POST only
53 
54  $request = $this->getRequest();
55  $user = $this->getUser();
56  $from = $request->getVal( 'from' );
57  $rev = $this->page->getRevision();
58  if ( $from === null ) {
59  throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
60  }
61  if ( !$rev ) {
62  throw new ErrorPageError( 'rollbackfailed', 'rollback-missingrevision' );
63  }
64  if ( $from !== $rev->getUserText() ) {
65  throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
66  $this->getTitle()->getPrefixedText(),
67  $from,
68  $rev->getUserText()
69  ] );
70  }
71 
72  $data = null;
73  $errors = $this->page->doRollback(
74  $from,
75  $request->getText( 'summary' ),
76  $request->getVal( 'token' ),
77  $request->getBool( 'bot' ),
78  $data,
79  $this->getUser()
80  );
81 
82  if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
83  throw new ThrottledError;
84  }
85 
86  if ( isset( $errors[0][0] ) &&
87  ( $errors[0][0] == 'alreadyrolled' || $errors[0][0] == 'cantrollback' )
88  ) {
89  $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
90  $errArray = $errors[0];
91  $errMsg = array_shift( $errArray );
92  $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
93 
94  if ( isset( $data['current'] ) ) {
96  $current = $data['current'];
97 
98  if ( $current->getComment() != '' ) {
99  $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
100  Linker::formatComment( $current->getComment() ) )->parse() );
101  }
102  }
103 
104  return;
105  }
106 
107  # NOTE: Permission errors already handled by Action::checkExecute.
108  if ( $errors == [ [ 'readonlytext' ] ] ) {
109  throw new ReadOnlyError;
110  }
111 
112  # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
113  # Right now, we only show the first error
114  foreach ( $errors as $error ) {
115  throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
116  }
117 
119  $current = $data['current'];
120  $target = $data['target'];
121  $newId = $data['newid'];
122  $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
123  $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
124 
125  $old = Linker::revUserTools( $current );
126  $new = Linker::revUserTools( $target );
127  $this->getOutput()->addHTML(
128  $this->msg( 'rollback-success' )
129  ->rawParams( $old, $new )
130  ->params( $current->getUserText( Revision::FOR_THIS_USER, $user ) )
131  ->params( $target->getUserText( Revision::FOR_THIS_USER, $user ) )
132  ->parseAsBlock()
133  );
134 
135  if ( $user->getBoolOption( 'watchrollback' ) ) {
136  $user->addWatch( $this->page->getTitle(), User::IGNORE_USER_RIGHTS );
137  }
138 
139  $this->getOutput()->returnToMain( false, $this->getTitle() );
140 
141  if ( !$request->getBool( 'hidediff', false ) &&
142  !$this->getUser()->getBoolOption( 'norollbackdiff' )
143  ) {
144  $contentHandler = $current->getContentHandler();
145  $de = $contentHandler->createDifferenceEngine(
146  $this->getContext(),
147  $current->getId(),
148  $newId,
149  false,
150  true
151  );
152  $de->showDiff( '', '' );
153  }
154  return;
155  }
156 
157  protected function getDescription() {
158  return '';
159  }
160 
161  public function doesWrites() {
162  return true;
163  }
164 }
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
$user
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 account $user
Definition: hooks.txt:244
FormlessAction
An action which just does something, without showing a form first.
Definition: FormlessAction.php:28
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:197
RollbackAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: RollbackAction.php:157
page
target page
Definition: All_system_messages.txt:1267
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:99
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:178
Action\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:256
wfTransactionalTimeLimit
wfTransactionalTimeLimit()
Set PHP's time limit to the larger of php.ini or $wgTransactionalTimeLimit.
Definition: GlobalFunctions.php:3114
Linker\revUserTools
static revUserTools( $rev, $isPublic=false)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1060
ThrottledError
Show an error when the user hits a rate limit.
Definition: ThrottledError.php:27
RollbackAction\onView
onView()
Temporarily unused message keys due to T88044/T136375:
Definition: RollbackAction.php:50
$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:2581
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:217
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:246
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:1099
RollbackAction
User interface for the rollback action.
Definition: RollbackAction.php:28
$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:1750
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
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:1965
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:207
RollbackAction\doesWrites
doesWrites()
Indicates whether this action may perform database writes.
Definition: RollbackAction.php:161
User\IGNORE_USER_RIGHTS
const IGNORE_USER_RIGHTS
Definition: User.php:88
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
RollbackAction\getName
getName()
Return the name of the action this object responds to.
Definition: RollbackAction.php:30