49 parent::__construct( $mainModule, $moduleName );
50 $this->restrictionStore = $restrictionStore;
54 $this->watchlistMaxDuration =
56 $this->watchlistManager = $watchlistManager;
57 $this->userOptionsLookup = $userOptionsLookup;
64 $titleObj = $pageObj->getTitle();
73 if ( $tags !==
null ) {
75 if ( !$ableToTag->isOK() ) {
80 $expiry = (array)
$params[
'expiry'];
81 if ( count( $expiry ) != count(
$params[
'protections'] ) ) {
82 if ( count( $expiry ) == 1 ) {
83 $expiry = array_fill( 0, count(
$params[
'protections'] ), $expiry[0] );
86 'apierror-toofewexpiries',
93 $restrictionTypes = $this->restrictionStore->listApplicableRestrictionTypes( $titleObj );
95 $titleObj->getNamespace(),
101 $resultProtections = [];
102 foreach (
$params[
'protections'] as $i => $prot ) {
103 $p = explode(
'=', $prot );
104 $protections[$p[0]] = ( $p[1] ==
'all' ?
'' : $p[1] );
106 if ( $titleObj->exists() && $p[0] ==
'create' ) {
109 if ( !$titleObj->exists() && $p[0] !=
'create' ) {
110 $this->
dieWithError(
'apierror-missingtitle-createonly' );
113 if ( !in_array( $p[0], $restrictionTypes ) && $p[0] !=
'create' ) {
116 if ( !in_array( $p[1], $levels ) && $p[1] !=
'all' ) {
121 $expiryarray[$p[0]] =
'infinity';
123 $exp = strtotime( $expiry[$i] );
124 if ( $exp < 0 || !$exp ) {
132 $expiryarray[$p[0]] = $exp;
134 $resultProtections[] = [
135 $p[0] => $protections[$p[0]],
144 $this->
setWatch( $watch, $titleObj, $user,
'watchdefault', $watchlistExpiry );
146 $status = $pageObj->doUpdateRestrictions(
155 if ( !$status->isOK() ) {
159 'title' => $titleObj->getPrefixedText(),
163 $res[
'cascade'] =
true;
165 $res[
'protections'] = $resultProtections;
182 ParamValidator::PARAM_TYPE =>
'string',
185 ParamValidator::PARAM_TYPE =>
'integer',
188 ParamValidator::PARAM_ISMULTI =>
true,
189 ParamValidator::PARAM_REQUIRED =>
true,
192 ParamValidator::PARAM_ISMULTI =>
true,
193 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
194 ParamValidator::PARAM_DEFAULT =>
'infinite',
198 ParamValidator::PARAM_TYPE =>
'tags',
199 ParamValidator::PARAM_ISMULTI =>
true,
203 ParamValidator::PARAM_DEFAULT =>
false,
204 ParamValidator::PARAM_DEPRECATED =>
true,
214 $title = Title::newMainPage()->getPrefixedText();
215 $mp = rawurlencode( $title );
218 "action=protect&title={$mp}&token=123ABC&" .
219 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
220 =>
'apihelp-protect-example-protect',
221 "action=protect&title={$mp}&token=123ABC&" .
222 'protections=edit=all|move=all&reason=Lifting%20restrictions'
223 =>
'apihelp-protect-example-unprotect',
224 "action=protect&title={$mp}&token=123ABC&" .
225 'protections=&reason=Lifting%20restrictions'
226 =>
'apihelp-protect-example-unprotect2',
231 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protect';
236class_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...