53 parent::__construct( $mainModule, $moduleName );
54 $this->rollbackPageFactory = $rollbackPageFactory;
58 $this->watchlistMaxDuration =
60 $this->watchlistManager = $watchlistManager;
61 $this->userOptionsLookup = $userOptionsLookup;
67 private $mTitleObj =
null;
72 private $mUser =
null;
80 $titleObj = $this->getRbTitle( $params );
84 if ( $params[
'tags'] ) {
85 $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
86 if ( !$tagStatus->isOK() ) {
95 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
96 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname ) {
97 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
100 $rollbackResult = $this->rollbackPageFactory
101 ->newRollbackPage( $titleObj, $this->
getAuthority(), $this->getRbUser( $params ) )
102 ->setSummary( $params[
'summary'] )
103 ->markAsBot( $params[
'markbot'] )
104 ->setChangeTags( $params[
'tags'] )
105 ->rollbackIfAllowed();
107 if ( !$rollbackResult->isGood() ) {
111 $watch = $params[
'watchlist'] ??
'preferences';
115 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
117 $details = $rollbackResult->getValue();
118 $currentRevisionRecord = $details[
'current-revision-record'];
119 $targetRevisionRecord = $details[
'target-revision-record'];
122 'title' => $titleObj->getPrefixedText(),
123 'pageid' => $currentRevisionRecord->getPageId(),
124 'summary' => $details[
'summary'],
125 'revid' => (int)$details[
'newid'],
127 'old_revid' => $currentRevisionRecord->getID(),
129 'last_revid' => $targetRevisionRecord->getID()
147 ParamValidator::PARAM_TYPE =>
'integer'
150 ParamValidator::PARAM_TYPE =>
'tags',
151 ParamValidator::PARAM_ISMULTI =>
true,
154 ParamValidator::PARAM_TYPE =>
'user',
155 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
156 UserDef::PARAM_RETURN_OBJECT =>
true,
157 ParamValidator::PARAM_REQUIRED => true
179 private function getRbUser( array $params ):
UserIdentity {
180 if ( $this->mUser !== null ) {
184 $this->mUser = $params[
'user'];
194 private function getRbTitle( array $params ) {
195 if ( $this->mTitleObj !==
null ) {
196 return $this->mTitleObj;
199 $this->requireOnlyOneParameter( $params,
'title',
'pageid' );
201 if ( isset( $params[
'title'] ) ) {
202 $this->mTitleObj = Title::newFromText( $params[
'title'] );
203 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
204 $this->dieWithError( [
'apierror-invalidtitle',
wfEscapeWikiText( $params[
'title'] ) ] );
206 } elseif ( isset( $params[
'pageid'] ) ) {
207 $this->mTitleObj = Title::newFromID( $params[
'pageid'] );
208 if ( !$this->mTitleObj ) {
209 $this->dieWithError( [
'apierror-nosuchpageid', $params[
'pageid'] ] );
213 if ( !$this->mTitleObj->exists() ) {
214 $this->dieWithError(
'apierror-missingtitle' );
217 return $this->mTitleObj;
221 $title = Title::newMainPage()->getPrefixedText();
222 $mp = rawurlencode( $title );
225 "action=rollback&title={$mp}&user=Example&token=123ABC" =>
226 'apihelp-rollback-example-simple',
227 "action=rollback&title={$mp}&user=192.0.2.5&" .
228 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
229 'apihelp-rollback-example-summary',
234 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rollback';
239class_alias( ApiRollback::class,
'ApiRollback' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const TrxProfilerLimits
Name constant for the TrxProfilerLimits setting, for use with Config::get()
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
Profiler base class that defines the interface and some shared functionality.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rollback actions.