39 private $rollbackPageFactory;
48 parent::__construct( $mainModule, $moduleName );
49 $this->rollbackPageFactory = $rollbackPageFactory;
52 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
53 $this->watchlistMaxDuration =
54 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
55 $this->watchlistManager = $watchlistManager;
56 $this->userOptionsLookup = $userOptionsLookup;
62 private $mTitleObj =
null;
67 private $mUser =
null;
75 $titleObj = $this->getRbTitle( $params );
79 if ( $params[
'tags'] ) {
81 if ( !$tagStatus->isOK() ) {
88 $trxLimits = $this->
getConfig()->get( MainConfigNames::TrxProfilerLimits );
89 $trxProfiler = Profiler::instance()->getTransactionProfiler();
90 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
91 DeferredUpdates::addCallableUpdate(
static function () use ( $trxProfiler, $trxLimits, $fname ) {
92 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
95 $rollbackResult = $this->rollbackPageFactory
96 ->newRollbackPage( $titleObj, $this->
getAuthority(), $this->getRbUser( $params ) )
97 ->setSummary( $params[
'summary'] )
98 ->markAsBot( $params[
'markbot'] )
99 ->setChangeTags( $params[
'tags'] )
100 ->rollbackIfAllowed();
102 if ( !$rollbackResult->isGood() ) {
106 $watch = $params[
'watchlist'] ??
'preferences';
110 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
112 $details = $rollbackResult->getValue();
113 $currentRevisionRecord = $details[
'current-revision-record'];
114 $targetRevisionRecord = $details[
'target-revision-record'];
117 'title' => $titleObj->getPrefixedText(),
118 'pageid' => $currentRevisionRecord->getPageId(),
119 'summary' => $details[
'summary'],
120 'revid' => (int)$details[
'newid'],
122 'old_revid' => $currentRevisionRecord->getID(),
124 'last_revid' => $targetRevisionRecord->getID()
142 ParamValidator::PARAM_TYPE =>
'integer'
145 ParamValidator::PARAM_TYPE =>
'tags',
146 ParamValidator::PARAM_ISMULTI =>
true,
149 ParamValidator::PARAM_TYPE =>
'user',
150 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
151 UserDef::PARAM_RETURN_OBJECT =>
true,
152 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'] ) ) {
203 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
204 $this->dieWithError( [
'apierror-invalidtitle',
wfEscapeWikiText( $params[
'title'] ) ] );
206 } elseif ( isset( $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';
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.
Represents a title within MediaWiki.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rollback actions.