Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiStabilizeGeneral
0.00% covered (danger)
0.00%
0 / 62
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 1
 doExecute
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
12
 defaultFromKey
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 24
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\Api\ApiResult;
25use Wikimedia\ParamValidator\ParamValidator;
26
27/**
28 * API module to stabilize pages
29 * Assumes $wgFlaggedRevsProtection is off
30 *
31 * @ingroup FlaggedRevs
32 */
33class ApiStabilizeGeneral extends ApiStabilize {
34    public function doExecute() {
35        $params = $this->extractRequestParams();
36        $user = $this->getUser();
37
38        $form = new PageStabilityGeneralForm( $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        $restriction = $params['autoreview'];
45
46        // Fill in config fields from URL params
47        $form->setOverride( $this->defaultFromKey( $params['default'] ) );
48
49        $form->setReviewThis( $params['review'] ); # Auto-review option
50
51        if ( $restriction == 'none' ) {
52            $restriction = ''; // 'none' => ''
53        }
54
55        $form->setAutoreview( $restriction ); # Autoreview restriction
56        $form->ready();
57
58        $status = $form->submit(); // true/error message key
59        if ( $status !== true ) {
60            $this->dieWithError( $status );
61        }
62
63        # Output success line with the title and config parameters
64        $res = [];
65        $res['title'] = $this->title->getPrefixedText();
66        $res['default'] = $params['default'];
67        $res['autoreview'] = $params['autoreview'];
68        $res['expiry'] = ApiResult::formatExpiry( $form->getExpiry() );
69        $this->getResult()->addValue( null, $this->getModuleName(), $res );
70    }
71
72    /**
73     * @param string $key
74     * @return int|null
75     */
76    private function defaultFromKey( $key ) {
77        if ( $key == 'stable' ) {
78            return 1;
79        } elseif ( $key == 'latest' ) {
80            return 0;
81        }
82
83        return null; // bad key?
84    }
85
86    /**
87     * @inheritDoc
88     */
89    protected function getAllowedParams() {
90        // Replace '' with more readable 'none' in autoreview restiction levels
91        $autoreviewLevels = [ ...FlaggedRevs::getRestrictionLevels(), 'none' ];
92        $pars = [
93            'default' => [
94                ParamValidator::PARAM_REQUIRED => true,
95                ParamValidator::PARAM_TYPE => [ 'latest', 'stable' ],
96            ],
97            'autoreview' => [
98                ParamValidator::PARAM_TYPE => $autoreviewLevels,
99                ParamValidator::PARAM_DEFAULT => 'none',
100            ],
101            'expiry' => [
102                ParamValidator::PARAM_DEFAULT => 'infinite',
103                ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-expiry-general',
104            ],
105            'reason' => '',
106            'review' => false,
107        ];
108
109        $pars += [
110            'title' => [
111                ParamValidator::PARAM_REQUIRED => true,
112                ApiBase::PARAM_HELP_MSG => 'apihelp-stabilize-param-title-general',
113            ],
114        ];
115        return $pars;
116    }
117
118    /**
119     * @return string
120     */
121    protected function getSummaryMessage() {
122        return "apihelp-{$this->getModulePath()}-summary-general";
123    }
124
125    /**
126     * @inheritDoc
127     */
128    protected function getExtendedDescription() {
129        return [ [
130            "apihelp-{$this->getModulePath()}-extended-description-general",
131            'api-help-no-extended-description',
132        ] ];
133    }
134
135    /**
136     * @inheritDoc
137     */
138    protected function getExamplesMessages() {
139        return [
140            'action=stabilize&title=Test&default=stable&reason=Test&token=123ABC'
141                => 'apihelp-stabilize-example-general',
142        ];
143    }
144}