Index: trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php |
— | — | @@ -27,8 +27,10 @@ |
28 | 28 | No configuration is possible.', |
29 | 29 | 'stabilization-notcontent' => 'The page "[[:$1|$1]]" cannot be reviewed. |
30 | 30 | No configuration is possible.', |
31 | | - 'stabilization-comment' => 'Comment:', |
| 31 | + 'stabilization-comment' => 'Reason:', |
| 32 | + 'stabilization-otherreason' => 'Other reason', |
32 | 33 | 'stabilization-expiry' => 'Expires:', |
| 34 | + 'stabilization-othertime' => 'Other time', |
33 | 35 | 'stabilization-sel-short' => 'Precedence', |
34 | 36 | 'stabilization-sel-short-0' => 'Quality', |
35 | 37 | 'stabilization-sel-short-1' => 'None', |
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php |
— | — | @@ -14,11 +14,12 @@ |
15 | 15 | |
16 | 16 | public function execute( $par ) { |
17 | 17 | global $wgRequest, $wgUser, $wgOut; |
18 | | - |
| 18 | + # Check user token |
19 | 19 | $confirm = $wgRequest->wasPosted() && |
20 | 20 | $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); |
21 | | - |
| 21 | + # Allow unprivileged users to at least view the settings |
22 | 22 | $this->isAllowed = $wgUser->isAllowed( 'stablesettings' ); |
| 23 | + $this->disabledAttrib = !$this->isAllowed ? array( 'disabled' => 'disabled' ) : array(); |
23 | 24 | # Let anyone view, but not submit... |
24 | 25 | if( $wgRequest->wasPosted() ) { |
25 | 26 | if( $wgUser->isBlocked( !$confirm ) ) { |
— | — | @@ -55,20 +56,29 @@ |
56 | 57 | # Watch checkbox |
57 | 58 | $this->watchThis = $wgRequest->getCheck( 'wpWatchthis' ); |
58 | 59 | # Reason |
59 | | - $this->comment = $wgRequest->getVal( 'wpReason' ); |
| 60 | + $this->reason = $wgRequest->getVal( 'wpReason' ); |
| 61 | + $this->reasonSelection = $wgRequest->getText( 'wpReasonSelection' ); |
60 | 62 | # Get visiblity settings... |
61 | | - $config = FlaggedRevs::getPageVisibilitySettings( $this->page, true ); |
62 | | - $this->select = $config['select']; |
63 | | - $this->override = $config['override']; |
64 | | - $this->expiry = $config['expiry'] !== 'infinity' ? wfTimestamp( TS_RFC2822, $config['expiry'] ) : 'infinite'; |
| 63 | + $this->config = FlaggedRevs::getPageVisibilitySettings( $this->page, true ); |
| 64 | + $this->select = $this->config['select']; |
| 65 | + $this->override = $this->config['override']; |
| 66 | + # Make user readable date for GET requests |
| 67 | + $this->expiry = $this->config['expiry'] !== 'infinity' ? |
| 68 | + wfTimestamp( TS_RFC2822, $this->config['expiry'] ) : 'infinite'; |
| 69 | + # Handle submissions |
65 | 70 | if( $wgRequest->wasPosted() ) { |
66 | | - $this->select = $wgRequest->getInt( 'mwStableconfig-select' ); |
67 | | - $this->override = intval( $wgRequest->getBool( 'mwStableconfig-override' ) ); |
68 | | - $this->expiry = $wgRequest->getText( 'mwStableconfig-expiry' ); |
69 | | - if( strlen( $this->expiry ) == 0 ) { |
70 | | - $this->expiry = 'infinite'; |
| 71 | + $this->select = $wgRequest->getInt( 'wpStableconfig-select' ); |
| 72 | + $this->override = intval( $wgRequest->getBool( 'wpStableconfig-override' ) ); |
| 73 | + // Custom expiry takes precedence |
| 74 | + $this->expiry = $wgRequest->getText( 'wpStableconfig-expiry' ); |
| 75 | + if( strlen($this->expiry) == 0 ) { |
| 76 | + $this->expiry = $wgRequest->getVal( "wpExpirySelection" ); |
71 | 77 | } |
72 | | - if( $this->select && !in_array( $this->select, array(FLAGGED_VIS_NORMAL,FLAGGED_VIS_LATEST) ) ) { |
| 78 | + // Custom reason takes precedence |
| 79 | + $this->reason = strlen($this->reason) ? $this->reason : $this->reasonSelection; |
| 80 | + // Validate precedence setting |
| 81 | + $allowed = array(FLAGGED_VIS_NORMAL,FLAGGED_VIS_LATEST,FLAGGED_VIS_PRISTINE); |
| 82 | + if( $this->select && !in_array( $this->select, $allowed ) ) { |
73 | 83 | $isValid = false; |
74 | 84 | } |
75 | 85 | } |
— | — | @@ -81,74 +91,132 @@ |
82 | 92 | } |
83 | 93 | |
84 | 94 | protected function showSettings( $err = null ) { |
85 | | - global $wgOut, $wgTitle, $wgUser; |
86 | | - |
87 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 95 | + global $wgOut, $wgLang, $wgUser; |
88 | 96 | # Must be a content page |
89 | 97 | if( !FlaggedRevs::isPageReviewable( $this->page ) ) { |
90 | 98 | $wgOut->addHTML( wfMsgExt('stableversions-none', array('parse'), $this->page->getPrefixedText() ) ); |
91 | 99 | return; |
92 | 100 | } |
93 | | - |
94 | | - if ( "" != $err ) { |
| 101 | + # Add any error messages |
| 102 | + if( "" != $err ) { |
95 | 103 | $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
96 | 104 | $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); |
97 | 105 | } |
98 | | - |
| 106 | + # Add header text |
99 | 107 | if( !$this->isAllowed ) { |
100 | 108 | $form = wfMsgExt( 'stabilization-perm', array('parse'), $this->page->getPrefixedText() ); |
101 | | - $off = array('disabled' => 'disabled'); |
102 | 109 | } else { |
103 | 110 | $form = wfMsgExt( 'stabilization-text', array('parse'), $this->page->getPrefixedText() ); |
104 | | - $off = array(); |
105 | 111 | } |
106 | | - |
| 112 | + # Borrow some protection messages for dropdowns |
| 113 | + $reasonDropDown = Xml::listDropDown( 'wpReasonSelection', |
| 114 | + wfMsgForContent( 'protect-dropdown' ), |
| 115 | + wfMsgForContent( 'protect-otherreason-op' ), |
| 116 | + $this->reasonSelection, |
| 117 | + 'mwStabilize-reason', 4 |
| 118 | + ); |
| 119 | + $scExpiryOptions = wfMsgForContent( 'protect-expiry-options' ); |
| 120 | + $showProtectOptions = ($scExpiryOptions !== '-' && $this->isAllowed); |
| 121 | + # Add the current expiry as an option |
| 122 | + $expiryFormOptions = ''; |
| 123 | + if( $this->config['expiry'] && $this->config['expiry'] != 'infinity' ) { |
| 124 | + $timestamp = $wgLang->timeanddate( $this->config['expiry'] ); |
| 125 | + $d = $wgLang->date( $this->config['expiry'] ); |
| 126 | + $t = $wgLang->time( $this->config['expiry'] ); |
| 127 | + $expiryFormOptions .= |
| 128 | + Xml::option( |
| 129 | + wfMsg( 'protect-existing-expiry', $timestamp, $d, $t ), |
| 130 | + 'existing', |
| 131 | + $this->config['expiry'] == 'existing' |
| 132 | + ) . "\n"; |
| 133 | + } |
| 134 | + $expiryFormOptions .= Xml::option( wfMsg( 'protect-othertime-op' ), "othertime" ) . "\n"; |
| 135 | + # Add custom levels |
| 136 | + foreach( explode(',',$scExpiryOptions) as $option ) { |
| 137 | + if( strpos($option,":") === false ) { |
| 138 | + $show = $value = $option; |
| 139 | + } else { |
| 140 | + list($show, $value) = explode(":",$option); |
| 141 | + } |
| 142 | + $show = htmlspecialchars($show); |
| 143 | + $value = htmlspecialchars($value); |
| 144 | + $expiryFormOptions .= Xml::option( $show, $value, $this->config['expiry'] === $value ) . "\n"; |
| 145 | + } |
| 146 | + # Add stable version override and selection options |
107 | 147 | $special = SpecialPage::getTitleFor( 'Stabilization' ); |
108 | 148 | $form .= Xml::openElement( 'form', array( 'name' => 'stabilization', |
109 | 149 | 'action' => $special->getLocalUrl(), 'method' => 'post' ) ) . |
110 | 150 | Xml::fieldset( wfMsg( 'stabilization-def' ), false ) . "\n" . |
111 | | - Xml::radioLabel( wfMsg( 'stabilization-def1' ), 'mwStableconfig-override', 1, |
112 | | - 'default-stable', 1 == $this->override, $off ) . '<br />' . "\n" . |
113 | | - Xml::radioLabel( wfMsg( 'stabilization-def2' ), 'mwStableconfig-override', 0, |
114 | | - 'default-current', 0 == $this->override, $off ) . "\n" . |
| 151 | + Xml::radioLabel( wfMsg( 'stabilization-def1' ), 'wpStableconfig-override', 1, |
| 152 | + 'default-stable', 1 == $this->override, $this->disabledAttrib ) . '<br />' . "\n" . |
| 153 | + Xml::radioLabel( wfMsg( 'stabilization-def2' ), 'wpStableconfig-override', 0, |
| 154 | + 'default-current', 0 == $this->override, $this->disabledAttrib ) . "\n" . |
115 | 155 | Xml::closeElement( 'fieldset' ) . |
116 | 156 | |
117 | 157 | Xml::fieldset( wfMsg( 'stabilization-select' ), false ) . |
118 | | - Xml::radioLabel( wfMsg( 'stabilization-select1' ), 'mwStableconfig-select', FLAGGED_VIS_NORMAL, |
119 | | - 'stable-select1', FLAGGED_VIS_NORMAL == $this->select, $off ) . '<br />' . "\n" . |
120 | | - Xml::radioLabel( wfMsg( 'stabilization-select2' ), 'mwStableconfig-select', FLAGGED_VIS_LATEST, |
121 | | - 'stable-select2', FLAGGED_VIS_LATEST == $this->select, $off ) . '<br />' . "\n" . |
122 | | - /* |
123 | | - Xml::radioLabel( wfMsg( 'stabilization-select3' ), 'mwStableconfig-select', FLAGGED_VIS_PRISTINE, |
124 | | - 'stable-select3', FLAGGED_VIS_PRISTINE == $this->select, $off ) . |
125 | | - */ |
| 158 | + Xml::radioLabel( wfMsg( 'stabilization-select3' ), 'wpStableconfig-select', FLAGGED_VIS_PRISTINE, |
| 159 | + 'stable-select3', FLAGGED_VIS_PRISTINE == $this->select, $this->disabledAttrib ) . '<br />' . "\n" . |
| 160 | + Xml::radioLabel( wfMsg( 'stabilization-select1' ), 'wpStableconfig-select', FLAGGED_VIS_NORMAL, |
| 161 | + 'stable-select1', FLAGGED_VIS_NORMAL == $this->select, $this->disabledAttrib ) . '<br />' . "\n" . |
| 162 | + Xml::radioLabel( wfMsg( 'stabilization-select2' ), 'wpStableconfig-select', FLAGGED_VIS_LATEST, |
| 163 | + 'stable-select2', FLAGGED_VIS_LATEST == $this->select, $this->disabledAttrib ) . '<br />' . "\n" . |
126 | 164 | Xml::closeElement( 'fieldset' ) . |
127 | 165 | |
128 | 166 | Xml::fieldset( wfMsg( 'stabilization-leg' ), false ) . |
129 | | - Xml::openElement( 'table', array( 'class' => 'mw-fr-stabilization-leg' ) ) . |
130 | | - '<tr> |
131 | | - <td class="mw-label">' . |
132 | | - Xml::tags( 'label', array( 'for' => 'expires' ), wfMsgExt( 'stabilization-expiry', array( 'parseinline' ) ) ) . |
133 | | - '</td> |
134 | | - <td class="mw-input">' . |
135 | | - Xml::input( 'mwStableconfig-expiry', 60, $this->expiry, array( 'id' => 'expires' ) + $off ) . |
136 | | - '</td> |
137 | | - </tr>'; |
138 | | - |
| 167 | + Xml::openElement( 'table' ); |
| 168 | + # Add expiry dropdown |
| 169 | + if( $showProtectOptions && $this->isAllowed ) { |
| 170 | + $js = "if(this.value != 'othertime') document.getElementById('mwStabilize-expiry').value=this.value;"; |
| 171 | + $form .= " |
| 172 | + <tr> |
| 173 | + <td class='mw-label'>" . |
| 174 | + Xml::label( wfMsg('stabilization-expiry'), 'mwExpirySelection' ) . |
| 175 | + "</td> |
| 176 | + <td class='mw-input'>" . |
| 177 | + Xml::tags( 'select', |
| 178 | + array( |
| 179 | + 'id' => "mwExpirySelection", |
| 180 | + 'name' => "wpExpirySelection", |
| 181 | + 'onchange' => $js |
| 182 | + ) + $this->disabledAttrib, |
| 183 | + $expiryFormOptions ) . |
| 184 | + "</td> |
| 185 | + </tr>"; |
| 186 | + } |
| 187 | + # Add custom expiry field |
| 188 | + $attribs = array( 'id' => "mwStabilize-expiry" ) + $this->disabledAttrib; |
| 189 | + $form .= " |
| 190 | + <tr> |
| 191 | + <td class='mw-label'>" . |
| 192 | + Xml::label( wfMsg('stabilization-othertime'), 'mwStabilize-expiry' ) . |
| 193 | + '</td> |
| 194 | + <td class="mw-input">' . |
| 195 | + Xml::input( "mwStabilize-expiry", 50, $this->expiry, $attribs ) . |
| 196 | + '</td> |
| 197 | + </tr>'; |
| 198 | + # Add comment input and submit button |
139 | 199 | if( $this->isAllowed ) { |
140 | | - $watchLabel = wfMsgExt('watchthis', array('parseinline')); |
| 200 | + $watchLabel = wfMsgExt( 'watchthis', array('parseinline') ); |
141 | 201 | $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis'); |
142 | | - $watchChecked = ( $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() ); |
| 202 | + $watchChecked = ( $wgUser->getOption( 'watchdefault' ) || $this->page->userIsWatching() ); |
143 | 203 | |
144 | 204 | $form .= '<tr> |
145 | 205 | <td class="mw-label">' . |
146 | 206 | Xml::label( wfMsg( 'stabilization-comment' ), 'wpReason' ) . |
147 | 207 | '</td> |
148 | 208 | <td class="mw-input">' . |
149 | | - Xml::input( 'wpReason', 60, $this->comment, array( 'id' => 'wpReason' ) ) . |
| 209 | + Xml::input( 'wpReason', 70, $this->reason, array( 'id' => 'wpReason' ) ) . |
150 | 210 | '</td> |
151 | 211 | </tr> |
152 | 212 | <tr> |
| 213 | + <td class="mw-label">' . |
| 214 | + xml::label( wfMsg('stabilization-otherreason'), 'wpReasonSelection' ) . |
| 215 | + '</td> |
| 216 | + <td class="mw-input">' . |
| 217 | + $reasonDropDown . |
| 218 | + '</td> |
| 219 | + </tr> |
| 220 | + <tr> |
153 | 221 | <td></td> |
154 | 222 | <td class="mw-input">' . |
155 | 223 | Xml::check( 'wpWatchthis', $watchChecked, $watchAttribs ) . |
— | — | @@ -160,18 +228,15 @@ |
161 | 229 | <td class="mw-submit">' . |
162 | 230 | Xml::submitButton( wfMsg( 'stabilization-submit' ) ) . |
163 | 231 | '</td> |
164 | | - </tr>' . |
165 | | - Xml::hidden( 'title', $wgTitle->getPrefixedDBKey() ) . |
| 232 | + </tr>' . Xml::closeElement( 'table' ) . |
| 233 | + Xml::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . |
166 | 234 | Xml::hidden( 'page', $this->page->getPrefixedText() ) . |
167 | 235 | Xml::hidden( 'wpEditToken', $wgUser->editToken() ); |
168 | 236 | } else { |
169 | | - $form .= Xml::openElement( 'table', array( 'class' => 'mw-fr-stabilization' ) ); |
| 237 | + $form .= Xml::closeElement( 'table' ); |
170 | 238 | } |
| 239 | + $form .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ); |
171 | 240 | |
172 | | - $form .= Xml::closeElement( 'table' ) . |
173 | | - Xml::closeElement( 'fieldset' ) . |
174 | | - Xml::closeElement( 'form' ); |
175 | | - |
176 | 241 | $wgOut->addHTML( $form ); |
177 | 242 | |
178 | 243 | $wgOut->addHTML( Xml::element( 'h2', NULL, htmlspecialchars( LogPage::logName( 'stable' ) ) ) ); |
— | — | @@ -179,26 +244,29 @@ |
180 | 245 | } |
181 | 246 | |
182 | 247 | protected function submit() { |
183 | | - global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride, $wgFlaggedRevsPrecedence; |
| 248 | + global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride; |
184 | 249 | |
185 | 250 | $changed = $reset = false; |
| 251 | + $defaultPrecedence = FlaggedRevs::getPrecedence(); |
| 252 | + if( $this->select == $defaultPrecedence && $this->override == $wgFlaggedRevsOverride ) { |
| 253 | + $reset = true; // we are going back to site defaults |
| 254 | + } |
186 | 255 | # Take this opportunity to purge out expired configurations |
187 | 256 | FlaggedRevs::purgeExpiredConfigurations(); |
188 | 257 | |
189 | | - if( $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) { |
| 258 | + if( $reset ) { |
| 259 | + $expiry = Block::infinity(); // doesn't matter |
| 260 | + } else if( $this->expiry == 'infinite' || $this->expiry == 'indefinite' ) { |
190 | 261 | $expiry = Block::infinity(); |
191 | 262 | } else { |
192 | 263 | # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1 |
193 | 264 | $expiry = strtotime( $this->expiry ); |
194 | | - |
195 | 265 | if( $expiry < 0 || $expiry === false ) { |
196 | 266 | $this->showSettings( wfMsg( 'stabilize_expiry_invalid' ) ); |
197 | 267 | return false; |
198 | 268 | } |
199 | | - |
200 | 269 | $expiry = wfTimestamp( TS_MW, $expiry ); |
201 | | - |
202 | | - if ( $expiry < wfTimestampNow() ) { |
| 270 | + if( $expiry < wfTimestampNow() ) { |
203 | 271 | $this->showSettings( wfMsg( 'stabilize_expiry_old' ) ); |
204 | 272 | return false; |
205 | 273 | } |
— | — | @@ -211,8 +279,7 @@ |
212 | 280 | array( 'fpc_page_id' => $this->page->getArticleID() ), |
213 | 281 | __METHOD__ ); |
214 | 282 | # If setting to site default values, erase the row if there is one... |
215 | | - if( $row && $this->select != $wgFlaggedRevsPrecedence && $this->override == $wgFlaggedRevsOverride ) { |
216 | | - $reset = true; |
| 283 | + if( $row && $reset ) { |
217 | 284 | $dbw->delete( 'flaggedpage_config', |
218 | 285 | array( 'fpc_page_id' => $this->page->getArticleID() ), |
219 | 286 | __METHOD__ ); |
— | — | @@ -247,7 +314,7 @@ |
248 | 315 | $reason = ''; |
249 | 316 | # Append comment with settings (other than for resets) |
250 | 317 | if( !$reset ) { |
251 | | - $reason = $this->comment ? "{$this->comment} $settings" : "$settings"; |
| 318 | + $reason = $this->reason ? "{$this->reason} $settings" : "$settings"; |
252 | 319 | |
253 | 320 | $encodedExpiry = Block::encodeExpiry($expiry, $dbw ); |
254 | 321 | if( $encodedExpiry != 'infinity' ) { |