34 parent::__construct( $mainModule, $moduleName, $modulePrefix );
36 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
37 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
57 $pageObj = WikiPage::factory( $titleObj );
58 $summary = $params[
'summary'];
63 if ( $params[
'tags'] ) {
65 if ( !$tagStatus->isOK() ) {
72 $trxLimits = $this->
getConfig()->get(
'TrxProfilerLimits' );
73 $trxProfiler = Profiler::instance()->getTransactionProfiler();
74 $trxProfiler->redefineExpectations( $trxLimits[
'POST'], $fname );
75 DeferredUpdates::addCallableUpdate(
function () use ( $trxProfiler, $trxLimits, $fname ) {
76 $trxProfiler->redefineExpectations( $trxLimits[
'PostSend-POST'], $fname );
79 $retval = $pageObj->doRollback(
93 $watch = $params[
'watchlist'] ??
'preferences';
97 $this->
setWatch( $watch, $titleObj, $user,
'watchrollback', $watchlistExpiry );
99 $currentRevisionRecord = $details[
'current-revision-record'];
100 $targetRevisionRecord = $details[
'target-revision-record'];
103 'title' => $titleObj->getPrefixedText(),
104 'pageid' => $currentRevisionRecord->getPageId(),
105 'summary' => $details[
'summary'],
106 'revid' => (int)$details[
'newid'],
108 'old_revid' => $currentRevisionRecord->getID(),
110 'last_revid' => $targetRevisionRecord->getID()
136 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
137 UserDef::PARAM_RETURN_OBJECT =>
true,
166 if ( $this->mUser !== null ) {
170 $this->mUser = $params[
'user'];
181 if ( $this->mTitleObj !==
null ) {
182 return $this->mTitleObj;
185 $this->requireOnlyOneParameter( $params,
'title',
'pageid' );
187 if ( isset( $params[
'title'] ) ) {
188 $this->mTitleObj = Title::newFromText( $params[
'title'] );
189 if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
190 $this->dieWithError( [
'apierror-invalidtitle',
wfEscapeWikiText( $params[
'title'] ) ] );
192 } elseif ( isset( $params[
'pageid'] ) ) {
193 $this->mTitleObj = Title::newFromID( $params[
'pageid'] );
194 if ( !$this->mTitleObj ) {
195 $this->dieWithError( [
'apierror-nosuchpageid', $params[
'pageid'] ] );
199 if ( !$this->mTitleObj->exists() ) {
200 $this->dieWithError(
'apierror-missingtitle' );
203 return $this->mTitleObj;
208 'action=rollback&title=Main%20Page&user=Example&token=123ABC' =>
209 'apihelp-rollback-example-simple',
210 'action=rollback&title=Main%20Page&user=192.0.2.5&' .
211 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
212 'apihelp-rollback-example-summary',
217 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,...
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 ...
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
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.
getRbTitle(array $params)
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.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
Stable to call.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
needsToken()
Returns the token type this module requires in order to execute.
getUser()
Stable to override.
Represents a title within MediaWiki.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...