Cleaner Special:Watchlist options form
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 20f5776..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' ) );
@@ -111,7 +116,9 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $opts->add( 'hidepatrolled', $user->getBoolOption( 'watchlisthidepatrolled' ) );
                $opts->add( 'hidemyself', $user->getBoolOption( 'watchlisthideown' ) );
 
-               $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
+               if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
+                       $opts->add( 'hidecategorization', $user->getBoolOption( 'watchlisthidecategorization' ) );
+               }
 
                return $opts;
        }
@@ -414,17 +421,22 @@ 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' ) ) {
+                       $filters['hidecategorization'] = 'rcshowhidecategorization';
+               }
+
                foreach ( $this->getCustomFilters() as $key => $params ) {
                        $filters[$key] = $params['msg'];
                }
@@ -435,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 = '';
@@ -449,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'],
@@ -487,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 = "";
@@ -526,7 +580,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                }
 
                $form .= Xml::openElement( 'form', array(
-                       'method' => 'post',
+                       'method' => 'get',
                        'action' => $this->getPageTitle()->getLocalURL(),
                        'id' => 'mw-watchlist-form'
                ) );
@@ -541,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
+               return Xml::checkLabel(
+                       $this->msg( $message, '' )->text(),
+                       $name,
+                       $name,
+                       (int)$value
                );
        }
 
-       protected function daysLink( $d, $options = array() ) {
-               $options['days'] = $d;
-
-               return Linker::linkKnown(
-                       $this->getPageTitle(),
-                       $this->getLanguage()->formatNum( $d ),
-                       array(),
-                       $options
-               );
-       }
-
-       /**
-        * 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
         *