r40555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40554‎ | r40555 | r40556 >
Date:23:20, 6 September 2008
Author:aaron
Status:old
Tags:
Comment:
* Add time/reason dropdown for protect form (bug 10799)
* Shorten message
Modified paths:
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1524,6 +1524,9 @@
15251525 'protect-expiring',
15261526 'protect-cascade',
15271527 'protect-cantedit',
 1528+ 'protect-otheroption',
 1529+ 'protect-otherreason',
 1530+ 'protect-dropdown',
15281531 'restriction-type',
15291532 'restriction-level',
15301533 'minimum-size',
Index: trunk/phase3/includes/ProtectionForm.php
@@ -65,8 +65,14 @@
6666 : array();
6767
6868 $this->mReason = $wgRequest->getText( 'mwProtect-reason' );
 69+ $this->mReasonList = $wgRequest->getText( 'wpProtectReasonList' );
6970 $this->mCascade = $wgRequest->getBool( 'mwProtect-cascade', $this->mCascade );
70 - $this->mExpiry = $wgRequest->getText( 'mwProtect-expiry', $this->mExpiry );
 71+ // Let dropdown have 'infinite' for unprotected pages
 72+ if( !($expiry = $wgRequest->getText( 'mwProtect-expiry' )) && $this->mExpiry != 'infinite' ) {
 73+ $expiry = $this->mExpiry;
 74+ }
 75+ $this->mExpiry = $expiry;
 76+ $this->mExpiryList = $wgRequest->getText( 'wpProtectExpiryList', $this->mExpiry ? '' : 'infinite' );
7177
7278 foreach( $this->mApplicableTypes as $action ) {
7379 $val = $wgRequest->getVal( "mwProtect-level-$action" );
@@ -150,20 +156,29 @@
151157
152158 function save() {
153159 global $wgRequest, $wgUser, $wgOut;
154 -
155 - if( $this->disabled ) {
 160+ # Permission check!
 161+ if ( $this->disabled ) {
156162 $this->show();
157163 return false;
158164 }
159165
160166 $token = $wgRequest->getVal( 'wpEditToken' );
161 - if( !$wgUser->matchEditToken( $token ) ) {
 167+ if ( !$wgUser->matchEditToken( $token ) ) {
162168 $this->show( wfMsg( 'sessionfailure' ) );
163169 return false;
164170 }
165 -
 171+
 172+ # Create reason string. Use list and/or custom string.
 173+ $reasonstr = $this->mReasonList;
 174+ if ( $reasonstr != 'other' && $this->mReason != '' ) {
 175+ // Entry from drop down menu + additional comment
 176+ $reasonstr .= ': ' . $this->mReason;
 177+ } elseif ( $reasonstr == 'other' ) {
 178+ $reasonstr = $this->mReason;
 179+ }
 180+ # Custom expiry takes precedence
166181 if ( strlen( $this->mExpiry ) == 0 ) {
167 - $this->mExpiry = 'infinite';
 182+ $this->mExpiry = strlen($this->mExpiryList) ? $this->mExpiryList : 'infinite';
168183 }
169184
170185 if ( $this->mExpiry == 'infinite' || $this->mExpiry == 'indefinite' ) {
@@ -185,7 +200,6 @@
186201 $this->show( wfMsg( 'protect_expiry_old' ) );
187202 return false;
188203 }
189 -
190204 }
191205
192206 # They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
@@ -199,9 +213,9 @@
200214 $this->mCascade = false;
201215
202216 if ($this->mTitle->exists()) {
203 - $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry );
 217+ $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $reasonstr, $this->mCascade, $expiry );
204218 } else {
205 - $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $this->mReason, $expiry );
 219+ $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $reasonstr, $expiry );
206220 }
207221
208222 if( !$ok ) {
@@ -225,13 +239,20 @@
226240 function buildForm() {
227241 global $wgUser;
228242
 243+ $mProtectexpiry = Xml::label( wfMsg( 'protectexpiry' ), 'mwProtectExpiryList' );
 244+ $mProtectother = Xml::label( wfMsg( 'protect-otheroption' ), 'expires' );
 245+ $mProtectreasonother = Xml::label( wfMsg( 'protectcomment' ), 'wpProtectReasonList' );
 246+ $mProtectreason = Xml::label( wfMsg( 'protect-otherreason' ), 'mwProtect-reason' );
 247+
229248 $out = '';
230249 if( !$this->disabled ) {
231250 $out .= $this->buildScript();
232251 // The submission needs to reenable the move permission selector
233252 // if it's in locked mode, or some browsers won't submit the data.
234 - $out .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalUrl( 'action=protect' ), 'id' => 'mw-Protect-Form', 'onsubmit' => 'protectEnable(true)' ) ) .
235 - Xml::hidden( 'wpEditToken',$wgUser->editToken() );
 253+ $out .= Xml::openElement( 'form', array( 'method' => 'post',
 254+ 'action' => $this->mTitle->getLocalUrl( 'action=protect' ),
 255+ 'id' => 'mw-Protect-Form', 'onsubmit' => 'protectEnable(true)' ) );
 256+ $out .= Xml::hidden( 'wpEditToken',$wgUser->editToken() );
236257 }
237258
238259 $out .= Xml::openElement( 'fieldset' ) .
@@ -255,9 +276,27 @@
256277 "</td>";
257278 }
258279 $out .= "</tr>\n";
 280+
 281+ $scExpiryOptions = wfMsgForContent( 'ipboptions' ); // FIXME: use its own message
259282
 283+ $showProtectOptions = ($scExpiryOptions !== '-' && !$this->disabled);
 284+ if( !$showProtectOptions )
 285+ $mProtectother = $mProtectexpiry;
 286+
 287+ $expiryFormOptions = Xml::option( wfMsg( 'protect-otheroption' ), 'wpProtectExpiryList' );
 288+ foreach( explode(',', $scExpiryOptions) as $option ) {
 289+ if ( strpos($option, ":") === false ) $option = "$option:$option";
 290+ list($show, $value) = explode(":", $option);
 291+ $show = htmlspecialchars($show);
 292+ $value = htmlspecialchars($value);
 293+ $expiryFormOptions .= Xml::option( $show, $value, $this->mExpiryList === $value ? true : false ) . "\n";
 294+ }
 295+
 296+ $reasonDropDown = Xml::listDropDown( 'wpProtectReasonList',
 297+ wfMsgForContent( 'protect-dropdown' ),
 298+ wfMsgForContent( 'protect-otherreason' ), '', 'mwProtect-reason', 4 );
 299+
260300 // JavaScript will add another row with a value-chaining checkbox
261 -
262301 $out .= Xml::closeElement( 'tbody' ) .
263302 Xml::closeElement( 'table' ) .
264303 Xml::openElement( 'table', array( 'id' => 'mw-protect-table2' ) ) .
@@ -267,29 +306,57 @@
268307 $out .= '<tr>
269308 <td></td>
270309 <td class="mw-input">' .
271 - Xml::checkLabel( wfMsg( 'protect-cascade' ), 'mwProtect-cascade', 'mwProtect-cascade', $this->mCascade, $this->disabledAttrib ) .
 310+ Xml::checkLabel( wfMsg( 'protect-cascade' ), 'mwProtect-cascade', 'mwProtect-cascade',
 311+ $this->mCascade, $this->disabledAttrib ) .
272312 "</td>
273313 </tr>\n";
274314 }
275 -
 315+ # Add expiry dropdown
 316+ if( $showProtectOptions && !$this->disabled ) {
 317+ $out .= "
 318+ <tr>
 319+ <td class='mw-label'>
 320+ {$mProtectexpiry}
 321+ </td>
 322+ <td class='mw-input'>" .
 323+ Xml::tags( 'select',
 324+ array(
 325+ 'id' => 'mwProtectExpiryList',
 326+ 'name' => 'wpProtectExpiryList',
 327+ 'onchange' => "document.getElementById('expires').value='';",
 328+ 'tabindex' => '2' ) + $this->disabledAttrib,
 329+ $expiryFormOptions ) .
 330+ "</td>
 331+ </tr>";
 332+ }
 333+ # Add custom expiry field
276334 $attribs = array( 'id' => 'expires' ) + $this->disabledAttrib;
277335 $out .= "<tr>
278336 <td class='mw-label'>" .
279 - Xml::label( wfMsgExt( 'protectexpiry', array( 'parseinline' ) ), 'expires' ) .
 337+ $mProtectother .
280338 '</td>
281339 <td class="mw-input">' .
282340 Xml::input( 'mwProtect-expiry', 60, $this->mExpiry, $attribs ) .
283341 '</td>
284342 </tr>';
285 -
 343+ # Add manual and custom reason field/selects
286344 if( !$this->disabled ) {
287 - $id = 'mwProtect-reason';
288 - $out .= "<tr>
289 - <td class='mw-label'>" .
290 - Xml::label( wfMsg( 'protectcomment' ), $id ) .
291 - '</td>
292 - <td class="mw-input">' .
293 - Xml::input( $id, 60, $this->mReason, array( 'type' => 'text', 'id' => $id, 'maxlength' => 255 ) ) .
 345+ $out .= "
 346+ <tr>
 347+ <td class='mw-label'>
 348+ {$mProtectreasonother}
 349+ </td>
 350+ <td class='mw-input'>
 351+ {$reasonDropDown}
 352+ </td>
 353+ </tr>
 354+ <tr>
 355+ <td class='mw-label'>
 356+ {$mProtectreason}
 357+ </td>
 358+ <td class='mw-input'>" .
 359+ Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text',
 360+ 'id' => 'mwProtect-reason', 'maxlength' => 255 ) ) .
294361 "</td>
295362 </tr>
296363 <tr>
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -663,7 +663,7 @@
664664 'deletethispage' => 'Delete this page',
665665 'undelete_short' => 'Undelete {{PLURAL:$1|one edit|$1 edits}}',
666666 'protect' => 'Protect',
667 -'protect_change' => 'change protection',
 667+'protect_change' => 'change',
668668 'protectthispage' => 'Protect this page',
669669 'unprotect' => 'Unprotect',
670670 'unprotectthispage' => 'Unprotect this page',
@@ -2298,6 +2298,13 @@
22992299 'protect-expiring' => 'expires $1 (UTC)',
23002300 'protect-cascade' => 'Protect pages included in this page (cascading protection)',
23012301 'protect-cantedit' => 'You cannot change the protection levels of this page, because you do not have permission to edit it.',
 2302+'protect-otheroption' => 'other',
 2303+'protect-otherreason' => 'other/additional:',
 2304+'protect-dropdown' => '*Common protection reasons
 2305+** Excessive vandalism
 2306+** Excessive spamming
 2307+** Counter-productive edit warring
 2308+** High traffic page',
23022309 'restriction-type' => 'Permission:',
23032310 'restriction-level' => 'Restriction level:',
23042311 'minimum-size' => 'Min size',