41 parent::__construct( $mainModule, $moduleName );
42 $this->rollbackPageFactory = $rollbackPageFactory;
46 $this->watchlistMaxDuration =
48 $this->watchlistManager = $watchlistManager;
49 $this->watchedItemStore = $watchedItemStore;
50 $this->userOptionsLookup = $userOptionsLookup;
56 private $mTitleObj =
null;
61 private $mUser =
null;
69 $titleObj = $this->getRbTitle( $params );
73 if ( $params[
'tags'] ) {
74 $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
75 if ( !$tagStatus->isOK() ) {
83 $trxProfiler = Profiler::instance()->getTransactionProfiler();
84 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
85 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname ) {
86 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
89 $rollbackResult = $this->rollbackPageFactory
90 ->newRollbackPage( $titleObj, $this->
getAuthority(), $this->getRbUser( $params ) )
91 ->setSummary( $params[
'summary'] )
92 ->markAsBot( $params[
'markbot'] )
93 ->setChangeTags( $params[
'tags'] )
94 ->rollbackIfAllowed();
96 if ( !$rollbackResult->isGood() ) {
100 $watch = $params[
'watchlist'] ??
'preferences';
101 $watchlistExpiry = $this->
getExpiryFromParams( $params, $titleObj, $user,
'watchrollback-expiry' );
104 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
106 $details = $rollbackResult->getValue();
107 $currentRevisionRecord = $details[
'current-revision-record'];
108 $targetRevisionRecord = $details[
'target-revision-record'];
111 'title' => $titleObj->getPrefixedText(),
112 'pageid' => $currentRevisionRecord->getPageId(),
113 'summary' => $details[
'summary'],
114 'revid' => (int)$details[
'newid'],
116 'old_revid' => $currentRevisionRecord->getID(),
118 'last_revid' => $targetRevisionRecord->getID()
139 ParamValidator::PARAM_TYPE =>
'integer'
142 ParamValidator::PARAM_TYPE =>
'tags',
143 ParamValidator::PARAM_ISMULTI =>
true,
146 ParamValidator::PARAM_TYPE =>
'user',
147 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
148 UserDef::PARAM_RETURN_OBJECT =>
true,
149 ParamValidator::PARAM_REQUIRED => true
172 private function getRbUser( array $params ):
UserIdentity {
173 if ( $this->mUser !== null ) {
177 $this->mUser = $params[
'user'];
187 private function getRbTitle( array $params ) {
188 if ( $this->mTitleObj !==
null ) {
189 return $this->mTitleObj;
192 $this->requireOnlyOneParameter( $params,
'title',
'pageid' );
194 if ( isset( $params[
'title'] ) ) {
195 $this->mTitleObj = Title::newFromText( $params[
'title'] );
196 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
197 $this->dieWithError( [
'apierror-invalidtitle',
wfEscapeWikiText( $params[
'title'] ) ] );
199 } elseif ( isset( $params[
'pageid'] ) ) {
200 $this->mTitleObj = Title::newFromID( $params[
'pageid'] );
201 if ( !$this->mTitleObj ) {
202 $this->dieWithError( [
'apierror-nosuchpageid', $params[
'pageid'] ] );
206 if ( !$this->mTitleObj->exists() ) {
207 $this->dieWithError(
'apierror-missingtitle' );
210 return $this->mTitleObj;
215 $title = Title::newMainPage()->getPrefixedText();
216 $mp = rawurlencode( $title );
219 "action=rollback&title={$mp}&user=Example&token=123ABC" =>
220 'apihelp-rollback-example-simple',
221 "action=rollback&title={$mp}&user=192.0.2.5&" .
222 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
223 'apihelp-rollback-example-summary',
229 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rollback';
234class_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()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rollback actions.