22use Wikimedia\ParamValidator\ParamValidator;
39 parent::__construct( $mainModule, $moduleName );
42 $this->watchlistMaxDuration =
44 $this->watchlistManager = $watchlistManager;
45 $this->watchedItemStore = $watchedItemStore;
46 $this->userOptionsLookup = $userOptionsLookup;
52 private $mTitleObj =
null;
57 private $mUser =
null;
65 $titleObj = $this->getRbTitle( $params );
69 if ( $params[
'tags'] ) {
70 $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
71 if ( !$tagStatus->isOK() ) {
79 $trxProfiler = Profiler::instance()->getTransactionProfiler();
80 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
81 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname ) {
82 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
85 $rollbackResult = $this->rollbackPageFactory
86 ->newRollbackPage( $titleObj, $this->
getAuthority(), $this->getRbUser( $params ) )
87 ->setSummary( $params[
'summary'] )
88 ->markAsBot( $params[
'markbot'] )
89 ->setChangeTags( $params[
'tags'] )
90 ->rollbackIfAllowed();
92 if ( !$rollbackResult->isGood() ) {
96 $watch = $params[
'watchlist'] ??
'preferences';
97 $watchlistExpiry = $this->
getExpiryFromParams( $params, $titleObj, $user,
'watchrollback-expiry' );
100 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
102 $details = $rollbackResult->getValue();
103 $currentRevisionRecord = $details[
'current-revision-record'];
104 $targetRevisionRecord = $details[
'target-revision-record'];
107 'title' => $titleObj->getPrefixedText(),
108 'pageid' => $currentRevisionRecord->getPageId(),
109 'summary' => $details[
'summary'],
110 'revid' => (int)$details[
'newid'],
112 'old_revid' => $currentRevisionRecord->getID(),
114 'last_revid' => $targetRevisionRecord->getID()
135 ParamValidator::PARAM_TYPE =>
'integer'
138 ParamValidator::PARAM_TYPE =>
'tags',
139 ParamValidator::PARAM_ISMULTI =>
true,
142 ParamValidator::PARAM_TYPE =>
'user',
143 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
144 UserDef::PARAM_RETURN_OBJECT =>
true,
145 ParamValidator::PARAM_REQUIRED => true
168 private function getRbUser( array $params ):
UserIdentity {
169 if ( $this->mUser !== null ) {
173 $this->mUser = $params[
'user'];
183 private function getRbTitle( array $params ) {
184 if ( $this->mTitleObj !==
null ) {
185 return $this->mTitleObj;
188 $this->requireOnlyOneParameter(
$params,
'title',
'pageid' );
190 if ( isset(
$params[
'title'] ) ) {
191 $this->mTitleObj = Title::newFromText(
$params[
'title'] );
192 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
195 } elseif ( isset(
$params[
'pageid'] ) ) {
196 $this->mTitleObj = Title::newFromID(
$params[
'pageid'] );
197 if ( !$this->mTitleObj ) {
198 $this->dieWithError( [
'apierror-nosuchpageid',
$params[
'pageid'] ] );
202 if ( !$this->mTitleObj->exists() ) {
203 $this->dieWithError(
'apierror-missingtitle' );
206 return $this->mTitleObj;
211 $title = Title::newMainPage()->getPrefixedText();
212 $mp = rawurlencode( $title );
215 "action=rollback&title={$mp}&user=Example&token=123ABC" =>
216 'apihelp-rollback-example-simple',
217 "action=rollback&title={$mp}&user=192.0.2.5&" .
218 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
219 'apihelp-rollback-example-summary',
225 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rollback';
230class_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.