40 private $rollbackPageFactory;
49 parent::__construct( $mainModule, $moduleName );
50 $this->rollbackPageFactory = $rollbackPageFactory;
53 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
54 $this->watchlistMaxDuration =
55 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
56 $this->watchlistManager = $watchlistManager;
57 $this->userOptionsLookup = $userOptionsLookup;
63 private $mTitleObj =
null;
68 private $mUser =
null;
76 $titleObj = $this->getRbTitle( $params );
80 if ( $params[
'tags'] ) {
82 if ( !$tagStatus->isOK() ) {
89 $trxLimits = $this->
getConfig()->get( MainConfigNames::TrxProfilerLimits );
90 $trxProfiler = Profiler::instance()->getTransactionProfiler();
91 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
92 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname ) {
93 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
96 $rollbackResult = $this->rollbackPageFactory
97 ->newRollbackPage( $titleObj, $this->
getAuthority(), $this->getRbUser( $params ) )
98 ->setSummary( $params[
'summary'] )
99 ->markAsBot( $params[
'markbot'] )
100 ->setChangeTags( $params[
'tags'] )
101 ->rollbackIfAllowed();
103 if ( !$rollbackResult->isGood() ) {
107 $watch = $params[
'watchlist'] ??
'preferences';
111 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
113 $details = $rollbackResult->getValue();
114 $currentRevisionRecord = $details[
'current-revision-record'];
115 $targetRevisionRecord = $details[
'target-revision-record'];
118 'title' => $titleObj->getPrefixedText(),
119 'pageid' => $currentRevisionRecord->getPageId(),
120 'summary' => $details[
'summary'],
121 'revid' => (int)$details[
'newid'],
123 'old_revid' => $currentRevisionRecord->getID(),
125 'last_revid' => $targetRevisionRecord->getID()
143 ParamValidator::PARAM_TYPE =>
'integer'
146 ParamValidator::PARAM_TYPE =>
'tags',
147 ParamValidator::PARAM_ISMULTI =>
true,
150 ParamValidator::PARAM_TYPE =>
'user',
151 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
152 UserDef::PARAM_RETURN_OBJECT =>
true,
153 ParamValidator::PARAM_REQUIRED =>
true
180 private function getRbUser( array $params ):
UserIdentity {
181 if ( $this->mUser !== null ) {
185 $this->mUser = $params[
'user'];
195 private function getRbTitle( array $params ) {
196 if ( $this->mTitleObj !==
null ) {
197 return $this->mTitleObj;
200 $this->requireOnlyOneParameter( $params,
'title',
'pageid' );
202 if ( isset( $params[
'title'] ) ) {
203 $this->mTitleObj = Title::newFromText( $params[
'title'] );
204 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
205 $this->dieWithError( [
'apierror-invalidtitle',
wfEscapeWikiText( $params[
'title'] ) ] );
207 } elseif ( isset( $params[
'pageid'] ) ) {
208 $this->mTitleObj = Title::newFromID( $params[
'pageid'] );
209 if ( !$this->mTitleObj ) {
210 $this->dieWithError( [
'apierror-nosuchpageid', $params[
'pageid'] ] );
214 if ( !$this->mTitleObj->exists() ) {
215 $this->dieWithError(
'apierror-missingtitle' );
218 return $this->mTitleObj;
222 $title = Title::newMainPage()->getPrefixedText();
223 $mp = rawurlencode(
$title );
226 "action=rollback&title={$mp}&user=Example&token=123ABC" =>
227 'apihelp-rollback-example-simple',
228 "action=rollback&title={$mp}&user=192.0.2.5&" .
229 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
230 'apihelp-rollback-example-summary',
235 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Rollback';
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, Title $title, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
This is the main API class, used for both external and internal processing.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
isWriteMode()
Indicates whether this module requires write mode.
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiMain $mainModule, $moduleName, RollbackPageFactory $rollbackPageFactory, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
mustBePosted()
Indicates whether this module must be called with a POST request.
needsToken()
Returns the token type this module requires in order to execute.
A class containing constants representing the names of configuration variables.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rollback actions.