56 parent::__construct( $mainModule, $moduleName );
57 $this->restrictionStore = $restrictionStore;
61 $this->watchlistMaxDuration =
63 $this->watchlistManager = $watchlistManager;
64 $this->userOptionsLookup = $userOptionsLookup;
71 $titleObj = $pageObj->getTitle();
80 if ( $tags !==
null ) {
82 if ( !$ableToTag->isOK() ) {
87 $expiry = (array)
$params[
'expiry'];
88 if ( count( $expiry ) != count(
$params[
'protections'] ) ) {
89 if ( count( $expiry ) == 1 ) {
90 $expiry = array_fill( 0, count(
$params[
'protections'] ), $expiry[0] );
93 'apierror-toofewexpiries',
100 $restrictionTypes = $this->restrictionStore->listApplicableRestrictionTypes( $titleObj );
102 $titleObj->getNamespace(),
108 $resultProtections = [];
109 foreach (
$params[
'protections'] as $i => $prot ) {
110 $p = explode(
'=', $prot );
111 $protections[$p[0]] = ( $p[1] ==
'all' ?
'' : $p[1] );
113 if ( $titleObj->exists() && $p[0] ==
'create' ) {
116 if ( !$titleObj->exists() && $p[0] !=
'create' ) {
117 $this->
dieWithError(
'apierror-missingtitle-createonly' );
120 if ( !in_array( $p[0], $restrictionTypes ) && $p[0] !=
'create' ) {
123 if ( !in_array( $p[1], $levels ) && $p[1] !=
'all' ) {
128 $expiryarray[$p[0]] =
'infinity';
130 $exp = strtotime( $expiry[$i] );
131 if ( $exp < 0 || !$exp ) {
139 $expiryarray[$p[0]] = $exp;
141 $resultProtections[] = [
142 $p[0] => $protections[$p[0]],
151 $this->
setWatch( $watch, $titleObj, $user,
'watchdefault', $watchlistExpiry );
153 $status = $pageObj->doUpdateRestrictions(
162 if ( !$status->isOK() ) {
166 'title' => $titleObj->getPrefixedText(),
170 $res[
'cascade'] =
true;
172 $res[
'protections'] = $resultProtections;
189 ParamValidator::PARAM_TYPE =>
'string',
192 ParamValidator::PARAM_TYPE =>
'integer',
195 ParamValidator::PARAM_ISMULTI =>
true,
196 ParamValidator::PARAM_REQUIRED =>
true,
199 ParamValidator::PARAM_ISMULTI =>
true,
200 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
201 ParamValidator::PARAM_DEFAULT =>
'infinite',
205 ParamValidator::PARAM_TYPE =>
'tags',
206 ParamValidator::PARAM_ISMULTI =>
true,
210 ParamValidator::PARAM_DEFAULT =>
false,
211 ParamValidator::PARAM_DEPRECATED =>
true,
221 $title = Title::newMainPage()->getPrefixedText();
222 $mp = rawurlencode( $title );
225 "action=protect&title={$mp}&token=123ABC&" .
226 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
227 =>
'apihelp-protect-example-protect',
228 "action=protect&title={$mp}&token=123ABC&" .
229 'protections=edit=all|move=all&reason=Lifting%20restrictions'
230 =>
'apihelp-protect-example-unprotect',
231 "action=protect&title={$mp}&token=123ABC&" .
232 'protections=&reason=Lifting%20restrictions'
233 =>
'apihelp-protect-example-unprotect2',
238 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protect';
243class_alias( ApiProtect::class,
'ApiProtect' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfIsInfinity( $str)
Determine input string is represents as infinity.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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...