31 parent::__construct( $mainModule, $moduleName, $modulePrefix );
33 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
34 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
41 $titleObj = $pageObj->getTitle();
46 $tags = $params[
'tags'];
49 if ( $tags !==
null ) {
51 if ( !$ableToTag->isOK() ) {
56 $expiry = (array)$params[
'expiry'];
57 if ( count( $expiry ) != count( $params[
'protections'] ) ) {
58 if ( count( $expiry ) == 1 ) {
59 $expiry = array_fill( 0, count( $params[
'protections'] ), $expiry[0] );
62 'apierror-toofewexpiries',
64 count( $params[
'protections'] )
69 $restrictionTypes = $titleObj->getRestrictionTypes();
71 $titleObj->getNamespace(),
77 $resultProtections = [];
78 foreach ( $params[
'protections'] as $i => $prot ) {
79 $p = explode(
'=', $prot );
80 $protections[$p[0]] = ( $p[1] ==
'all' ?
'' : $p[1] );
82 if ( $titleObj->exists() && $p[0] ==
'create' ) {
85 if ( !$titleObj->exists() && $p[0] !=
'create' ) {
86 $this->
dieWithError(
'apierror-missingtitle-createonly' );
89 if ( !in_array( $p[0], $restrictionTypes ) && $p[0] !=
'create' ) {
92 if ( !in_array( $p[1], $levels ) && $p[1] !=
'all' ) {
97 $expiryarray[$p[0]] =
'infinity';
99 $exp = strtotime( $expiry[$i] );
100 if ( $exp < 0 || !$exp ) {
108 $expiryarray[$p[0]] = $exp;
110 $resultProtections[] = [
111 $p[0] => $protections[$p[0]],
112 'expiry' => ApiResult::formatExpiry( $expiryarray[$p[0]],
'infinite' ),
116 $cascade = $params[
'cascade'];
118 $watch = $params[
'watch'] ?
'watch' : $params[
'watchlist'];
120 $this->
setWatch( $watch, $titleObj, $user,
'watchdefault', $watchlistExpiry );
122 $status = $pageObj->doUpdateRestrictions(
131 if ( !$status->isOK() ) {
135 'title' => $titleObj->getPrefixedText(),
136 'reason' => $params[
'reason']
139 $res[
'cascade'] =
true;
141 $res[
'protections'] = $resultProtections;
143 ApiResult::setIndexedTagName(
$res[
'protections'],
'protection' );
191 'action=protect&title=Main%20Page&token=123ABC&' .
192 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
193 =>
'apihelp-protect-example-protect',
194 'action=protect&title=Main%20Page&token=123ABC&' .
195 'protections=edit=all|move=all&reason=Lifting%20restrictions'
196 =>
'apihelp-protect-example-unprotect',
197 'action=protect&title=Main%20Page&token=123ABC&' .
198 'protections=&reason=Lifting%20restrictions'
199 =>
'apihelp-protect-example-unprotect2',
204 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protect';
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.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfIsInfinity( $str)
Determine input string is represents as infinity.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
const PARAM_ALLOW_DUPLICATES
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
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.
checkTitleUserPermissions(LinkTarget $linkTarget, $actions, array $options=[])
Helper function for permission-denied errors.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
This is the main API class, used for both external and internal processing.
isWriteMode()
Indicates whether this module requires write mode.
getExamplesMessages()
Returns usage examples for this module.
needsToken()
Returns the token type this module requires in order to execute.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
Stable to call.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
getUser()
Stable to override.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...