Index: trunk/extensions/FlaggedRevs/business/FRGenericSubmitForm.php |
— | — | @@ -4,15 +4,20 @@ |
5 | 5 | * Note: edit tokens are the responsibility of the caller |
6 | 6 | * Usage: (a) set ALL form params before doing anything else |
7 | 7 | * (b) call ready() when all params are set |
8 | | - * (c) call submit() as needed |
| 8 | + * (c) call preload() OR submit() as needed |
9 | 9 | */ |
10 | 10 | abstract class FRGenericSubmitForm { |
11 | | - const ON_SUBMISSION = 1; # Notify functions when we are submitting |
| 11 | + const FOR_SUBMISSION = 1; # Notify functions when we are submitting |
| 12 | + /* Internal form state */ |
| 13 | + const FORM_UNREADY = 0; # Params not given yet |
| 14 | + const FORM_READY = 1; # Params given and ready to submit |
| 15 | + const FORM_PRELOADED = 2; # Params pre-loaded (likely from slave DB) |
| 16 | + const FORM_SUBMITTED = 3; # Form submitted |
| 17 | + private $state = self::FORM_UNREADY; # Form state (disallows bad operations) |
12 | 18 | |
13 | | - protected $inputLock = 0; # Disallow bad submissions |
14 | | - protected $user = null; |
| 19 | + protected $user = null; # User performing the action |
15 | 20 | |
16 | | - public function __construct( User $user ) { |
| 21 | + final public function __construct( User $user ) { |
17 | 22 | $this->user = $user; |
18 | 23 | $this->initialize(); |
19 | 24 | } |
— | — | @@ -27,39 +32,51 @@ |
28 | 33 | * Get the submitting user |
29 | 34 | * @return User |
30 | 35 | */ |
31 | | - public function getUser() { |
| 36 | + final public function getUser() { |
32 | 37 | return $this->user; |
33 | 38 | } |
34 | 39 | |
35 | 40 | /** |
36 | | - * Signal that inputs will be given (via accessors) |
37 | | - * @return void |
| 41 | + * Get the internal form state |
| 42 | + * @return int |
38 | 43 | */ |
39 | | - public function start() { |
40 | | - $this->inputLock = 0; |
| 44 | + final protected function getState() { |
| 45 | + return $this->state; |
41 | 46 | } |
42 | 47 | |
43 | 48 | /** |
44 | 49 | * Signal that inputs are all given (via accessors) |
45 | 50 | * @return mixed (true on success, error string on target failure) |
46 | 51 | */ |
47 | | - public function ready() { |
48 | | - $this->inputLock = 1; |
49 | | - $status = $this->doCheckTarget(); |
| 52 | + final public function ready() { |
| 53 | + if ( $this->state != self::FORM_UNREADY ) { |
| 54 | + throw new MWException( __CLASS__ . " ready() already called.\n"); |
| 55 | + } |
| 56 | + $this->state = self::FORM_READY; |
| 57 | + $status = $this->doCheckTargetGiven(); |
50 | 58 | if ( $status !== true ) { |
51 | 59 | return $status; // bad target |
52 | 60 | } |
53 | | - return $this->doLoadOnReady(); |
| 61 | + return $this->doBuildOnReady(); |
54 | 62 | } |
55 | 63 | |
56 | 64 | /** |
| 65 | + * Load any objects after ready() called |
| 66 | + * NOTE: do not do any DB hits here, just build objects |
| 67 | + * @return mixed (true on success, error string on failure) |
| 68 | + */ |
| 69 | + protected function doBuildOnReady() { |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
57 | 74 | * Set a member field to a value if the fields are unlocked |
58 | 75 | * @param mixed &$field Field of this form |
59 | 76 | * @param mixed $value Value to set the field to |
60 | 77 | * @return void |
61 | 78 | */ |
62 | | - protected function trySet( &$field, $value ) { |
63 | | - if ( $this->inputLock ) { |
| 79 | + final protected function trySet( &$field, $value ) { |
| 80 | + if ( $this->state != self::FORM_UNREADY ) { |
64 | 81 | throw new MWException( __CLASS__ . " fields cannot be set anymore.\n"); |
65 | 82 | } else { |
66 | 83 | $field = $value; // still allowing input |
— | — | @@ -67,51 +84,45 @@ |
68 | 85 | } |
69 | 86 | |
70 | 87 | /* |
71 | | - * Preload existing params from a DB (e.g. for GET request). |
| 88 | + * Check that a target is given (e.g. from GET/POST request) |
| 89 | + * NOTE: do not do any DB hits here, just check if there is a target |
72 | 90 | * @return mixed (true on success, error string on failure) |
73 | 91 | */ |
74 | | - public function preload() { |
75 | | - if ( !$this->inputLock ) { |
76 | | - throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
77 | | - } |
78 | | - $status = $this->doCheckTarget(); |
79 | | - if ( $status !== true ) { |
80 | | - return $status; // bad target |
81 | | - } |
82 | | - return $this->doPreloadParameters(); |
83 | | - } |
84 | | - |
85 | | - /* |
86 | | - * Preload existing params from a DB (e.g. for GET request). |
87 | | - * @return mixed (true on success, error string on failure) |
88 | | - */ |
89 | | - protected function doPreloadParameters() { |
| 92 | + protected function doCheckTargetGiven() { |
90 | 93 | return true; |
91 | 94 | } |
92 | 95 | |
93 | 96 | /* |
94 | 97 | * Check that the target is valid (e.g. from GET/POST request) |
95 | | - * @param int $flags ON_SUBMISSION (set on submit) |
| 98 | + * @param int $flags FOR_SUBMISSION (set on submit) |
96 | 99 | * @return mixed (true on success, error string on failure) |
97 | 100 | */ |
98 | 101 | protected function doCheckTarget( $flags = 0 ) { |
99 | 102 | return true; |
100 | 103 | } |
101 | 104 | |
102 | | - /** |
103 | | - * Load any parameters after ready() called |
| 105 | + /* |
| 106 | + * Check that a target is and it is valid (e.g. from GET/POST request) |
| 107 | + * NOTE: do not do any DB hits here, just check if there is a target |
104 | 108 | * @return mixed (true on success, error string on failure) |
105 | 109 | */ |
106 | | - protected function doLoadOnReady() { |
107 | | - return true; |
| 110 | + final public function checkTarget() { |
| 111 | + if ( $this->state != self::FORM_READY ) { |
| 112 | + throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
| 113 | + } |
| 114 | + $status = $this->doCheckTargetGiven(); |
| 115 | + if ( $status !== true ) { |
| 116 | + return $status; // bad target |
| 117 | + } |
| 118 | + return $this->doCheckTarget(); |
108 | 119 | } |
109 | 120 | |
110 | 121 | /* |
111 | | - * Verify and clean up parameters (e.g. from POST request) |
| 122 | + * Validate and clean up target/parameters (e.g. from POST request) |
112 | 123 | * @return mixed (true on success, error string on failure) |
113 | 124 | */ |
114 | | - protected function checkParameters() { |
115 | | - $status = $this->doCheckTarget( self::ON_SUBMISSION ); |
| 125 | + final protected function checkParameters() { |
| 126 | + $status = $this->checkTarget( self::FOR_SUBMISSION ); |
116 | 127 | if ( $status !== true ) { |
117 | 128 | return $status; // bad target |
118 | 129 | } |
— | — | @@ -126,25 +137,57 @@ |
127 | 138 | return true; |
128 | 139 | } |
129 | 140 | |
130 | | - /** |
131 | | - * Submit the form parameters for the page config to the DB. |
132 | | - * |
| 141 | + /* |
| 142 | + * Preload existing params for the target from the DB (e.g. for GET request) |
| 143 | + * NOTE: do not call this and then submit() |
133 | 144 | * @return mixed (true on success, error string on failure) |
134 | 145 | */ |
135 | | - public function submit() { |
136 | | - if ( !$this->inputLock ) { |
| 146 | + final public function preload() { |
| 147 | + if ( $this->state != self::FORM_READY ) { |
137 | 148 | throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
138 | 149 | } |
| 150 | + $status = $this->checkTarget(); |
| 151 | + if ( $status !== true ) { |
| 152 | + return $status; // bad target |
| 153 | + } |
| 154 | + $status = $this->doPreloadParameters(); |
| 155 | + if ( $status !== true ) { |
| 156 | + return $status; // bad target |
| 157 | + } |
| 158 | + $this->state = self::FORM_PRELOADED; |
| 159 | + return true; |
| 160 | + } |
| 161 | + |
| 162 | + /* |
| 163 | + * Preload existing params for the target from the DB (e.g. for GET request) |
| 164 | + * @return mixed (true on success, error string on failure) |
| 165 | + */ |
| 166 | + protected function doPreloadParameters() { |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Submit the form parameters for the page config to the DB |
| 172 | + * @return mixed (true on success, error string on failure) |
| 173 | + */ |
| 174 | + final public function submit() { |
| 175 | + if ( $this->state != self::FORM_READY ) { |
| 176 | + throw new MWException( __CLASS__ . " input fields preloaded or not set yet.\n"); |
| 177 | + } |
139 | 178 | $status = $this->checkParameters(); |
140 | 179 | if ( $status !== true ) { |
141 | | - return $status; // cannot submit - broken params |
| 180 | + return $status; // cannot submit - broken target or params |
142 | 181 | } |
143 | | - return $this->doSubmit(); |
| 182 | + $status = $this->doSubmit(); |
| 183 | + if ( $status !== true ) { |
| 184 | + return $status; // cannot submit |
| 185 | + } |
| 186 | + $this->state = self::FORM_SUBMITTED; |
| 187 | + return true; |
144 | 188 | } |
145 | 189 | |
146 | 190 | /** |
147 | | - * Submit the form parameters for the page config to the DB. |
148 | | - * |
| 191 | + * Submit the form parameters for the page config to the DB |
149 | 192 | * @return mixed (true on success, error string on failure) |
150 | 193 | */ |
151 | 194 | protected function doSubmit() { |
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php |
— | — | @@ -4,24 +4,24 @@ |
5 | 5 | */ |
6 | 6 | class RevisionReviewForm extends FRGenericSubmitForm { |
7 | 7 | /* Form parameters which can be user given */ |
8 | | - protected $page = null; |
9 | | - protected $approve = false; |
10 | | - protected $unapprove = false; |
11 | | - protected $reject = false; |
12 | | - protected $oldid = 0; |
13 | | - protected $refid = 0; |
14 | | - protected $templateParams = ''; |
15 | | - protected $imageParams = ''; |
16 | | - protected $fileVersion = ''; |
17 | | - protected $validatedParams = ''; |
18 | | - protected $comment = ''; |
19 | | - protected $dims = array(); |
20 | | - protected $lastChangeTime = null; # Conflict handling |
21 | | - protected $newLastChangeTime = null; # Conflict handling |
| 8 | + protected $page = null; # Target page obj |
| 9 | + protected $approve = false; # Approval requested |
| 10 | + protected $unapprove = false; # De-approval requested |
| 11 | + protected $reject = false; # Rejection requested |
| 12 | + protected $oldid = 0; # ID being reviewed (last "bad" ID for rejection) |
| 13 | + protected $refid = 0; # Old, "last good", ID (used for rejection) |
| 14 | + protected $templateParams = ''; # Included template versions (flat string) |
| 15 | + protected $imageParams = ''; # Included file versions (flat string) |
| 16 | + protected $fileVersion = ''; # File page file version (flat string) |
| 17 | + protected $validatedParams = ''; # Parameter key |
| 18 | + protected $comment = ''; # Review comments |
| 19 | + protected $dims = array(); # Review flags (for approval) |
| 20 | + protected $lastChangeTime = null; # Conflict handling |
| 21 | + protected $newLastChangeTime = null; # Conflict handling |
22 | 22 | |
23 | | - protected $oflags = array(); |
| 23 | + protected $oflags = array(); # Prior flags for Rev with ID $oldid |
24 | 24 | |
25 | | - public function initialize() { |
| 25 | + protected function initialize() { |
26 | 26 | foreach ( FlaggedRevs::getTags() as $tag ) { |
27 | 27 | $this->dims[$tag] = 0; // default to "inadequate" |
28 | 28 | } |
— | — | @@ -122,39 +122,45 @@ |
123 | 123 | $this->trySet( $this->dims[$tag], (int)$value ); |
124 | 124 | } |
125 | 125 | |
| 126 | + /* |
| 127 | + * Check that a target is given (e.g. from GET/POST request) |
| 128 | + * @return mixed (true on success, error string on failure) |
| 129 | + */ |
| 130 | + public function doCheckTargetGiven() { |
| 131 | + if ( is_null( $this->page ) ) { |
| 132 | + return 'review_page_invalid'; |
| 133 | + } |
| 134 | + return true; |
| 135 | + } |
| 136 | + |
126 | 137 | /** |
127 | | - * Load old config and last review status change time |
128 | | - * @return mixed (true on success, error string on target failure) |
| 138 | + * Load any objects after ready() called |
| 139 | + * @return mixed (true on success, error string on failure) |
129 | 140 | */ |
130 | | - public function doLoadOnReady() { |
131 | | - # Get the revision's current flags, if any |
132 | | - $this->oflags = FlaggedRevs::getRevisionTags( $this->page, $this->oldid, FR_MASTER ); |
133 | | - # Set initial value for newLastChangeTime (if unchanged on submit) |
134 | | - $this->newLastChangeTime = $this->lastChangeTime; |
| 141 | + protected function doBuildOnReady() { |
| 142 | + $this->article = FlaggedArticle::getTitleInstance( $this->page ); |
135 | 143 | return true; |
136 | 144 | } |
137 | 145 | |
138 | 146 | /* |
139 | 147 | * Check that the target is valid (e.g. from GET/POST request) |
140 | | - * @param int $flags ON_SUBMISSION (set on submit) |
| 148 | + * @param int $flags FOR_SUBMISSION (set on submit) |
141 | 149 | * @return mixed (true on success, error string on failure) |
142 | 150 | */ |
143 | 151 | protected function doCheckTarget( $flags = 0 ) { |
144 | | - if ( is_null( $this->page ) ) { |
145 | | - return 'review_page_invalid'; |
146 | | - } elseif ( !$this->page->exists() ) { |
| 152 | + $flgs = ( $flags & self::FOR_SUBMISSION ) ? Title::GAID_FOR_UPDATE : 0; |
| 153 | + if ( !$this->page->getArticleId( $flgs ) ) { |
147 | 154 | return 'review_page_notexists'; |
148 | 155 | } |
149 | | - $fa = FlaggedArticle::getTitleInstance( $this->page ); |
150 | | - $flags = ( $flags & self::ON_SUBMISSION ) ? FR_MASTER : 0; |
151 | | - if ( !$fa->isReviewable( $flags ) ) { |
| 156 | + $flgs = ( $flags & self::FOR_SUBMISSION ) ? FR_MASTER : 0; |
| 157 | + if ( !$this->article->isReviewable( $flgs ) ) { |
152 | 158 | return 'review_page_unreviewable'; |
153 | 159 | } |
154 | 160 | return true; |
155 | 161 | } |
156 | 162 | |
157 | 163 | /* |
158 | | - * Verify and clean up parameters (e.g. from POST request). |
| 164 | + * Validate and clean up parameters (e.g. from POST request). |
159 | 165 | * @return mixed (true on success, error string on failure) |
160 | 166 | */ |
161 | 167 | protected function doCheckParameters() { |
— | — | @@ -165,6 +171,10 @@ |
166 | 172 | if ( $this->getAction() === null ) { |
167 | 173 | return 'review_param_missing'; // user didn't say |
168 | 174 | } |
| 175 | + # Get the revision's current flags, if any |
| 176 | + $this->oflags = FlaggedRevs::getRevisionTags( $this->page, $this->oldid, FR_MASTER ); |
| 177 | + # Set initial value for newLastChangeTime (if unchanged on submit) |
| 178 | + $this->newLastChangeTime = $this->lastChangeTime; |
169 | 179 | # Fill in implicit tag data for binary flag case |
170 | 180 | $iDims = $this->implicitDims(); |
171 | 181 | if ( $iDims ) { |
Index: trunk/extensions/FlaggedRevs/business/PageStabilityForm.php |
— | — | @@ -4,15 +4,15 @@ |
5 | 5 | */ |
6 | 6 | abstract class PageStabilityForm extends FRGenericSubmitForm { |
7 | 7 | /* Form parameters which can be user given */ |
8 | | - protected $page = false; # Target page obj |
9 | | - protected $watchThis = null; # Watch checkbox |
10 | | - protected $reviewThis = null; # Auto-review option... |
11 | | - protected $reasonExtra = ''; # Custom/extra reason |
12 | | - protected $reasonSelection = ''; # Reason dropdown key |
13 | | - protected $expiryCustom = ''; # Custom expiry |
14 | | - protected $expirySelection = ''; # Expiry dropdown key |
15 | | - protected $override = -1; # Default version |
16 | | - protected $autoreview = ''; # Autoreview restrictions... |
| 8 | + protected $page = false; # Target page obj |
| 9 | + protected $watchThis = null; # Watch checkbox |
| 10 | + protected $reviewThis = null; # Auto-review option... |
| 11 | + protected $reasonExtra = ''; # Custom/extra reason |
| 12 | + protected $reasonSelection = ''; # Reason dropdown key |
| 13 | + protected $expiryCustom = ''; # Custom expiry |
| 14 | + protected $expirySelection = ''; # Expiry dropdown key |
| 15 | + protected $override = -1; # Default version |
| 16 | + protected $autoreview = ''; # Autoreview restrictions... |
17 | 17 | |
18 | 18 | protected $oldConfig = array(); # Old page config |
19 | 19 | |
— | — | @@ -78,8 +78,9 @@ |
79 | 79 | * @return 14-char timestamp or "infinity", or false if the input was invalid |
80 | 80 | */ |
81 | 81 | public function getExpiry() { |
| 82 | + $oldConfig = $this->getOldConfig(); |
82 | 83 | if ( $this->expirySelection == 'existing' ) { |
83 | | - return $this->oldConfig['expiry']; |
| 84 | + return $oldConfig['expiry']; |
84 | 85 | } elseif ( $this->expirySelection == 'othertime' ) { |
85 | 86 | $value = $this->expiryCustom; |
86 | 87 | } else { |
— | — | @@ -119,30 +120,38 @@ |
120 | 121 | } |
121 | 122 | |
122 | 123 | /* |
123 | | - * Preload existing page settings (e.g. from GET request). |
| 124 | + * Check that a target is given (e.g. from GET/POST request) |
124 | 125 | * @return mixed (true on success, error string on failure) |
125 | 126 | */ |
126 | | - public function doPreloadParameters() { |
127 | | - if ( $this->oldConfig['expiry'] == Block::infinity() ) { |
128 | | - $this->expirySelection = 'infinite'; // no settings set OR indefinite |
129 | | - } else { |
130 | | - $this->expirySelection = 'existing'; // settings set and NOT indefinite |
| 127 | + protected function doCheckTargetGiven() { |
| 128 | + if ( is_null( $this->page ) ) { |
| 129 | + return 'stabilize_page_invalid'; |
131 | 130 | } |
132 | | - return $this->reallyDoPreloadParameters(); // load the params... |
| 131 | + return true; |
133 | 132 | } |
134 | 133 | |
135 | 134 | /* |
| 135 | + * Check that the target page is valid |
| 136 | + * @param int $flags FOR_SUBMISSION (set on submit) |
136 | 137 | * @return mixed (true on success, error string on failure) |
137 | | - */ |
138 | | - protected function reallyDoPreloadParameters() { |
| 138 | + */ |
| 139 | + protected function doCheckTarget( $flags = 0 ) { |
| 140 | + $flgs = ( $flags & self::FOR_SUBMISSION ) ? Title::GAID_FOR_UPDATE : 0; |
| 141 | + if ( !$this->page->getArticleId( $flgs ) ) { |
| 142 | + return 'stabilize_page_notexists'; |
| 143 | + } elseif ( !FlaggedRevs::inReviewNamespace( $this->page ) ) { |
| 144 | + return 'stabilize_page_unreviewable'; |
| 145 | + } |
139 | 146 | return true; |
140 | 147 | } |
141 | 148 | |
142 | 149 | /* |
143 | | - * Verify and clean up parameters (e.g. from POST request). |
| 150 | + * Verify and clean up parameters (e.g. from POST request) |
144 | 151 | * @return mixed (true on success, error string on failure) |
145 | 152 | */ |
146 | 153 | protected function doCheckParameters() { |
| 154 | + # Load old config settings from the master |
| 155 | + $this->oldConfig = FlaggedPageConfig::getStabilitySettings( $this->page, FR_MASTER ); |
147 | 156 | if ( $this->expiryCustom != '' ) { |
148 | 157 | // Custom expiry takes precedence |
149 | 158 | $this->expirySelection = 'othertime'; |
— | — | @@ -159,28 +168,6 @@ |
160 | 169 | } |
161 | 170 | |
162 | 171 | /* |
163 | | - * Check that the target page is valid |
164 | | - * @param int $flags ON_SUBMISSION (set on submit) |
165 | | - * @return mixed (true on success, error string on failure) |
166 | | - */ |
167 | | - protected function doCheckTarget( $flags = 0 ) { |
168 | | - if ( is_null( $this->page ) ) { |
169 | | - return 'stabilize_page_invalid'; |
170 | | - } elseif ( !$this->page->exists() ) { |
171 | | - return 'stabilize_page_notexists'; |
172 | | - } elseif ( !FlaggedRevs::inReviewNamespace( $this->page ) ) { |
173 | | - return 'stabilize_page_unreviewable'; |
174 | | - } |
175 | | - return true; |
176 | | - } |
177 | | - |
178 | | - protected function doLoadOnReady() { |
179 | | - # Get the current page config |
180 | | - $this->oldConfig = FlaggedPageConfig::getStabilitySettings( $this->page, FR_MASTER ); |
181 | | - return true; |
182 | | - } |
183 | | - |
184 | | - /* |
185 | 172 | * Can the user change the settings for this page? |
186 | 173 | * Note: if the current autoreview restriction is too high for this user |
187 | 174 | * then this will return false. Useful for form selectors. |
— | — | @@ -195,6 +182,27 @@ |
196 | 183 | ); |
197 | 184 | } |
198 | 185 | |
| 186 | + /* |
| 187 | + * Preload existing page settings (e.g. from GET request). |
| 188 | + * @return mixed (true on success, error string on failure) |
| 189 | + */ |
| 190 | + public function doPreloadParameters() { |
| 191 | + $oldConfig = $this->getOldConfig(); |
| 192 | + if ( $oldConfig['expiry'] == Block::infinity() ) { |
| 193 | + $this->expirySelection = 'infinite'; // no settings set OR indefinite |
| 194 | + } else { |
| 195 | + $this->expirySelection = 'existing'; // settings set and NOT indefinite |
| 196 | + } |
| 197 | + return $this->reallyDoPreloadParameters(); // load the params... |
| 198 | + } |
| 199 | + |
| 200 | + /* |
| 201 | + * @return mixed (true on success, error string on failure) |
| 202 | + */ |
| 203 | + protected function reallyDoPreloadParameters() { |
| 204 | + return true; |
| 205 | + } |
| 206 | + |
199 | 207 | /** |
200 | 208 | * Submit the form parameters for the page config to the DB. |
201 | 209 | * |
— | — | @@ -309,9 +317,12 @@ |
310 | 318 | * @return Array |
311 | 319 | */ |
312 | 320 | public function getOldConfig() { |
313 | | - if ( !$this->inputLock ) { |
| 321 | + if ( $this->getState() == self::FORM_UNREADY ) { |
314 | 322 | throw new MWException( __CLASS__ . " input fields not set yet.\n"); |
315 | 323 | } |
| 324 | + if ( $this->oldConfig === array() && $this->page ) { |
| 325 | + $this->oldConfig = FlaggedPageConfig::getStabilitySettings( $this->page ); |
| 326 | + } |
316 | 327 | return $this->oldConfig; |
317 | 328 | } |
318 | 329 | |
— | — | @@ -360,8 +371,9 @@ |
361 | 372 | } |
362 | 373 | |
363 | 374 | protected function reallyDoPreloadParameters() { |
364 | | - $this->override = $this->oldConfig['override']; |
365 | | - $this->autoreview = $this->oldConfig['autoreview']; |
| 375 | + $oldConfig = $this->getOldConfig(); |
| 376 | + $this->override = $oldConfig['override']; |
| 377 | + $this->autoreview = $oldConfig['autoreview']; |
366 | 378 | $this->watchThis = $this->page->userIsWatching(); |
367 | 379 | return true; |
368 | 380 | } |
— | — | @@ -384,7 +396,8 @@ |
385 | 397 | // Assumes $wgFlaggedRevsProtection is on |
386 | 398 | class PageStabilityProtectForm extends PageStabilityForm { |
387 | 399 | protected function reallyDoPreloadParameters() { |
388 | | - $this->autoreview = $this->oldConfig['autoreview']; // protect level |
| 400 | + $oldConfig = $this->getOldConfig(); |
| 401 | + $this->autoreview = $oldConfig['autoreview']; // protect level |
389 | 402 | $this->watchThis = $this->page->userIsWatching(); |
390 | 403 | return true; |
391 | 404 | } |
— | — | @@ -392,9 +405,10 @@ |
393 | 406 | protected function reallyDoCheckParameters() { |
394 | 407 | # WMF temp hack...protection limit quota |
395 | 408 | global $wgFlaggedRevsProtectQuota; |
| 409 | + $oldConfig = $this->getOldConfig(); |
396 | 410 | if ( isset( $wgFlaggedRevsProtectQuota ) // quota exists |
397 | 411 | && $this->autoreview != '' // and we are protecting |
398 | | - && FlaggedPageConfig::getProtectionLevel( $this->oldConfig ) == 'none' ) // unprotected |
| 412 | + && FlaggedPageConfig::getProtectionLevel( $oldConfig ) == 'none' ) // unprotected |
399 | 413 | { |
400 | 414 | $dbw = wfGetDB( DB_MASTER ); |
401 | 415 | $count = $dbw->selectField( 'flaggedpage_config', 'COUNT(*)', '', __METHOD__ ); |
— | — | @@ -403,7 +417,7 @@ |
404 | 418 | } |
405 | 419 | } |
406 | 420 | # Autoreview only when protecting currently unprotected pages |
407 | | - $this->reviewThis = ( FlaggedPageConfig::getProtectionLevel( $this->oldConfig ) == 'none' ); |
| 421 | + $this->reviewThis = ( FlaggedPageConfig::getProtectionLevel( $oldConfig ) == 'none' ); |
408 | 422 | # Autoreview restriction => use stable |
409 | 423 | # No autoreview restriction => site default |
410 | 424 | $this->override = ( $this->autoreview != '' ) |
Index: trunk/extensions/FlaggedRevs/presentation/specialpages/actions/Stabilization_body.php |
— | — | @@ -32,15 +32,17 @@ |
33 | 33 | } |
34 | 34 | # Set page title |
35 | 35 | $this->setHeaders(); |
36 | | - |
37 | | - $this->form = new PageStabilityGeneralForm( $wgUser ); |
38 | | - $form = $this->form; // convenience |
| 36 | + |
39 | 37 | # Target page |
40 | 38 | $title = Title::newFromURL( $wgRequest->getVal( 'page', $par ) ); |
41 | 39 | if ( !$title ) { |
42 | 40 | $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); |
43 | 41 | return; |
44 | 42 | } |
| 43 | + |
| 44 | + $this->form = new PageStabilityGeneralForm( $wgUser ); |
| 45 | + $form = $this->form; // convenience |
| 46 | + |
45 | 47 | $form->setPage( $title ); |
46 | 48 | # Watch checkbox |
47 | 49 | $form->setWatchThis( (bool)$wgRequest->getCheck( 'wpWatchthis' ) ); |
— | — | @@ -56,15 +58,14 @@ |
57 | 59 | $form->setOverride( (int)$wgRequest->getBool( 'wpStableconfig-override' ) ); |
58 | 60 | # Get autoreview restrictions... |
59 | 61 | $form->setAutoreview( $wgRequest->getVal( 'mwProtect-level-autoreview' ) ); |
| 62 | + $form->ready(); // params all set |
60 | 63 | |
61 | | - $status = $form->ready(); // params all set |
| 64 | + $status = $form->checkTarget(); |
62 | 65 | if ( $status === 'stabilize_page_notexists' ) { |
63 | | - $wgOut->addWikiText( |
64 | | - wfMsg( 'stabilization-notexists', $title->getPrefixedText() ) ); |
| 66 | + $wgOut->addWikiMsg( 'stabilization-notexists', $title->getPrefixedText() ); |
65 | 67 | return; |
66 | 68 | } elseif ( $status === 'stabilize_page_unreviewable' ) { |
67 | | - $wgOut->addWikiText( |
68 | | - wfMsg( 'stabilization-notcontent', $title->getPrefixedText() ) ); |
| 69 | + $wgOut->addWikiMsg( 'stabilization-notcontent', $title->getPrefixedText() ); |
69 | 70 | return; |
70 | 71 | } |
71 | 72 | # Form POST request... |
Index: trunk/extensions/FlaggedRevs/presentation/specialpages/actions/RevisionReview_body.php |
— | — | @@ -6,7 +6,9 @@ |
7 | 7 | var $skin; // FIXME: with RevDel_RevisionList stuff |
8 | 8 | |
9 | 9 | public function __construct() { |
| 10 | + global $wgUser; |
10 | 11 | parent::__construct( 'RevisionReview', 'review' ); |
| 12 | + $this->skin = $wgUser->getSkin(); |
11 | 13 | } |
12 | 14 | |
13 | 15 | public function execute( $par ) { |
— | — | @@ -27,16 +29,25 @@ |
28 | 30 | } |
29 | 31 | $this->setHeaders(); |
30 | 32 | |
31 | | - $this->skin = $wgUser->getSkin(); |
32 | | - $this->form = new RevisionReviewForm( $wgUser ); |
33 | 33 | # Our target page |
34 | 34 | $this->page = Title::newFromURL( $wgRequest->getVal( 'target' ) ); |
35 | 35 | if ( !$this->page ) { |
36 | 36 | $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); |
37 | 37 | return; |
38 | 38 | } |
| 39 | + # Basic page permission checks... |
| 40 | + $permErrors = $this->page->getUserPermissionsErrors( 'review', $wgUser, false ); |
| 41 | + if ( !$permErrors ) { |
| 42 | + $permErrors = $this->page->getUserPermissionsErrors( 'edit', $wgUser, false ); |
| 43 | + } |
| 44 | + if ( $permErrors ) { |
| 45 | + $wgOut->showPermissionsErrorPage( $permErrors, 'review' ); |
| 46 | + return; |
| 47 | + } |
39 | 48 | |
| 49 | + $this->form = new RevisionReviewForm( $wgUser ); |
40 | 50 | $form = $this->form; // convenience |
| 51 | + |
41 | 52 | $form->setPage( $this->page ); |
42 | 53 | # Param for sites with binary flagging |
43 | 54 | $form->setApprove( $wgRequest->getCheck( 'wpApprove' ) ); |
— | — | @@ -61,26 +72,8 @@ |
62 | 73 | } |
63 | 74 | # Log comment |
64 | 75 | $form->setComment( $wgRequest->getText( 'wpReason' ) ); |
| 76 | + $form->ready(); |
65 | 77 | |
66 | | - $status = $form->ready(); |
67 | | - # Page must exist and be in reviewable namespace |
68 | | - if ( $status === 'review_page_unreviewable' ) { |
69 | | - $wgOut->addWikiText( wfMsg( 'revreview-main' ) ); |
70 | | - return; |
71 | | - } elseif ( $status === 'review_page_notexists' ) { |
72 | | - $wgOut->showErrorPage( 'internalerror', 'nopagetext' ); |
73 | | - return; |
74 | | - } |
75 | | - # Basic page permission checks... |
76 | | - $permErrors = $this->page->getUserPermissionsErrors( 'review', $wgUser, false ); |
77 | | - if ( !$permErrors ) { |
78 | | - $permErrors = $this->page->getUserPermissionsErrors( 'edit', $wgUser, false ); |
79 | | - } |
80 | | - if ( $permErrors ) { |
81 | | - $wgOut->showPermissionsErrorPage( $permErrors, 'review' ); |
82 | | - return; |
83 | | - } |
84 | | - |
85 | 78 | # Review the edit if requested (POST)... |
86 | 79 | if ( $wgRequest->wasPosted() ) { |
87 | 80 | // Check the edit token... |
— | — | @@ -98,7 +91,13 @@ |
99 | 92 | $wgOut->addHtml( $html ); |
100 | 93 | // Failure... |
101 | 94 | } else { |
102 | | - if ( $status === 'review_bad_oldid' ) { |
| 95 | + if ( $status === 'review_page_unreviewable' ) { |
| 96 | + $wgOut->addWikiText( wfMsg( 'revreview-main' ) ); |
| 97 | + return; |
| 98 | + } elseif ( $status === 'review_page_notexists' ) { |
| 99 | + $wgOut->showErrorPage( 'internalerror', 'nopagetext' ); |
| 100 | + return; |
| 101 | + } elseif ( $status === 'review_bad_oldid' ) { |
103 | 102 | $wgOut->showErrorPage( 'internalerror', 'revreview-revnotfound' ); |
104 | 103 | } else { |
105 | 104 | $wgOut->showErrorPage( 'internalerror', $status ); |
— | — | @@ -120,7 +119,13 @@ |
121 | 120 | } |
122 | 121 | // Failure... |
123 | 122 | } else { |
124 | | - if ( $status === 'review_denied' ) { |
| 123 | + if ( $status === 'review_page_unreviewable' ) { |
| 124 | + $wgOut->addWikiText( wfMsg( 'revreview-main' ) ); |
| 125 | + return; |
| 126 | + } elseif ( $status === 'review_page_notexists' ) { |
| 127 | + $wgOut->showErrorPage( 'internalerror', 'nopagetext' ); |
| 128 | + return; |
| 129 | + } elseif ( $status === 'review_denied' ) { |
125 | 130 | $wgOut->permissionRequired( 'badaccess-group0' ); // protected? |
126 | 131 | } elseif ( $status === 'review_bad_key' ) { |
127 | 132 | $wgOut->permissionRequired( 'badaccess-group0' ); // fiddling |
— | — | @@ -263,12 +268,6 @@ |
264 | 269 | $form->setPage( $title ); |
265 | 270 | |
266 | 271 | $status = $form->ready(); // all params loaded |
267 | | - # Page must exist and be in reviewable namespace |
268 | | - if ( $status === 'review_page_unreviewable' ) { |
269 | | - return '<err#>' . wfMsgExt( 'revreview-main', 'parseinline' ); |
270 | | - } elseif ( $status === 'review_page_notexists' ) { |
271 | | - return '<err#>' . wfMsgExt( 'nopagetext', 'parseinline' ); |
272 | | - } |
273 | 272 | # Check session via user token |
274 | 273 | if ( !$wgUser->matchEditToken( $editToken ) ) { |
275 | 274 | return '<err#>' . wfMsgExt( 'sessionfailure', 'parseinline' ); |
Index: trunk/extensions/FlaggedRevs/presentation/RejectConfirmationFormGUI.php |
— | — | @@ -17,6 +17,10 @@ |
18 | 18 | */ |
19 | 19 | public function getHtml() { |
20 | 20 | global $wgLang, $wgContLang; |
| 21 | + $status = $this->form->checkTarget(); |
| 22 | + if ( $status !== true ) { |
| 23 | + return array( '', $status ); // not a reviewable existing page |
| 24 | + } |
21 | 25 | $oldRev = $this->oldRev; // convenience |
22 | 26 | $newRev = $this->newRev; // convenience |
23 | 27 | # Do not mess with archived/deleted revisions |