26use InvalidArgumentException;
52 parent::__construct( $mainModule, $moduleName );
53 $this->restrictionStore = $restrictionStore;
57 $this->watchlistMaxDuration =
59 $this->watchlistManager = $watchlistManager;
60 $this->userOptionsLookup = $userOptionsLookup;
67 $titleObj = $pageObj->getTitle();
76 if ( $tags !==
null ) {
78 if ( !$ableToTag->isOK() ) {
83 $expiry = (array)
$params[
'expiry'];
84 if ( count( $expiry ) != count(
$params[
'protections'] ) ) {
85 if ( count( $expiry ) == 1 ) {
86 $expiry = array_fill( 0, count(
$params[
'protections'] ), $expiry[0] );
89 'apierror-toofewexpiries',
96 $restrictionTypes = $this->restrictionStore->listApplicableRestrictionTypes( $titleObj );
98 $titleObj->getNamespace(),
104 $resultProtections = [];
105 foreach (
$params[
'protections'] as $i => $prot ) {
106 $p = explode(
'=', $prot );
107 $protections[$p[0]] = ( $p[1] ==
'all' ?
'' : $p[1] );
109 if ( $titleObj->exists() && $p[0] ==
'create' ) {
112 if ( !$titleObj->exists() && $p[0] !=
'create' ) {
113 $this->
dieWithError(
'apierror-missingtitle-createonly' );
116 if ( !in_array( $p[0], $restrictionTypes ) && $p[0] !=
'create' ) {
119 if ( !in_array( $p[1], $levels ) && $p[1] !=
'all' ) {
124 $expiries[$p[0]] = ExpiryDef::normalizeExpiry( $expiry[$i], TS_MW );
125 }
catch ( InvalidArgumentException $e ) {
128 if ( $expiries[$p[0]] < MWTimestamp::now( TS_MW ) ) {
132 $resultProtections[] = [
133 $p[0] => $protections[$p[0]],
142 $this->
setWatch( $watch, $titleObj, $user,
'watchdefault', $watchlistExpiry );
144 $status = $pageObj->doUpdateRestrictions(
153 if ( !$status->isOK() ) {
157 'title' => $titleObj->getPrefixedText(),
161 $res[
'cascade'] =
true;
163 $res[
'protections'] = $resultProtections;
180 ParamValidator::PARAM_TYPE =>
'string',
183 ParamValidator::PARAM_TYPE =>
'integer',
186 ParamValidator::PARAM_ISMULTI =>
true,
187 ParamValidator::PARAM_REQUIRED =>
true,
190 ParamValidator::PARAM_ISMULTI =>
true,
191 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
192 ParamValidator::PARAM_DEFAULT =>
'infinite',
196 ParamValidator::PARAM_TYPE =>
'tags',
197 ParamValidator::PARAM_ISMULTI =>
true,
201 ParamValidator::PARAM_DEFAULT =>
false,
202 ParamValidator::PARAM_DEPRECATED =>
true,
212 $title = Title::newMainPage()->getPrefixedText();
213 $mp = rawurlencode( $title );
216 "action=protect&title={$mp}&token=123ABC&" .
217 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
218 =>
'apihelp-protect-example-protect',
219 "action=protect&title={$mp}&token=123ABC&" .
220 'protections=edit=all|move=all&reason=Lifting%20restrictions'
221 =>
'apihelp-protect-example-unprotect',
222 "action=protect&title={$mp}&token=123ABC&" .
223 'protections=&reason=Lifting%20restrictions'
224 =>
'apihelp-protect-example-unprotect2',
229 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protect';
234class_alias( ApiProtect::class,
'ApiProtect' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
array $params
The job parameters.
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...