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(
116 if ( !$status->isOK() ) {
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';
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.
const PARAM_REQUIRED
(boolean) Is the parameter required?
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
checkTitleUserPermissions(LinkTarget $linkTarget, $actions, $options=[])
Helper function for permission-denied errors.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
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.
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.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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.
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.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.