Go to the documentation of this file.
31 $titleObj = $pageObj->getTitle();
36 $tags = $params[
'tags'];
39 if ( !is_null( $tags ) ) {
41 if ( !$ableToTag->isOK() ) {
46 $expiry = (array)$params[
'expiry'];
47 if ( count( $expiry ) != count( $params[
'protections'] ) ) {
48 if ( count( $expiry ) == 1 ) {
49 $expiry = array_fill( 0, count( $params[
'protections'] ), $expiry[0] );
52 'apierror-toofewexpiries',
54 count( $params[
'protections'] )
59 $restrictionTypes = $titleObj->getRestrictionTypes();
63 $resultProtections = [];
64 foreach ( $params[
'protections'] as $i => $prot ) {
65 $p = explode(
'=', $prot );
66 $protections[$p[0]] = ( $p[1] ==
'all' ?
'' : $p[1] );
68 if ( $titleObj->exists() && $p[0] ==
'create' ) {
71 if ( !$titleObj->exists() && $p[0] !=
'create' ) {
72 $this->
dieWithError(
'apierror-missingtitle-createonly' );
75 if ( !in_array( $p[0], $restrictionTypes ) && $p[0] !=
'create' ) {
78 if ( !in_array( $p[1], $this->
getConfig()->
get(
'RestrictionLevels' ) ) && $p[1] !=
'all' ) {
83 $expiryarray[$p[0]] =
'infinity';
85 $exp = strtotime( $expiry[$i] );
86 if ( $exp < 0 || !$exp ) {
94 $expiryarray[$p[0]] = $exp;
96 $resultProtections[] = [
97 $p[0] => $protections[$p[0]],
102 $cascade = $params[
'cascade'];
104 $watch = $params[
'watch'] ?
'watch' : $params[
'watchlist'];
105 $this->
setWatch( $watch, $titleObj,
'watchdefault' );
107 $status = $pageObj->doUpdateRestrictions(
120 'title' => $titleObj->getPrefixedText(),
121 'reason' => $params[
'reason']
124 $res[
'cascade'] =
true;
126 $res[
'protections'] = $resultProtections;
185 'action=protect&title=Main%20Page&token=123ABC&' .
186 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
187 =>
'apihelp-protect-example-protect',
188 'action=protect&title=Main%20Page&token=123ABC&' .
189 'protections=edit=all|move=all&reason=Lifting%20restrictions'
190 =>
'apihelp-protect-example-unprotect',
191 'action=protect&title=Main%20Page&token=123ABC&' .
192 'protections=&reason=Lifting%20restrictions'
193 =>
'apihelp-protect-example-unprotect2',
198 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protect';
const PARAM_REQUIRED
(boolean) Is the parameter required?
mustBePosted()
Indicates whether this module must be called with a POST request.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
checkTitleUserPermissions(LinkTarget $linkTarget, $actions, $options=[])
Helper function for permission-denied errors.
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getExamplesMessages()
Returns usage examples for this module.
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
wfIsInfinity( $str)
Determine input string is represents as infinity.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
getHelpUrls()
Return links to more detailed help pages about the module.
isWriteMode()
Indicates whether this module requires write mode.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
needsToken()
Returns the token type this module requires in order to execute.