Revision: 46283
Author:   aaron
Date:     2009-01-26 20:48:04 +0000 (Mon, 26 Jan 2009)

Log Message:
-----------
* 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
    trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php

Modified: trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php
===================================================================
--- trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php        
2009-01-26 20:39:27 UTC (rev 46282)
+++ trunk/extensions/FlaggedRevs/language/Stabilization.i18n.php        
2009-01-26 20:48:04 UTC (rev 46283)
@@ -27,8 +27,10 @@
 No configuration is possible.',
        'stabilization-notcontent' => 'The page "[[:$1|$1]]" cannot be reviewed.
 No configuration is possible.',
-       'stabilization-comment' => 'Comment:',
+       'stabilization-comment' => 'Reason:',
+       'stabilization-otherreason' => 'Other reason',
        'stabilization-expiry' => 'Expires:',
+       'stabilization-othertime' => 'Other time',
        'stabilization-sel-short' => 'Precedence',
        'stabilization-sel-short-0' => 'Quality',
        'stabilization-sel-short-1' => 'None',

Modified: trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php
===================================================================
--- trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php    
2009-01-26 20:39:27 UTC (rev 46282)
+++ trunk/extensions/FlaggedRevs/specialpages/Stabilization_body.php    
2009-01-26 20:48:04 UTC (rev 46283)
@@ -14,11 +14,12 @@
 
        public function execute( $par ) {
                global $wgRequest, $wgUser, $wgOut;
-
+               # Check user token
                $confirm = $wgRequest->wasPosted() &&
                        $wgUser->matchEditToken( $wgRequest->getVal( 
'wpEditToken' ) );
-
+               # Allow unprivileged users to at least view the settings
                $this->isAllowed = $wgUser->isAllowed( 'stablesettings' );
+               $this->disabledAttrib = !$this->isAllowed ? array( 'disabled' 
=> 'disabled' ) : array();
                # Let anyone view, but not submit...
                if( $wgRequest->wasPosted() ) {
                        if( $wgUser->isBlocked( !$confirm ) ) {
@@ -55,20 +56,29 @@
                # Watch checkbox
                $this->watchThis = $wgRequest->getCheck( 'wpWatchthis' );
                # Reason
-               $this->comment = $wgRequest->getVal( 'wpReason' );
+               $this->reason = $wgRequest->getVal( 'wpReason' );
+               $this->reasonSelection = $wgRequest->getText( 
'wpReasonSelection' );
                # Get visiblity settings...
-               $config = FlaggedRevs::getPageVisibilitySettings( $this->page, 
true );
-               $this->select = $config['select'];
-               $this->override = $config['override'];
-               $this->expiry = $config['expiry'] !== 'infinity' ? wfTimestamp( 
TS_RFC2822, $config['expiry'] ) : 'infinite';
+               $this->config = FlaggedRevs::getPageVisibilitySettings( 
$this->page, true );
+               $this->select = $this->config['select'];
+               $this->override = $this->config['override'];
+               # Make user readable date for GET requests
+               $this->expiry = $this->config['expiry'] !== 'infinity' ? 
+                       wfTimestamp( TS_RFC2822, $this->config['expiry'] ) : 
'infinite';
+               # Handle submissions
                if( $wgRequest->wasPosted() ) {
-                       $this->select = $wgRequest->getInt( 
'mwStableconfig-select' );
-                       $this->override = intval( $wgRequest->getBool( 
'mwStableconfig-override' ) );
-                       $this->expiry = $wgRequest->getText( 
'mwStableconfig-expiry' );
-                       if( strlen( $this->expiry ) == 0 ) {
-                               $this->expiry = 'infinite';
+                       $this->select = $wgRequest->getInt( 
'wpStableconfig-select' );
+                       $this->override = intval( $wgRequest->getBool( 
'wpStableconfig-override' ) );
+                       // Custom expiry takes precedence
+                       $this->expiry = $wgRequest->getText( 
'wpStableconfig-expiry' );
+                       if( strlen($this->expiry) == 0 ) {
+                               $this->expiry = $wgRequest->getVal( 
"wpExpirySelection" );
                        }
-                       if( $this->select && !in_array( $this->select, 
array(FLAGGED_VIS_NORMAL,FLAGGED_VIS_LATEST) ) ) {
+                       // Custom reason takes precedence
+                       $this->reason = strlen($this->reason) ? $this->reason : 
$this->reasonSelection;
+                       // Validate precedence setting
+                       $allowed = 
array(FLAGGED_VIS_NORMAL,FLAGGED_VIS_LATEST,FLAGGED_VIS_PRISTINE);
+                       if( $this->select && !in_array( $this->select, $allowed 
) ) {
                                $isValid = false;
                        }
                }
@@ -81,74 +91,132 @@
        }
 
        protected function showSettings( $err = null ) {
-               global $wgOut, $wgTitle, $wgUser;
-
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+               global $wgOut, $wgLang, $wgUser;
                # Must be a content page
                if( !FlaggedRevs::isPageReviewable( $this->page ) ) {
                        $wgOut->addHTML( wfMsgExt('stableversions-none', 
array('parse'), $this->page->getPrefixedText() ) );
                        return;
                }
-
-               if ( "" != $err ) {
+               # Add any error messages
+               if( "" != $err ) {
                        $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
                        $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
                }
-
+               # Add header text
                if( !$this->isAllowed ) {
                        $form = wfMsgExt( 'stabilization-perm', array('parse'), 
$this->page->getPrefixedText() );
-                       $off = array('disabled' => 'disabled');
                } else {
                        $form = wfMsgExt( 'stabilization-text', array('parse'), 
$this->page->getPrefixedText() );
-                       $off = array();
                }
-
+               # Borrow some protection messages for dropdowns
+               $reasonDropDown = Xml::listDropDown( 'wpReasonSelection',
+                       wfMsgForContent( 'protect-dropdown' ),
+                       wfMsgForContent( 'protect-otherreason-op' ), 
+                       $this->reasonSelection,
+                       'mwStabilize-reason', 4
+               );
+               $scExpiryOptions = wfMsgForContent( 'protect-expiry-options' );
+               $showProtectOptions = ($scExpiryOptions !== '-' && 
$this->isAllowed);
+               # Add the current expiry as an option
+               $expiryFormOptions = '';
+               if( $this->config['expiry'] && $this->config['expiry'] != 
'infinity' ) {
+                       $timestamp = $wgLang->timeanddate( 
$this->config['expiry'] );
+                       $d = $wgLang->date( $this->config['expiry'] );
+                       $t = $wgLang->time( $this->config['expiry'] );
+                       $expiryFormOptions .= 
+                               Xml::option( 
+                                       wfMsg( 'protect-existing-expiry', 
$timestamp, $d, $t ),
+                                       'existing',
+                                       $this->config['expiry'] == 'existing'
+                               ) . "\n";
+               }
+               $expiryFormOptions .= Xml::option( wfMsg( 
'protect-othertime-op' ), "othertime" ) . "\n";
+               # Add custom levels
+               foreach( explode(',',$scExpiryOptions) as $option ) {
+                       if( strpos($option,":") === false ) {
+                               $show = $value = $option;
+                       } else {
+                               list($show, $value) = explode(":",$option);
+                       }
+                       $show = htmlspecialchars($show);
+                       $value = htmlspecialchars($value);
+                       $expiryFormOptions .= Xml::option( $show, $value, 
$this->config['expiry'] === $value ) . "\n";
+               }
+               # Add stable version override and selection options
                $special = SpecialPage::getTitleFor( 'Stabilization' );
                $form .= Xml::openElement( 'form', array( 'name' => 
'stabilization',
                        'action' => $special->getLocalUrl(), 'method' => 'post' 
) ) .
                        Xml::fieldset( wfMsg( 'stabilization-def' ), false ) . 
"\n" .
-                       Xml::radioLabel( wfMsg( 'stabilization-def1' ), 
'mwStableconfig-override', 1,
-                               'default-stable', 1 == $this->override, $off ) 
. '<br />' . "\n" .
-                       Xml::radioLabel( wfMsg( 'stabilization-def2' ), 
'mwStableconfig-override', 0,
-                               'default-current', 0 == $this->override, $off ) 
. "\n" .
+                       Xml::radioLabel( wfMsg( 'stabilization-def1' ), 
'wpStableconfig-override', 1,
+                               'default-stable', 1 == $this->override, 
$this->disabledAttrib ) . '<br />' . "\n" .
+                       Xml::radioLabel( wfMsg( 'stabilization-def2' ), 
'wpStableconfig-override', 0,
+                               'default-current', 0 == $this->override, 
$this->disabledAttrib ) . "\n" .
                        Xml::closeElement( 'fieldset' ) .
 
                        Xml::fieldset( wfMsg( 'stabilization-select' ), false ) 
.
-                       Xml::radioLabel( wfMsg( 'stabilization-select1' ), 
'mwStableconfig-select', FLAGGED_VIS_NORMAL,
-                               'stable-select1', FLAGGED_VIS_NORMAL == 
$this->select, $off ) . '<br />' . "\n" .
-                       Xml::radioLabel( wfMsg( 'stabilization-select2' ), 
'mwStableconfig-select', FLAGGED_VIS_LATEST,
-                               'stable-select2', FLAGGED_VIS_LATEST == 
$this->select, $off ) . '<br />' . "\n" .
-                       /* 
-                       Xml::radioLabel( wfMsg( 'stabilization-select3' ), 
'mwStableconfig-select', FLAGGED_VIS_PRISTINE,
-                               'stable-select3', FLAGGED_VIS_PRISTINE == 
$this->select, $off ) .
-                       */
+                       Xml::radioLabel( wfMsg( 'stabilization-select3' ), 
'wpStableconfig-select', FLAGGED_VIS_PRISTINE,
+                               'stable-select3', FLAGGED_VIS_PRISTINE == 
$this->select, $this->disabledAttrib ) . '<br />' . "\n" .
+                       Xml::radioLabel( wfMsg( 'stabilization-select1' ), 
'wpStableconfig-select', FLAGGED_VIS_NORMAL,
+                               'stable-select1', FLAGGED_VIS_NORMAL == 
$this->select, $this->disabledAttrib ) . '<br />' . "\n" .
+                       Xml::radioLabel( wfMsg( 'stabilization-select2' ), 
'wpStableconfig-select', FLAGGED_VIS_LATEST,
+                               'stable-select2', FLAGGED_VIS_LATEST == 
$this->select, $this->disabledAttrib ) . '<br />' . "\n" .
                        Xml::closeElement( 'fieldset' ) .
 
                        Xml::fieldset( wfMsg( 'stabilization-leg' ), false ) .
-                       Xml::openElement( 'table', array( 'class' => 
'mw-fr-stabilization-leg' ) ) .
-                       '<tr>
-                               <td class="mw-label">' .
-                                       Xml::tags( 'label', array( 'for' => 
'expires' ), wfMsgExt( 'stabilization-expiry', array( 'parseinline' ) ) ) .
-                               '</td>
-                               <td class="mw-input">' .
-                                       Xml::input( 'mwStableconfig-expiry', 
60, $this->expiry, array( 'id' => 'expires'  ) + $off ) .
-                               '</td>
-                       </tr>';         
-
+                       Xml::openElement( 'table' );
+               # Add expiry dropdown
+               if( $showProtectOptions && $this->isAllowed ) {
+                       $js = "if(this.value != 'othertime') 
document.getElementById('mwStabilize-expiry').value=this.value;";
+                       $form .= "
+                               <tr>
+                                       <td class='mw-label'>" .
+                                               Xml::label( 
wfMsg('stabilization-expiry'), 'mwExpirySelection' ) .
+                                       "</td>
+                                       <td class='mw-input'>" .
+                                               Xml::tags( 'select',
+                                                       array(
+                                                               'id' => 
"mwExpirySelection",
+                                                               'name' => 
"wpExpirySelection",
+                                                               'onchange' => 
$js
+                                                       ) + 
$this->disabledAttrib,
+                                                       $expiryFormOptions ) .
+                                       "</td>
+                               </tr>";
+               }
+               # Add custom expiry field
+               $attribs = array( 'id' => "mwStabilize-expiry" ) + 
$this->disabledAttrib;
+                       $form .= "
+                               <tr>
+                                       <td class='mw-label'>" .
+                                               Xml::label( 
wfMsg('stabilization-othertime'), 'mwStabilize-expiry' ) .
+                                       '</td>
+                                       <td class="mw-input">' .
+                                               Xml::input( 
"mwStabilize-expiry", 50, $this->expiry, $attribs ) .
+                                       '</td>
+                               </tr>';
+               # Add comment input and submit button
                if( $this->isAllowed ) {
-                       $watchLabel = wfMsgExt('watchthis', 
array('parseinline'));
+                       $watchLabel = wfMsgExt( 'watchthis', 
array('parseinline') );
                        $watchAttribs = array('accesskey' => wfMsg( 
'accesskey-watch' ), 'id' => 'wpWatchthis');
-                       $watchChecked = ( $wgUser->getOption( 'watchdefault' ) 
|| $wgTitle->userIsWatching() );
+                       $watchChecked = ( $wgUser->getOption( 'watchdefault' ) 
|| $this->page->userIsWatching() );
 
                        $form .= '<tr>
                                        <td class="mw-label">' .
                                                Xml::label( wfMsg( 
'stabilization-comment' ), 'wpReason' ) .
                                        '</td>
                                        <td class="mw-input">' .
-                                               Xml::input( 'wpReason', 60, 
$this->comment, array( 'id' => 'wpReason' ) ) .
+                                               Xml::input( 'wpReason', 70, 
$this->reason, array( 'id' => 'wpReason' ) ) .
                                        '</td>
                                </tr>
                                <tr>
+                                       <td class="mw-label">' .
+                                               xml::label( 
wfMsg('stabilization-otherreason'), 'wpReasonSelection' ) .
+                                       '</td>
+                                       <td class="mw-input">' .
+                                               $reasonDropDown .
+                                       '</td>
+                               </tr>
+                               <tr>
                                        <td></td>
                                        <td class="mw-input">' .
                                                Xml::check( 'wpWatchthis', 
$watchChecked, $watchAttribs ) .
@@ -160,18 +228,15 @@
                                        <td class="mw-submit">' .
                                                Xml::submitButton( wfMsg( 
'stabilization-submit' ) ) .
                                        '</td>
-                               </tr>' .
-                               Xml::hidden( 'title', 
$wgTitle->getPrefixedDBKey() ) .
+                               </tr>' . Xml::closeElement( 'table' ) .
+                               Xml::hidden( 'title', 
$this->getTitle()->getPrefixedDBKey() ) .
                                Xml::hidden( 'page', 
$this->page->getPrefixedText() ) .
                                Xml::hidden( 'wpEditToken', 
$wgUser->editToken() );
                } else {
-                       $form .= Xml::openElement( 'table', array( 'class' => 
'mw-fr-stabilization' ) );
+                       $form .= Xml::closeElement( 'table' );
                }
+               $form .= Xml::closeElement( 'fieldset' ) . Xml::closeElement( 
'form' );
 
-               $form .= Xml::closeElement( 'table' ) .
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' );
-
                $wgOut->addHTML( $form );
 
                $wgOut->addHTML( Xml::element( 'h2', NULL, htmlspecialchars( 
LogPage::logName( 'stable' ) ) ) );
@@ -179,26 +244,29 @@
        }
 
        protected function submit() {
-               global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride, 
$wgFlaggedRevsPrecedence;
+               global $wgOut, $wgUser, $wgParser, $wgFlaggedRevsOverride;
 
                $changed = $reset = false;
+               $defaultPrecedence = FlaggedRevs::getPrecedence();
+               if( $this->select == $defaultPrecedence && $this->override == 
$wgFlaggedRevsOverride ) {
+                       $reset = true; // we are going back to site defaults
+               }
                # Take this opportunity to purge out expired configurations
                FlaggedRevs::purgeExpiredConfigurations();
 
-               if( $this->expiry == 'infinite' || $this->expiry == 
'indefinite' ) {
+               if( $reset ) {
+                       $expiry = Block::infinity(); // doesn't matter
+               } else if( $this->expiry == 'infinite' || $this->expiry == 
'indefinite' ) {
                        $expiry = Block::infinity();
                } else {
                        # Convert GNU-style date, on error returns -1 for PHP 
<5.1 and false for PHP >=5.1
                        $expiry = strtotime( $this->expiry );
-
                        if( $expiry < 0 || $expiry === false ) {
                                $this->showSettings( wfMsg( 
'stabilize_expiry_invalid' ) );
                                return false;
                        }
-
                        $expiry = wfTimestamp( TS_MW, $expiry );
-
-                       if ( $expiry < wfTimestampNow() ) {
+                       if( $expiry < wfTimestampNow() ) {
                                $this->showSettings( wfMsg( 
'stabilize_expiry_old' ) );
                                return false;
                        }
@@ -211,8 +279,7 @@
                        array( 'fpc_page_id' => $this->page->getArticleID() ),
                        __METHOD__ );
                # If setting to site default values, erase the row if there is 
one...
-               if( $row && $this->select != $wgFlaggedRevsPrecedence && 
$this->override == $wgFlaggedRevsOverride ) {
-                       $reset = true;
+               if( $row && $reset ) {
                        $dbw->delete( 'flaggedpage_config',
                                array( 'fpc_page_id' => 
$this->page->getArticleID() ),
                                __METHOD__ );
@@ -247,7 +314,7 @@
                        $reason = '';
                        # Append comment with settings (other than for resets)
                        if( !$reset ) {
-                               $reason = $this->comment ? "{$this->comment} 
$settings" : "$settings";
+                               $reason = $this->reason ? "{$this->reason} 
$settings" : "$settings";
 
                                $encodedExpiry = Block::encodeExpiry($expiry, 
$dbw );
                                if( $encodedExpiry != 'infinity' ) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to