Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiStabilizeProtect
0.00% covered (danger)
0.00%
0 / 50
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 doExecute
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
 getSummaryMessage
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getExtendedDescription
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Created on Sep 19, 2009
4 *
5 * API module for MediaWiki's FlaggedRevs extension
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 */
22
23use MediaWiki\Api\ApiBase;
24use MediaWiki\MediaWikiServices;
25use Wikimedia\ParamValidator\ParamValidator;
26
27/**
28 * API module to stabilize pages
29 * Assumes $wgFlaggedRevsProtection is on
30 *
31 * @ingroup FlaggedRevs
32 */
33class ApiStabilizeProtect extends ApiStabilize {
34    public function doExecute() {
35        $params = $this->extractRequestParams();
36        $user = $this->getUser();
37
38        $form = new PageStabilityProtectForm( $user );
39        $form->setTitle( $this->title ); # Our target page
40        $form->setReasonExtra( $params['reason'] ); # Reason
41        $form->setReasonSelection( 'other' ); # Reason dropdown
42        $form->setExpiryCustom( $params['expiry'] ); # Expiry
43        $form->setExpirySelection( 'other' ); # Expiry dropdown
44
45        $restriction = $params['protectlevel'];
46        if ( $restriction == 'none' ) {
47            $restriction = ''; // 'none' => ''
48        }
49
50        $form->setAutoreview( $restriction ); # Autoreview restriction
51        $form->ready();
52
53        $status = $form->submit(); // true/error message key
54        if ( $status !== true ) {
55            $this->dieWithError( $status );
56        }
57
58        # Output success line with the title and config parameters
59        $res = [];
60        $res['title'] = $this->title->getPrefixedText();
61        $res['protectlevel'] = $params['protectlevel'];
62        $res['expiry'] = MediaWikiServices::getInstance()->getContentLanguage()
63            ->formatExpiry( $form->getExpiry(), TS_ISO_8601 );
64        $this->getResult()->addValue( null, $this->getModuleName(), $res );
65    }
66
67    /**
68     * @inheritDoc
69     */
70    protected function getAllowedParams() {
71        // Replace '' with more readable 'none' in autoreview restiction levels
72        $autoreviewLevels = [ ...FlaggedRevs::getRestrictionLevels(), 'none' ];
73        $params = [
74            'protectlevel' => [
75                ParamValidator::PARAM_TYPE => $autoreviewLevels,
76                ParamValidator::PARAM_DEFAULT => 'none',
77            ],
78            'expiry' => [
79                ParamValidator::PARAM_DEFAULT => 'infinite',
80                ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-expiry-protect',
81            ],
82            'reason' => '',
83        ];
84
85        $params += [
86            'title' => [
87                ParamValidator::PARAM_REQUIRED => true,
88                ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-title-protect',
89            ],
90        ];
91
92        return $params;
93    }
94
95    /**
96     * @return string
97     */
98    protected function getSummaryMessage() {
99        return "apihelp-{$this->getModulePath()}-summary-protect";
100    }
101
102    /**
103     * @inheritDoc
104     */
105    protected function getExtendedDescription() {
106        return [ [
107            "apihelp-{$this->getModulePath()}-extended-description-protect",
108            'api-help-no-extended-description',
109        ] ];
110    }
111
112    /**
113     * @inheritDoc
114     */
115    protected function getExamplesMessages() {
116        return [
117            'action=stabilize&title=Test&protectlevel=none&reason=Test&token=123ABC'
118                => 'apihelp-stabilize-example-protect',
119        ];
120    }
121}