41 private $contentHandlerFactory;
44 private $rollbackPageFactory;
47 private $userOptionsLookup;
50 private $watchlistManager;
53 private $commentFormatter;
73 parent::__construct( $page, $context );
74 $this->contentHandlerFactory = $contentHandlerFactory;
75 $this->rollbackPageFactory = $rollbackPageFactory;
76 $this->userOptionsLookup = $userOptionsLookup;
77 $this->watchlistManager = $watchlistManager;
78 $this->commentFormatter = $commentFormatter;
114 $from = $this->
getRequest()->getVal(
'from' );
115 if ( $from ===
null ) {
116 throw new BadRequestError(
'rollbackfailed',
'rollback-missingparam' );
118 foreach ( [
'from',
'bot',
'hidediff',
'summary',
'token' ] as $param ) {
120 if ( $val !==
null ) {
136 if ( !$this->userOptionsLookup->getOption( $this->getUser(),
'showrollbackconfirmation' ) ||
137 $this->getRequest()->wasPosted()
141 $this->showRollbackConfirmationForm();
146 $this->enableTransactionalTimelimit();
147 $this->
getOutput()->addModuleStyles(
'mediawiki.interface.helpers.styles' );
151 $from = $request->getVal(
'from' );
153 if ( $from ===
null ) {
154 throw new ErrorPageError(
'rollbackfailed',
'rollback-missingparam' );
157 throw new ErrorPageError(
'rollbackfailed',
'rollback-missingrevision' );
160 $revUser = $rev->getUser();
161 $userText = $revUser ? $revUser->getName() :
'';
162 if ( $from !== $userText ) {
164 $this->
getTitle()->getPrefixedText(),
170 if ( !$user->matchEditToken( $request->getVal(
'token' ),
'rollback' ) ) {
171 throw new ErrorPageError(
'sessionfailure-title',
'sessionfailure' );
178 if ( $this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
179 $revUser = $rev->getUser( RevisionRecord::RAW );
181 $userFactory = MediaWikiServices::getInstance()->getUserFactory();
182 $revUser = $userFactory->newFromName( $this->context->msg(
'rev-deleted-user' )->plain() );
186 $rollbackResult = $this->rollbackPageFactory
189 ->setSummary( $request->getText(
'summary' ) )
190 ->markAsBot( $request->getBool(
'bot' ) )
191 ->rollbackIfAllowed();
192 $data = $rollbackResult->getValue();
194 if ( $rollbackResult->hasMessage(
'actionthrottledtext' ) ) {
198 if ( $rollbackResult->hasMessage(
'alreadyrolled' ) || $rollbackResult->hasMessage(
'cantrollback' ) ) {
199 $this->
getOutput()->setPageTitle( $this->
msg(
'rollbackfailed' ) );
200 $errArray = $rollbackResult->getErrors()[0];
201 $this->
getOutput()->addWikiMsgArray( $errArray[
'message'], $errArray[
'params'] );
203 if ( isset( $data[
'current-revision-record'] ) ) {
205 $current = $data[
'current-revision-record'];
207 if ( $current->getComment() !=
null ) {
211 $this->commentFormatter
212 ->format( $current->getComment()->text )
221 # NOTE: Permission errors already handled by Action::checkExecute.
222 if ( $rollbackResult->hasMessage(
'readonlytext' ) ) {
226 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
227 # Right now, we only show the first error
228 foreach ( $rollbackResult->getErrors() as $error ) {
229 throw new ErrorPageError(
'rollbackfailed', $error[
'message'], $error[
'params'] );
233 $current = $data[
'current-revision-record'];
234 $target = $data[
'target-revision-record'];
235 $newId = $data[
'newid'];
236 $this->
getOutput()->setPageTitle( $this->
msg(
'actioncomplete' ) );
237 $this->
getOutput()->setRobotPolicy(
'noindex,nofollow' );
242 $currentUser = $current->getUser( RevisionRecord::FOR_THIS_USER, $user );
243 $targetUser = $target->getUser( RevisionRecord::FOR_THIS_USER, $user );
245 $this->
msg(
'rollback-success' )
246 ->rawParams( $old, $new )
247 ->params( $currentUser ? $currentUser->getName() :
'' )
248 ->params( $targetUser ? $targetUser->getName() :
'' )
252 if ( $this->userOptionsLookup->getBoolOption( $user,
'watchrollback' ) ) {
253 $this->watchlistManager->addWatchIgnoringRights( $user, $this->
getTitle() );
258 if ( !$request->getBool(
'hidediff',
false ) &&
259 !$this->userOptionsLookup->getBoolOption( $this->getUser(),
'norollbackdiff' )
261 $contentModel = $current->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
263 $contentHandler = $this->contentHandlerFactory->getContentHandler( $contentModel );
264 $de = $contentHandler->createDifferenceEngine(
271 $de->showDiff(
'',
'' );
279 private function enableTransactionalTimelimit() {
282 if ( !$this->getRequest()->wasPosted() ) {
288 $trxLimits = $this->context->getConfig()->get( MainConfigNames::TrxProfilerLimits );
289 $trxProfiler = Profiler::instance()->getTransactionProfiler();
290 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
291 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname
293 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
298 private function showRollbackConfirmationForm() {
300 if ( $form->show() ) {
310 'default' => $this->
msg(
'confirm-rollback-bottom' )->parse()
wfTransactionalTimeLimit()
Raise the request time limit to $wgTransactionalTimeLimit.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getWikiPage()
Get a WikiPage object.
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
getOutput()
Get the OutputPage being used for this instance.
setHeaders()
Set output headers for noindexing etc.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getRequest()
Get the WebRequest being used for this instance.
An error page that emits an HTTP 400 Bad Request status code.
An error page which can definitely be safely rendered using the OutputPage.
static revUserTools(RevisionRecord $revRecord, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
A class containing constants representing the names of configuration variables.
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
User interface for the rollback action.
getFormFields()
Get an HTMLForm descriptor array.
getDescription()
Returns the description that goes below the <h1> element.
usesOOUI()
Whether the form should use OOUI.
onSubmit( $data)
Process the form on POST submission.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
getRestriction()
Get the permission required to perform this action.
__construct(Page $page, ?IContextSource $context, IContentHandlerFactory $contentHandlerFactory, RollbackPageFactory $rollbackPageFactory, UserOptionsLookup $userOptionsLookup, WatchlistManager $watchlistManager, CommentFormatter $commentFormatter)
onSuccess()
Do something exciting on successful processing of the form.
getName()
Return the name of the action this object responds to.
Show an error when the user hits a rate limit.
Interface for objects which can provide a MediaWiki context on request.
Service for page rollback actions.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)