r56708 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56707‎ | r56708 | r56709 >
Date:14:58, 21 September 2009
Author:aaron
Status:ok
Tags:
Comment:
revert r56638: massive duplication
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/api/ApiStabilize.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -366,9 +366,7 @@
367367 $wgAPIPropModules['flagged'] = 'ApiQueryFlagged';
368368
369369 $wgAutoloadClasses['ApiReview'] = $dir.'api/ApiReview.php';
370 -$wgAutoloadClasses['ApiStabilize'] = $dir.'api/ApiStabilize.php';
371370 $wgAPIModules['review'] = 'ApiReview';
372 -$wgAPIModules['stabilize'] = 'ApiStabilize';
373371
374372 ######### Hook attachments #########
375373 # Autopromote Editors
Index: trunk/extensions/FlaggedRevs/api/ApiStabilize.php
@@ -1,235 +0,0 @@
2 -<?php
3 -
4 -/*
5 - * Created on Sep 19, 2009
6 - *
7 - * API module for MediaWiki's FlaggedRevs extension
8 - *
9 - * This program is free software; you can redistribute it and/or modify
10 - * it under the terms of the GNU General Public License as published by
11 - * the Free Software Foundation; either version 2 of the License, or
12 - * (at your option) any later version.
13 - *
14 - * This program is distributed in the hope that it will be useful,
15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 - * GNU General Public License for more details.
18 - *
19 - * You should have received a copy of the GNU General Public License along
20 - * with this program; if not, write to the Free Software Foundation, Inc.,
21 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 - * http://www.gnu.org/copyleft/gpl.html
23 - */
24 -
25 -/**
26 - * API module to stabilize pages
27 - *
28 - * @ingroup FlaggedRevs
29 - */
30 -class ApiStabilize extends ApiBase {
31 - public function execute() {
32 - global $wgUser, $wgContLang;
33 - $params = $this->extractRequestParams();
34 -
35 - // Check permissions
36 - if( !$wgUser->isAllowed( 'stablesettings' ) )
37 - $this->dieUsageMsg( array( 'badaccess-group0' ) );
38 - if( $wgUser->isBlocked() )
39 - $this->dieUsageMsg( array( 'blockedtext' ) );
40 - //if( !$wgUser->matchEditToken( $params['token'] ) )
41 - // $this->dieUsageMsg( array( 'sessionfailure' ) );
42 -
43 - $target = Title::newFromText( $params['title'] );
44 - if( !$target )
45 - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
46 - if( !$target->getArticleID() )
47 - $this->dieUsageMsg( array( 'notanarticle', $params['title'] ) );
48 -
49 - $stabilize = $params['default'] == 'stable';
50 - $autoreview = $params['restriction'] == 'none' ?
51 - '' : $params['restriction'];
52 - switch( $params['precedence'] ) {
53 - case 'latest':
54 - $precedence = FLAGGED_VIS_LATEST;
55 - break;
56 - case 'quality':
57 - $precedence = FLAGGED_VIS_QUALITY;
58 - break;
59 - case 'pristine':
60 - $precedence = FLAGGED_VIS_PRISTINE;
61 - break;
62 - }
63 - $reset = $precedence == FlaggedRevs::getPrecedence() &&
64 - $stabilize == FlaggedRevs::showStableByDefault();
65 -
66 - if( !$reset || $params['expiry'] == 'infinite' || $params['expiry'] == 'indefinite' ) {
67 - $expiry = Block::infinity();
68 - } else {
69 - # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
70 - $expiry = strtotime( $params['expiry'] );
71 - if( $expiry < 0 || $expiry === false ) {
72 - $this->dieUsageMsg( array( 'ipb_expiry_invalid' ) );
73 - }
74 - $expiry = wfTimestamp( TS_MW, $expiry );
75 - if( $expiry < wfTimestampNow() )
76 - $this->dieUsageMsg( array( 'ipb_expiry_invalid' ) );
77 - }
78 -
79 - FlaggedRevs::purgeExpiredConfigurations();
80 -
81 - $dbw = wfGetDB( DB_MASTER );
82 - $row = $dbw->selectRow( 'flaggedpage_config',
83 - array( 'fpc_select', 'fpc_override', 'fpc_level', 'fpc_expiry' ),
84 - array( 'fpc_page_id' => $target->getArticleID() ),
85 - __METHOD__
86 - );
87 - if( !$reset ) {
88 - $changed = false;
89 - if( !$row
90 - || $row->fpc_select != $precedence
91 - || $row->fpc_override != $stabilize
92 - || $row->fpc_level != $autoreview
93 - || $row->fpc_expiry != $expiry ) {
94 - $changed = true;
95 - $dbw->replace( 'flaggedpage_config',
96 - array( 'PRIMARY' ),
97 - array( 'fpc_page_id' => $target->getArticleID(),
98 - 'fpc_select' => $precedence,
99 - 'fpc_override' => $stabilize,
100 - 'fpc_level' => $autoreview,
101 - 'fpc_expiry' => $expiry ),
102 - __METHOD__
103 - );
104 - }
105 - } else {
106 - $dbw->delete(
107 - 'flaggedpage_config',
108 - array( 'fpc_page_id' => $target->getArticleID() ),
109 - __METHOD__
110 - );
111 - $changed = (bool)$dbw->affectedRows();
112 - }
113 -
114 - # Mostly copied from Stabilization_body.php
115 - if( $changed ) {
116 - $latest = $target->getLatestRevID( GAID_FOR_UPDATE );
117 - # ID, accuracy, depth, style
118 - $set = array();
119 - # @FIXME: do this better
120 - $set[] = wfMsgForContent( "stabilization-sel-short" ) . wfMsgForContent( 'colon-separator' ) .
121 - wfMsgForContent("stabilization-sel-short-{$precedence}");
122 - $set[] = wfMsgForContent( "stabilization-def-short" ) . wfMsgForContent( 'colon-separator' ) .
123 - wfMsgForContent("stabilization-def-short-" . ((int)$stabilize) );
124 - if( strlen( $autoreview ) ) {
125 - $set[] = "autoreview={$autoreview}";
126 - }
127 - $settings = '[' . implode( ', ' , $set ). ']';
128 - # Append comment with settings (other than for resets)
129 - $reason = '';
130 - if( !$reset ) {
131 - $reason = $params['reason'] ? "{$params['reason']} $settings" : "$settings";
132 - $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
133 - if( $encodedExpiry != 'infinity' ) {
134 - $expiryDescription = ' (' . wfMsgForContent( 'stabilize-expiring',
135 - $wgContLang->timeanddate($expiry, false, false) ,
136 - $wgContLang->date($expiry, false, false) ,
137 - $wgContLang->time($expiry, false, false) ) . ')';
138 - $reason .= $expiryDescription;
139 - }
140 - }
141 - # Add log entry...
142 - $log = new LogPage( 'stable' );
143 - if( !$reset ) {
144 - $log->addEntry( 'config', $target, $reason );
145 - $type = "stable-logentry";
146 - } else {
147 - $log->addEntry( 'reset', $target, $reason );
148 - $type = "stable-logentry2";
149 - }
150 - # Build null-edit comment
151 - $comment = $wgContLang->ucfirst( wfMsgForContent( $type, $target->getPrefixedText() ) );
152 - if( $reason ) {
153 - $comment .= ": $reason";
154 - }
155 - # Insert a null revision
156 - $nullRevision = Revision::newNullRevision( $dbw, $target->getArticleID(), $comment, true );
157 - $nullRevId = $nullRevision->insertOn( $dbw );
158 - # Update page record and touch page
159 - $article = new Article( $target );
160 - $article->updateRevisionOn( $dbw, $nullRevision, $latest );
161 - wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest ) );
162 -
163 - $res['title'] = $target->getPrefixedText();
164 - $res['default'] = (int)$stabilize;
165 - $this->getResult()->addValue(null, $this->getModuleName(), $res);
166 - }
167 - }
168 -
169 - protected function getRestrictionLevels() {
170 - global $wgUser, $wgFlaggedRevsRestrictionLevels;
171 - $levels = array( 'none' );
172 - foreach( $wgFlaggedRevsRestrictionLevels as $level ) {
173 - if( $level == 'sysop' )
174 - if( $wgUser->isAllowed( 'protect' ) || $wgUser->isAllowed( 'editprotected' ) )
175 - $levels[] = 'sysop';
176 - else
177 - if( $wgUser->isAllowed( $level ) )
178 - $levels[] = $level;
179 - }
180 - return $levels;
181 - }
182 -
183 - public function mustBePosted() {
184 - return true;
185 - }
186 -
187 - public function isWriteMode() {
188 - return true;
189 - }
190 -
191 - public function getAllowedParams() {
192 - $pars = array(
193 - 'default' => array(
194 - ApiBase :: PARAM_TYPE => array( 'latest', 'stable' ),
195 - ),
196 - 'precedence' => array(
197 - ApiBase :: PARAM_TYPE => array( 'pristine', 'quality', 'latest' ),
198 - ApiBase :: PARAM_DFLT => 'latest',
199 - ),
200 - 'restriction' => array(
201 - ApiBase :: PARAM_TYPE => $this->getRestrictionLevels(),
202 - ApiBase :: PARAM_DFLT => 'none',
203 - ),
204 - 'expiry' => 'infinite',
205 - 'reason' => null,
206 - 'token' => null,
207 - 'title' => null,
208 - );
209 - return $pars;
210 - }
211 -
212 - public function getParamDescription() {
213 - $desc = array(
214 - 'default' => 'Default revision to show',
215 - 'precedence' => 'What stable revision should be shown',
216 - 'restriction' => 'Auto-review restriction',
217 - 'expiry' => 'Stabilization expiry',
218 - 'title' => 'Title of page to be stabilized',
219 - 'reason' => 'Reason',
220 - 'token' => 'An edit token retrieved through prop=info',
221 - );
222 - return $desc;
223 - }
224 -
225 - public function getDescription() {
226 - return 'Change page stabilization settings.';
227 - }
228 -
229 - protected function getExamples() {
230 - return 'api.php?action=stabilize&title=Test&default=stable&reason=Test&token=123ABC';
231 - }
232 -
233 - public function getVersion() {
234 - return __CLASS__ . ': $Id$';
235 - }
236 -}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56638Add an API module for stabilization.vasilievvv13:17, 19 September 2009

Status & tagging log