Cleaner Special:Watchlist options form
authorRohan <rohan1395@yahoo.com>
Thu, 24 Jul 2014 08:12:34 +0000 (13:42 +0530)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Mon, 26 Oct 2015 18:12:29 +0000 (19:12 +0100)
* Show/hide links have been changed to checkboxes
* The 'show last' links have been changed to a selector
* New hidden parameter as action=submit has been added to detect form
  submissions
* Changed form method to 'get', so as to make links bookmarkable

Bug: T50615
Change-Id: I3bcd27596c21aa474547f182469abbf2ca34c4eb

includes/specials/SpecialWatchlist.php
languages/i18n/en.json
languages/i18n/qqq.json

index 962e0c3..7cc7d5f 100644 (file)
@@ -103,6 +103,11 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $user = $this->getUser();
 
                $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions::FLOAT );
+               $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
+               if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
+                       // The user has submitted the form, so we dont need the default values
+                       return $opts;
+               }
 
                $opts->add( 'hideminor', $user->getBoolOption( 'watchlisthideminor' ) );
                $opts->add( 'hidebots', $user->getBoolOption( 'watchlisthidebots' ) );
@@ -115,8 +120,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                        $opts->add( 'hidecategorization', $user->getBoolOption( 'watchlisthidecategorization' ) );
                }
 
-               $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
-
                return $opts;
        }
 
@@ -418,16 +421,16 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
 
                $nondefaults = $opts->getChangedValues();
-               $cutofflinks = $this->cutoffLinks( $opts['days'], $nondefaults ) . "<br />\n";
+               $cutofflinks = $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts );
 
                # Spit out some control panel links
                $filters = array(
-                       'hideminor' => 'rcshowhideminor',
-                       'hidebots' => 'rcshowhidebots',
-                       'hideanons' => 'rcshowhideanons',
-                       'hideliu' => 'rcshowhideliu',
-                       'hidemyself' => 'rcshowhidemine',
-                       'hidepatrolled' => 'rcshowhidepatr'
+                       'hideminor' => 'wlshowhideminor',
+                       'hidebots' => 'wlshowhidebots',
+                       'hideanons' => 'wlshowhideanons',
+                       'hideliu' => 'wlshowhideliu',
+                       'hidemyself' => 'wlshowhidemine',
+                       'hidepatrolled' => 'wlshowhidepatr'
                );
 
                if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
@@ -444,13 +447,18 @@ class SpecialWatchlist extends ChangesListSpecialPage {
 
                $links = array();
                foreach ( $filters as $name => $msg ) {
-                       $links[] = $this->showHideLink( $nondefaults, $msg, $name, $opts[$name] );
+                       $links[] = $this->showHideCheck( $nondefaults, $msg, $name, $opts[$name] );
                }
 
                $hiddenFields = $nondefaults;
+               $hiddenFields['action'] = 'submit';
                unset( $hiddenFields['namespace'] );
                unset( $hiddenFields['invert'] );
                unset( $hiddenFields['associated'] );
+               unset( $hiddenFields['days'] );
+               foreach ( $filters as $key => $value ) {
+                       unset( $hiddenFields[$key] );
+               }
 
                # Create output
                $form = '';
@@ -458,8 +466,10 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                # Namespace filter and put the whole form together.
                $form .= $wlInfo;
                $form .= $cutofflinks;
-               $form .= $lang->pipeList( $links ) . "\n";
-               $form .= "<hr />\n<p>";
+               $form .= $this->msg( 'hide' ) .
+                       $this->msg( 'colon-separator' )->escaped() .
+                       implode( ' ', $links );
+               $form .= "\n<hr />\n<p>";
                $form .= Html::namespaceSelector(
                        array(
                                'selected' => $opts['namespace'],
@@ -496,6 +506,41 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $this->setBottomText( $opts );
        }
 
+       function cutoffselector( $options ) {
+               $list = array();
+               $selectOptions = '';
+               $hours = array( 1, 2, 6, 12 );
+               $days = array( 1, 3, 7 );
+               foreach ( $hours as $h ) {
+                       $name = $this->msg( 'hours', $h );
+                       $value = $h / 24;
+                       $selected = ( $value == $options['days'] ) ? true : false;
+
+                       $selectOptions .= Xml::option( $name, $value, $selected );
+               }
+               foreach ( $days as $d ) {
+                       $name = $this->msg( 'days', $d );
+                       $value = $d;
+                       $selected = ( $value == $options['days'] ) ? true : false;
+
+                       $selectOptions .= Xml::option( $name, $value, $selected );
+               }
+
+               // all option
+               $name = $this->msg( 'watchlistall2' );
+               $value = 0;
+               $selected = ( $value == $options['days'] ) ? true : false;
+               $selectOptions .= Xml::option( $name, $value, $selected );
+
+               $attribs = array( "name" => "days", "id" => "days" );
+               return Xml::openElement( 'select', $attribs )
+                       . "\n"
+                       . $selectOptions
+                       . "\n"
+                       . Xml::closeElement( 'select' )
+                       . "<br />\n";
+       }
+
        function setTopText( FormOptions $opts ) {
                $nondefaults = $opts->getChangedValues();
                $form = "";
@@ -535,7 +580,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
 
                $form .= Xml::openElement( 'form', array(
-                       'method' => 'post',
+                       'method' => 'get',
                        'action' => $this->getPageTitle()->getLocalURL(),
                        'id' => 'mw-watchlist-form'
                ) );
@@ -550,64 +595,17 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $this->getOutput()->addHTML( $form );
        }
 
-       protected function showHideLink( $options, $message, $name, $value ) {
-               $label = $this->msg( $value ? 'show' : 'hide' )->escaped();
+       protected function showHideCheck( $options, $message, $name, $value ) {
                $options[$name] = 1 - (int)$value;
 
-               return $this->msg( $message )
-                       ->rawParams( Linker::linkKnown( $this->getPageTitle(), $label, array(), $options ) )
-                       ->escaped();
-       }
-
-       protected function hoursLink( $h, $options = array() ) {
-               $options['days'] = ( $h / 24.0 );
-
-               return Linker::linkKnown(
-                       $this->getPageTitle(),
-                       $this->getLanguage()->formatNum( $h ),
-                       array(),
-                       $options
-               );
-       }
-
-       protected function daysLink( $d, $options = array() ) {
-               $options['days'] = $d;
-
-               return Linker::linkKnown(
-                       $this->getPageTitle(),
-                       $this->getLanguage()->formatNum( $d ),
-                       array(),
-                       $options
+               return Xml::checkLabel(
+                       $this->msg( $message, '' )->text(),
+                       $name,
+                       $name,
+                       (int)$value
                );
        }
 
-       /**
-        * Returns html
-        *
-        * @param int $days This gets overwritten, so is not used
-        * @param array $options Query parameters for URL
-        * @return string
-        */
-       protected function cutoffLinks( $days, $options = array() ) {
-               global $wgRCMaxAge;
-               $watchlistMaxDays = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
-
-               $hours = array( 1, 2, 6, 12 );
-               $days = array( 1, 3, 7, $watchlistMaxDays );
-               $i = 0;
-               foreach ( $hours as $h ) {
-                       $hours[$i++] = $this->hoursLink( $h, $options );
-               }
-               $i = 0;
-               foreach ( $days as $d ) {
-                       $days[$i++] = $this->daysLink( $d, $options );
-               }
-
-               return $this->msg( 'wlshowlast' )->rawParams(
-                       $this->getLanguage()->pipeList( $hours ),
-                       $this->getLanguage()->pipeList( $days ) )->parse();
-       }
-
        /**
         * Count the number of items on a user's watchlist
         *
index 853c9ed..2a296c1 100644 (file)
        "wlheader-showupdated": "Pages that have been changed since you last visited them are shown in <strong>bold</strong>.",
        "wlnote": "Below {{PLURAL:$1|is the last change|are the last <strong>$1</strong> changes}} in the last {{PLURAL:$2|hour|<strong>$2</strong> hours}}, as of $3, $4.",
        "wlshowlast": "Show last $1 hours $2 days",
+       "watchlistall2": "all",
+       "wlshowtime": "Show last:",
+       "wlshowhideminor": "minor edits",
+       "wlshowhidebots": "bots",
+       "wlshowhideliu": "registered users",
+       "wlshowhideanons": "anonymous users",
+       "wlshowhidepatr": "patrolled edits",
+       "wlshowhidemine": "my edits",
        "watchlist-options": "Watchlist options",
        "watching": "Watching...",
        "unwatching": "Unwatching...",
index 17d259d..1f8078c 100644 (file)
        "wlheader-showupdated": "Message at the top of [[Special:Watchlist]], after {{msg-mw|watchlist-details}}. Has to be a full sentence.",
        "wlnote": "Used on [[Special:Watchlist]] when a maximum number of hours or days is specified.\n\nParameters:\n* $1 - the number of changes shown\n* $2 - the number of hours for which the changes are shown\n* $3 - a date alone\n* $4 - a time alone",
        "wlshowlast": "Appears on [[Special:Watchlist]]. Parameters:\n* $1 - a choice of different numbers of hours (\"1 | 2 | 6 | 12\")\n* $2 - a choice of different numbers of days (\"1 | 3 | 7\" and the maximum number of days available)\nClicking on your choice changes the list of changes you see (without changing the default in my preferences).",
+       "wlshowtime": "Appears on [[Special:Watchlist]].",
+       "watchlistall2": "Appears on [[Special:Watchlist]], after {{msg-mw|wlshowtime}}, as the option to display all available data regardless of age.",
+       "wlshowhideminor": "Option text in [[Special:Watchlist]].",
+       "wlshowhidebots": "Option text in [[Special:Watchlist]].",
+       "wlshowhideliu": "Option text in [[Special:Watchlist]].",
+       "wlshowhideanons": "Option text in [[Special:Watchlist]].",
+       "wlshowhidepatr": "Option text in [[Special:Watchlist]].",
+       "wlshowhidemine": "Option text in [[Special:Watchlist]].",
        "watchlist-options": "Legend of the fieldset of [[Special:Watchlist]]\n\nSee also:\n* {{msg-mw|Watchlist-details|watchlist header}}\n* {{msg-mw|Wlheader-enotif|watchlist header}}\n* {{msg-mw|enotif reset|Submit button text}}",
        "watching": "Text displayed when clicked on the watch tab: {{msg-mw|Watch}}. It means the wiki is adding that page to your watchlist.",
        "unwatching": "Text displayed when clicked on the unwatch tab: {{msg-mw|Unwatch}}. It means the wiki is removing that page from your watchlist.",