Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -258,6 +258,7 @@ |
259 | 259 | $wgAutoloadClasses['FlaggedRevision'] = $dir . 'FlaggedRevision.php'; |
260 | 260 | |
261 | 261 | # Business object classes |
| 262 | +$wgAutoloadClasses['FRGenericSubmitForm'] = $dir . 'business/FRGenericSubmitForm.php'; |
262 | 263 | $wgAutoloadClasses['RevisionReviewForm'] = $dir . 'business/RevisionReviewForm.php'; |
263 | 264 | $wgAutoloadClasses['PageStabilityForm'] = $dir . 'business/PageStabilityForm.php'; |
264 | 265 | $wgAutoloadClasses['PageStabilityGeneralForm'] = $dir . 'business/PageStabilityForm.php'; |
Index: trunk/extensions/FlaggedRevs/business/FRGenericSubmitForm.php |
— | — | @@ -0,0 +1,130 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Class containing generic form business logic |
| 5 | + * Note: edit tokens are the responsibility of the caller |
| 6 | + * Usage: (a) set ALL form params before doing anything else |
| 7 | + * (b) call ready() when all params are set |
| 8 | + * (c) call submit() as needed |
| 9 | + */ |
| 10 | +abstract class FRGenericSubmitForm { |
| 11 | + const ON_SUBMISSION = 1; # Notify functions when we are submitting |
| 12 | + |
| 13 | + protected $inputLock = 0; # Disallow bad submissions |
| 14 | + protected $user = null; |
| 15 | + |
| 16 | + public function __construct( User $user ) { |
| 17 | + $this->user = $user; |
| 18 | + $this->initialize(); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Initialize any parameters on construction |
| 23 | + * @return void |
| 24 | + */ |
| 25 | + protected function initialize() {} |
| 26 | + |
| 27 | + /** |
| 28 | + * Get the submitting user |
| 29 | + * @return User |
| 30 | + */ |
| 31 | + public function getUser() { |
| 32 | + return $this->user; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Signal that inputs will be given (via accessors) |
| 37 | + * @return void |
| 38 | + */ |
| 39 | + public function start() { |
| 40 | + $this->inputLock = 0; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Signal that inputs are all given (via accessors) |
| 45 | + * @return mixed (true on success, error string on target failure) |
| 46 | + */ |
| 47 | + public function ready() { |
| 48 | + $this->inputLock = 1; |
| 49 | + $status = $this->doCheckTarget(); |
| 50 | + if ( $status !== true ) { |
| 51 | + return $status; // bad target |
| 52 | + } |
| 53 | + return $this->doLoadOnReady(); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Set a member field to a value if the fields are unlocked |
| 58 | + * @param mixed &$field Field of this form |
| 59 | + * @param mixed $value Value to set the field to |
| 60 | + * @return void |
| 61 | + */ |
| 62 | + protected function trySet( &$field, $value ) { |
| 63 | + if ( $this->inputLock ) { |
| 64 | + throw new MWException( __CLASS__ . " fields cannot be set anymore.\n"); |
| 65 | + } else { |
| 66 | + $field = $value; // still allowing input |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /* |
| 71 | + * Check that the target is valid (e.g. from GET/POST request) |
| 72 | + * @param int $flags ON_SUBMISSION (set on submit) |
| 73 | + * @return mixed (true on success, error string on failure) |
| 74 | + */ |
| 75 | + protected function doCheckTarget( $flags = 0 ) { |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Load any parameters after ready() called |
| 81 | + * @return mixed (true on success, error string on failure) |
| 82 | + */ |
| 83 | + protected function doLoadOnReady() { |
| 84 | + return true; |
| 85 | + } |
| 86 | + |
| 87 | + /* |
| 88 | + * Verify and clean up parameters (e.g. from POST request) |
| 89 | + * @return mixed (true on success, error string on failure) |
| 90 | + */ |
| 91 | + protected function checkParameters() { |
| 92 | + $status = $this->doCheckTarget( self::ON_SUBMISSION ); |
| 93 | + if ( $status !== true ) { |
| 94 | + return $status; // bad target |
| 95 | + } |
| 96 | + return $this->doCheckParameters(); |
| 97 | + } |
| 98 | + |
| 99 | + /* |
| 100 | + * Verify and clean up parameters (e.g. from POST request) |
| 101 | + * @return mixed (true on success, error string on failure) |
| 102 | + */ |
| 103 | + protected function doCheckParameters() { |
| 104 | + return true; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Submit the form parameters for the page config to the DB. |
| 109 | + * |
| 110 | + * @return mixed (true on success, error string on failure) |
| 111 | + */ |
| 112 | + public function submit() { |
| 113 | + if ( !$this->inputLock ) { |
| 114 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 115 | + } |
| 116 | + $status = $this->checkParameters(); |
| 117 | + if ( $status !== true ) { |
| 118 | + return $status; // cannot submit - broken params |
| 119 | + } |
| 120 | + return $this->doSubmit(); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Submit the form parameters for the page config to the DB. |
| 125 | + * |
| 126 | + * @return mixed (true on success, error string on failure) |
| 127 | + */ |
| 128 | + protected function doSubmit() { |
| 129 | + return true; |
| 130 | + } |
| 131 | +} |
Property changes on: trunk/extensions/FlaggedRevs/business/FRGenericSubmitForm.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 132 | + native |
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php |
— | — | @@ -1,12 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Class containing revision review form business logic |
5 | | - * Note: edit tokens are the responsibility of caller |
6 | | - * Usage: (a) set ALL form params before doing anything else |
7 | | - * (b) call ready() when all params are set |
8 | | - * (c) call submit() as needed |
9 | 5 | */ |
10 | | -class RevisionReviewForm { |
| 6 | +class RevisionReviewForm extends FRGenericSubmitForm { |
11 | 7 | /* Form parameters which can be user given */ |
12 | 8 | protected $page = null; |
13 | 9 | protected $approve = false; |
— | — | @@ -24,21 +20,13 @@ |
25 | 21 | protected $newLastChangeTime = null; # Conflict handling |
26 | 22 | |
27 | 23 | protected $oflags = array(); |
28 | | - protected $inputLock = 0; # Disallow bad submissions |
29 | 24 | |
30 | | - protected $user = null; |
31 | | - |
32 | | - public function __construct( User $user ) { |
33 | | - $this->user = $user; |
| 25 | + public function initialize() { |
34 | 26 | foreach ( FlaggedRevs::getTags() as $tag ) { |
35 | 27 | $this->dims[$tag] = 0; // default to "inadequate" |
36 | 28 | } |
37 | 29 | } |
38 | 30 | |
39 | | - public function getUser() { |
40 | | - return $this->user; |
41 | | - } |
42 | | - |
43 | 31 | public function getPage() { |
44 | 32 | return $this->page; |
45 | 33 | } |
— | — | @@ -135,52 +123,31 @@ |
136 | 124 | } |
137 | 125 | |
138 | 126 | /** |
139 | | - * Set a member field to a value if the fields are unlocked |
140 | | - */ |
141 | | - protected function trySet( &$field, $value ) { |
142 | | - if ( $this->inputLock ) { |
143 | | - throw new MWException( __CLASS__ . " fields cannot be set anymore.\n"); |
144 | | - } else { |
145 | | - $field = $value; // still allowing input |
146 | | - } |
147 | | - } |
148 | | - |
149 | | - /** |
150 | | - * Signal that inputs are starting |
151 | | - */ |
152 | | - public function start() { |
153 | | - $this->inputLock = 0; |
154 | | - } |
155 | | - |
156 | | - /** |
157 | | - * Signal that inputs are done and load old config |
| 127 | + * Load old config and last review status change time |
158 | 128 | * @return mixed (true on success, error string on target failure) |
159 | 129 | */ |
160 | | - public function ready() { |
161 | | - $this->inputLock = 1; |
162 | | - $status = $this->checkTarget(); |
163 | | - if ( $status !== true ) { |
164 | | - return $status; // bad target |
165 | | - } |
| 130 | + public function doLoadOnReady() { |
166 | 131 | # Get the revision's current flags, if any |
167 | 132 | $this->oflags = FlaggedRevs::getRevisionTags( $this->page, $this->oldid, FR_MASTER ); |
168 | 133 | # Set initial value for newLastChangeTime (if unchanged on submit) |
169 | 134 | $this->newLastChangeTime = $this->lastChangeTime; |
170 | | - return $status; |
| 135 | + return true; |
171 | 136 | } |
172 | 137 | |
173 | 138 | /* |
174 | | - * Check that the target page is valid |
| 139 | + * Check that the target is valid (e.g. from GET/POST request) |
| 140 | + * @param int $flags ON_SUBMISSION (set on submit) |
175 | 141 | * @return mixed (true on success, error string on failure) |
176 | 142 | */ |
177 | | - protected function checkTarget() { |
| 143 | + protected function doCheckTarget( $flags = 0 ) { |
178 | 144 | if ( is_null( $this->page ) ) { |
179 | 145 | return 'review_page_invalid'; |
180 | 146 | } elseif ( !$this->page->exists() ) { |
181 | 147 | return 'review_page_notexists'; |
182 | 148 | } |
183 | 149 | $fa = FlaggedArticle::getTitleInstance( $this->page ); |
184 | | - if ( !$fa->isReviewable() ) { |
| 150 | + $flags = ( $flags & self::ON_SUBMISSION ) ? FR_MASTER : 0; |
| 151 | + if ( !$fa->isReviewable( $flags ) ) { |
185 | 152 | return 'review_page_unreviewable'; |
186 | 153 | } |
187 | 154 | return true; |
— | — | @@ -190,11 +157,8 @@ |
191 | 158 | * Verify and clean up parameters (e.g. from POST request). |
192 | 159 | * @return mixed (true on success, error string on failure) |
193 | 160 | */ |
194 | | - protected function checkSettings() { |
195 | | - $status = $this->checkTarget(); |
196 | | - if ( $status !== true ) { |
197 | | - return $status; // bad page target |
198 | | - } elseif ( !$this->oldid ) { |
| 161 | + protected function doCheckParameters() { |
| 162 | + if ( !$this->oldid ) { |
199 | 163 | return 'review_no_oldid'; // bad revision target |
200 | 164 | } |
201 | 165 | # Check that an action is specified (approve, reject, de-approve) |
— | — | @@ -275,14 +239,7 @@ |
276 | 240 | * |
277 | 241 | * @return mixed (true on success, error string on failure) |
278 | 242 | */ |
279 | | - public function submit() { |
280 | | - if ( !$this->inputLock ) { |
281 | | - throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
282 | | - } |
283 | | - $status = $this->checkSettings(); |
284 | | - if ( $status !== true ) { |
285 | | - return $status; // cannot submit - broken params |
286 | | - } |
| 243 | + public function doSubmit() { |
287 | 244 | # Double-check permissions |
288 | 245 | if ( !$this->isAllowed() ) { |
289 | 246 | return 'review_denied'; |
Index: trunk/extensions/FlaggedRevs/business/PageStabilityForm.php |
— | — | @@ -1,12 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Class containing stability settings form business logic |
5 | | - * Note: edit tokens are the responsibility of caller |
6 | | - * Usage: (a) set ALL form params before doing anything else |
7 | | - * (b) call ready() when all params are set |
8 | | - * (c) call preloadSettings() or submit() as needed |
9 | 5 | */ |
10 | | -abstract class PageStabilityForm { |
| 6 | +abstract class PageStabilityForm extends FRGenericSubmitForm { |
11 | 7 | /* Form parameters which can be user given */ |
12 | 8 | protected $page = false; # Target page obj |
13 | 9 | protected $watchThis = null; # Watch checkbox |
— | — | @@ -19,18 +15,7 @@ |
20 | 16 | protected $autoreview = ''; # Autoreview restrictions... |
21 | 17 | |
22 | 18 | protected $oldConfig = array(); # Old page config |
23 | | - protected $inputLock = 0; # Disallow bad submissions |
24 | 19 | |
25 | | - protected $user = null; |
26 | | - |
27 | | - public function __construct( User $user ) { |
28 | | - $this->user = $user; |
29 | | - } |
30 | | - |
31 | | - public function getUser() { |
32 | | - return $this->user; |
33 | | - } |
34 | | - |
35 | 20 | public function getPage() { |
36 | 21 | return $this->page; |
37 | 22 | } |
— | — | @@ -133,38 +118,6 @@ |
134 | 119 | return $comment; |
135 | 120 | } |
136 | 121 | |
137 | | - /** |
138 | | - * Set a member field to a value if the fields are unlocked |
139 | | - */ |
140 | | - protected function trySet( &$field, $value ) { |
141 | | - if ( $this->inputLock ) { |
142 | | - throw new MWException( __CLASS__ . " fields cannot be set anymore.\n"); |
143 | | - } else { |
144 | | - $field = $value; // still allowing input |
145 | | - } |
146 | | - } |
147 | | - |
148 | | - /** |
149 | | - * Signal that inputs are starting |
150 | | - */ |
151 | | - public function start() { |
152 | | - $this->inputLock = 0; |
153 | | - } |
154 | | - |
155 | | - /** |
156 | | - * Signal that inputs are done and load old config |
157 | | - * @return mixed (true on success, error string on target failure) |
158 | | - */ |
159 | | - public function ready() { |
160 | | - $this->inputLock = 1; |
161 | | - $status = $this->checkTarget(); |
162 | | - if ( $status !== true ) { |
163 | | - return $status; // bad target |
164 | | - } |
165 | | - $this->loadOldConfig(); // current settings from DB |
166 | | - return $status; |
167 | | - } |
168 | | - |
169 | 122 | /* |
170 | 123 | * Preload existing page settings (e.g. from GET request). |
171 | 124 | * @return mixed (true on success, error string on failure) |
— | — | @@ -173,7 +126,7 @@ |
174 | 127 | if ( !$this->inputLock ) { |
175 | 128 | throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
176 | 129 | } |
177 | | - $status = $this->checkTarget(); |
| 130 | + $status = $this->doCheckTarget(); |
178 | 131 | if ( $status !== true ) { |
179 | 132 | return $status; // bad target |
180 | 133 | } |
— | — | @@ -196,31 +149,28 @@ |
197 | 150 | * Verify and clean up parameters (e.g. from POST request). |
198 | 151 | * @return mixed (true on success, error string on failure) |
199 | 152 | */ |
200 | | - protected function checkSettings() { |
201 | | - $status = $this->checkTarget(); |
202 | | - if ( $status !== true ) { |
203 | | - return $status; // bad target |
204 | | - } |
| 153 | + protected function doCheckParameters() { |
205 | 154 | if ( $this->expiryCustom != '' ) { |
206 | 155 | // Custom expiry takes precedence |
207 | 156 | $this->expirySelection = 'othertime'; |
208 | 157 | } |
209 | | - $status = $this->reallyCheckSettings(); // check other params... |
| 158 | + $status = $this->reallyDoCheckParameters(); // check other params... |
210 | 159 | return $status; |
211 | 160 | } |
212 | 161 | |
213 | 162 | /* |
214 | 163 | * @return mixed (true on success, error string on failure) |
215 | 164 | */ |
216 | | - protected function reallyCheckSettings() { |
| 165 | + protected function reallyDoCheckParameters() { |
217 | 166 | return true; |
218 | 167 | } |
219 | 168 | |
220 | 169 | /* |
221 | 170 | * Check that the target page is valid |
| 171 | + * @param int $flags ON_SUBMISSION (set on submit) |
222 | 172 | * @return mixed (true on success, error string on failure) |
223 | 173 | */ |
224 | | - protected function checkTarget() { |
| 174 | + protected function doCheckTarget( $flags = 0 ) { |
225 | 175 | if ( is_null( $this->page ) ) { |
226 | 176 | return 'stabilize_page_invalid'; |
227 | 177 | } elseif ( !$this->page->exists() ) { |
— | — | @@ -231,9 +181,10 @@ |
232 | 182 | return true; |
233 | 183 | } |
234 | 184 | |
235 | | - protected function loadOldConfig() { |
| 185 | + protected function doLoadOnReady() { |
236 | 186 | # Get the current page config |
237 | 187 | $this->oldConfig = FlaggedPageConfig::getPageStabilitySettings( $this->page, FR_MASTER ); |
| 188 | + return true; |
238 | 189 | } |
239 | 190 | |
240 | 191 | /* |
— | — | @@ -256,14 +207,7 @@ |
257 | 208 | * |
258 | 209 | * @return mixed (true on success, error string on failure) |
259 | 210 | */ |
260 | | - public function submit() { |
261 | | - if ( !$this->inputLock ) { |
262 | | - throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
263 | | - } |
264 | | - $status = $this->checkSettings(); |
265 | | - if ( $status !== true ) { |
266 | | - return $status; // cannot submit - broken params |
267 | | - } |
| 211 | + public function doSubmit() { |
268 | 212 | # Double-check permissions |
269 | 213 | if ( !$this->isAllowed() ) { |
270 | 214 | return 'stablize_denied'; |
— | — | @@ -435,7 +379,7 @@ |
436 | 380 | return true; |
437 | 381 | } |
438 | 382 | |
439 | | - protected function reallyCheckSettings() { |
| 383 | + protected function reallyDoCheckParameters() { |
440 | 384 | $this->override = $this->override ? 1 : 0; // default version settings is 0 or 1 |
441 | 385 | // Check autoreview restriction setting |
442 | 386 | if ( $this->autoreview != '' // restriction other than 'none' |
— | — | @@ -533,12 +477,12 @@ |
534 | 478 | return true; |
535 | 479 | } |
536 | 480 | |
537 | | - protected function reallyCheckSettings() { |
| 481 | + protected function reallyDoCheckParameters() { |
538 | 482 | # WMF temp hack...protection limit quota |
539 | 483 | global $wgFlaggedRevsProtectQuota; |
540 | 484 | if ( isset( $wgFlaggedRevsProtectQuota ) // quota exists |
541 | 485 | && $this->autoreview != '' // and we are protecting |
542 | | - && FlaggedPageConfig::getProtectionLevel( $this->oldConfig ) == 'none' ) // page unprotected |
| 486 | + && FlaggedPageConfig::getProtectionLevel( $this->oldConfig ) == 'none' ) // unprotected |
543 | 487 | { |
544 | 488 | $dbw = wfGetDB( DB_MASTER ); |
545 | 489 | $count = $dbw->selectField( 'flaggedpage_config', 'COUNT(*)', '', __METHOD__ ); |