r46283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46282‎ | r46283 | r46284 >
Date:20:48, 26 January 2009
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Fixed watchlist check
* Improved expiry handling
* Added 'pristine' precedence setting back
* Added reason/time dropdown
* Expanded comment width a tad
* Removed some useless css classes
* Renamed some url parameters for consistency
Modified paths:
  • /trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php
@@ -27,8 +27,10 @@
2828 No configuration is possible.',
2929 'stabilization-notcontent' => 'The page "[[:$1|$1]]" cannot be reviewed.
3030 No configuration is possible.',
31 - 'stabilization-comment' => 'Comment:',
 31+ 'stabilization-comment' => 'Reason:',
 32+ 'stabilization-otherreason' => 'Other reason',
3233 'stabilization-expiry' => 'Expires:',
 34+ 'stabilization-othertime' => 'Other time',
3335 'stabilization-sel-short' => 'Precedence',
3436 'stabilization-sel-short-0' => 'Quality',
3537 'stabilization-sel-short-1' => 'None',
Index: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
@@ -14,11 +14,12 @@
1515
1616 public function execute( $par ) {
1717 global $wgRequest, $wgUser, $wgOut;
18 -
 18+ # Check user token
1919 $confirm = $wgRequest->wasPosted() &&
2020 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
21 -
 21+ # Allow unprivileged users to at least view the settings
2222 $this->isAllowed = $wgUser->isAllowed( 'stablesettings' );
 23+ $this->disabledAttrib = !$this->isAllowed ? array( 'disabled' => 'disabled' ) : array();
2324 # Let anyone view, but not submit...
2425 if( $wgRequest->wasPosted() ) {
2526 if( $wgUser->isBlocked( !$confirm ) ) {
@@ -55,20 +56,29 @@
5657 # Watch checkbox
5758 $this->watchThis = $wgRequest->getCheck( 'wpWatchthis' );
5859 # Reason
59 - $this->comment = $wgRequest->getVal( 'wpReason' );
 60+ $this->reason = $wgRequest->getVal( 'wpReason' );
 61+ $this->reasonSelection = $wgRequest->getText( 'wpReasonSelection' );
6062 # 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
6570 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" );
7177 }
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 ) ) {
7383 $isValid = false;
7484 }
7585 }
@@ -81,74 +91,132 @@
8292 }
8393
8494 protected function showSettings( $err = null ) {
85 - global $wgOut, $wgTitle, $wgUser;
86 -
87 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
 95+ global $wgOut, $wgLang, $wgUser;
8896 # Must be a content page
8997 if( !FlaggedRevs::isPageReviewable( $this->page ) ) {
9098 $wgOut->addHTML( wfMsgExt('stableversions-none', array('parse'), $this->page->getPrefixedText() ) );
9199 return;
92100 }
93 -
94 - if ( "" != $err ) {
 101+ # Add any error messages
 102+ if( "" != $err ) {
95103 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
96104 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
97105 }
98 -
 106+ # Add header text
99107 if( !$this->isAllowed ) {
100108 $form = wfMsgExt( 'stabilization-perm', array('parse'), $this->page->getPrefixedText() );
101 - $off = array('disabled' => 'disabled');
102109 } else {
103110 $form = wfMsgExt( 'stabilization-text', array('parse'), $this->page->getPrefixedText() );
104 - $off = array();
105111 }
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
107147 $special = SpecialPage::getTitleFor( 'Stabilization' );
108148 $form .= Xml::openElement( 'form', array( 'name' => 'stabilization',
109149 'action' => $special->getLocalUrl(), 'method' => 'post' ) ) .
110150 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" .
115155 Xml::closeElement( 'fieldset' ) .
116156
117157 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" .
126164 Xml::closeElement( 'fieldset' ) .
127165
128166 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
139199 if( $this->isAllowed ) {
140 - $watchLabel = wfMsgExt('watchthis', array('parseinline'));
 200+ $watchLabel = wfMsgExt( 'watchthis', array('parseinline') );
141201 $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis');
142 - $watchChecked = ( $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() );
 202+ $watchChecked = ( $wgUser->getOption( 'watchdefault' ) || $this->page->userIsWatching() );
143203
144204 $form .= '<tr>
145205 <td class="mw-label">' .
146206 Xml::label( wfMsg( 'stabilization-comment' ), 'wpReason' ) .
147207 '</td>
148208 <td class="mw-input">' .
149 - Xml::input( 'wpReason', 60, $this->comment, array( 'id' => 'wpReason' ) ) .
 209+ Xml::input( 'wpReason', 70, $this->reason, array( 'id' => 'wpReason' ) ) .
150210 '</td>
151211 </tr>
152212 <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>
153221 <td></td>
154222 <td class="mw-input">' .
155223 Xml::check( 'wpWatchthis', $watchChecked, $watchAttribs ) .
@@ -160,18 +228,15 @@
161229 <td class="mw-submit">' .
162230 Xml::submitButton( wfMsg( 'stabilization-submit' ) ) .
163231 '</td>
164 - </tr>' .
165 - Xml::hidden( 'title', $wgTitle->getPrefixedDBKey() ) .
 232+ </tr>' . Xml::closeElement( 'table' ) .
 233+ Xml::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) .
166234 Xml::hidden( 'page', $this->page->getPrefixedText() ) .
167235 Xml::hidden( 'wpEditToken', $wgUser->editToken() );
168236 } else {
169 - $form .= Xml::openElement( 'table', array( 'class' => 'mw-fr-stabilization' ) );
 237+ $form .= Xml::closeElement( 'table' );
170238 }
 239+ $form .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' );
171240
172 - $form .= Xml::closeElement( 'table' ) .
173 - Xml::closeElement( 'fieldset' ) .
174 - Xml::closeElement( 'form' );
175 -
176241 $wgOut->addHTML( $form );
177242
178243 $wgOut->addHTML( Xml::element( 'h2', NULL, htmlspecialchars( LogPage::logName( 'stable' ) ) ) );
@@ -179,26 +244,29 @@
180245 }
181246
182247 protected function submit() {
183 - global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride, $wgFlaggedRevsPrecedence;
 248+ global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride;
184249
185250 $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+ }
186255 # Take this opportunity to purge out expired configurations
187256 FlaggedRevs::purgeExpiredConfigurations();
188257
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' ) {
190261 $expiry = Block::infinity();
191262 } else {
192263 # Convert GNU-style date, on error returns -1 for PHP <5.1 and false for PHP >=5.1
193264 $expiry = strtotime( $this->expiry );
194 -
195265 if( $expiry < 0 || $expiry === false ) {
196266 $this->showSettings( wfMsg( 'stabilize_expiry_invalid' ) );
197267 return false;
198268 }
199 -
200269 $expiry = wfTimestamp( TS_MW, $expiry );
201 -
202 - if ( $expiry < wfTimestampNow() ) {
 270+ if( $expiry < wfTimestampNow() ) {
203271 $this->showSettings( wfMsg( 'stabilize_expiry_old' ) );
204272 return false;
205273 }
@@ -211,8 +279,7 @@
212280 array( 'fpc_page_id' => $this->page->getArticleID() ),
213281 __METHOD__ );
214282 # 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 ) {
217284 $dbw->delete( 'flaggedpage_config',
218285 array( 'fpc_page_id' => $this->page->getArticleID() ),
219286 __METHOD__ );
@@ -247,7 +314,7 @@
248315 $reason = '';
249316 # Append comment with settings (other than for resets)
250317 if( !$reset ) {
251 - $reason = $this->comment ? "{$this->comment} $settings" : "$settings";
 318+ $reason = $this->reason ? "{$this->reason} $settings" : "$settings";
252319
253320 $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
254321 if( $encodedExpiry != 'infinity' ) {

Comments

#Comment by Aaron Schulz (talk | contribs)   21:07, 26 January 2009

JS improvements in r46286

#Comment by Aaron Schulz (talk | contribs)   03:48, 27 January 2009

Expiry fix in r46318

Status & tagging log