* consolidated getDateMenu duplication into xml.php
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 12 Feb 2009 19:02:14 +0000 (19:02 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 12 Feb 2009 19:02:14 +0000 (19:02 +0000)
* made filter settings carry over when pressing "go"
* made filter links a bit smaller
* removed DefaultQuery cruft
* updated docs

includes/LogEventsList.php
includes/Xml.php
includes/specials/SpecialContributions.php

index b85634b..252de82 100644 (file)
@@ -65,10 +65,11 @@ class LogEventsList {
         * @param $pattern String
         * @param $year Integer: year
         * @param $month Integer: month
-        * @param $filter Boolean
+        * @param $filter: array
+        * @param $tagFilter: array?
         */
        public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '', 
-                       $month = '', $filter = null, $tagFilter='' ) 
+               $month = '', $filter = null, $tagFilter='' ) 
        {
                global $wgScript, $wgMiserMode;
                $action = htmlspecialchars( $wgScript );
@@ -98,15 +99,17 @@ class LogEventsList {
                $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
                // Option value -> message mapping
                $links = array();
+               $hiddens = ''; // keep track for "go" button
                foreach( $filter as $type => $val ) {
                        $hideVal = 1 - intval($val);
                        $link = $this->skin->makeKnownLinkObj( $wgTitle, $messages[$hideVal],
                                wfArrayToCGI( array( "hide_{$type}_log" => $hideVal ), $this->getDefaultQuery() )
                        );
                        $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
+                       $hiddens .= Xml::hidden( "hide_{$type}_log", $val ) . "\n";
                }
                // Build links
-               return $wgLang->pipeList( $links );
+               return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
        }
        
        private function getDefaultQuery() {
@@ -183,29 +186,7 @@ class LogEventsList {
         * @return string Formatted HTML
         */
        private function getDateMenu( $year, $month ) {
-               # Offset overrides year/month selection
-               if( $month && $month !== -1 ) {
-                       $encMonth = intval( $month );
-               } else {
-                       $encMonth = '';
-               }
-               if ( $year ) {
-                       $encYear = intval( $year );
-               } else if( $encMonth ) {
-                       $thisMonth = intval( gmdate( 'n' ) );
-                       $thisYear = intval( gmdate( 'Y' ) );
-                       if( intval($encMonth) > $thisMonth ) {
-                               $thisYear--;
-                       }
-                       $encYear = $thisYear;
-               } else {
-                       $encYear = '';
-               }
-               return Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
-                       Xml::input( 'year', 4, $encYear, array('id' => 'year', 'maxlength' => 4) ) .
-                       ' '.
-                       Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
-                       Xml::monthSelector( $encMonth, -1 );
+               return Xml::dateMenu( $year, $month );
        }
 
        /**
@@ -523,7 +504,7 @@ class LogPager extends ReverseChronologicalPager {
 
                $this->mLogEventsList = $list;
 
-               $this->limitType( $type );
+               $this->limitType( $type ); // excludes hidden types too
                $this->limitUser( $user );
                $this->limitTitle( $title, $pattern );
                $this->getDateCond( $year, $month );
@@ -532,10 +513,6 @@ class LogPager extends ReverseChronologicalPager {
 
        public function getDefaultQuery() {
                $query = parent::getDefaultQuery();
-               $query['type'] = $this->type;
-               $query['user'] = $this->user;
-               $query['month'] = $this->mMonth;
-               $query['year'] = $this->mYear;
                return $query;
        }
 
index 68990d8..40a5a30 100644 (file)
@@ -172,6 +172,36 @@ class Xml {
                        . implode( "\n", $options )
                        . self::closeElement( 'select' );
        }
+       
+       /**
+        * @param $year Integer
+        * @param $month Integer
+        * @return string Formatted HTML
+        */
+       public static function dateMenu( $year, $month ) {
+               # Offset overrides year/month selection
+               if( $month && $month !== -1 ) {
+                       $encMonth = intval( $month );
+               } else {
+                       $encMonth = '';
+               }
+               if( $year ) {
+                       $encYear = intval( $year );
+               } else if( $encMonth ) {
+                       $thisMonth = intval( gmdate( 'n' ) );
+                       $thisYear = intval( gmdate( 'Y' ) );
+                       if( intval($encMonth) > $thisMonth ) {
+                               $thisYear--;
+                       }
+                       $encYear = $thisYear;
+               } else {
+                       $encYear = '';
+               }
+               return Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
+                       Xml::input( 'year', 4, $encYear, array('id' => 'year', 'maxlength' => 4) ) . ' '.
+                       Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
+                       Xml::monthSelector( $encMonth, -1 );
+       }
 
        /**
         *
index 84ece2a..a8955d8 100644 (file)
@@ -74,27 +74,12 @@ class SpecialContributions extends SpecialPage {
 
                $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev';
                # Offset overrides year/month selection
-               if( ( $month = $wgRequest->getIntOrNull( 'month' ) ) !== null && $month !== -1 ) {
-                       $this->opts['month'] = intval( $month );
-               } else {
-                       $this->opts['month'] = '';
-               }
-               if( ( $year = $wgRequest->getIntOrNull( 'year' ) ) !== null ) {
-                       $this->opts['year'] = intval( $year );
-               } else if( $this->opts['month'] ) {
-                       $thisMonth = intval( gmdate( 'n' ) );
-                       $thisYear = intval( gmdate( 'Y' ) );
-                       if( intval( $this->opts['month'] ) > $thisMonth ) {
-                               $thisYear--;
-                       }
-                       $this->opts['year'] = $thisYear;
-               } else {
-                       $this->opts['year'] = '';
-               }
-
                if( $skip ) {
                        $this->opts['year'] = '';
                        $this->opts['month'] = '';
+               } else {
+                       $this->opts['year'] = $wgRequest->getIntOrNull( 'year' );
+                       $this->opts['month'] = $wgRequest->getIntOrNull( 'month' );
                }
                
                // Add RSS/atom links
@@ -243,7 +228,7 @@ class SpecialContributions extends SpecialPage {
                }
        
                $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
-       
+               # Add hidden params for tracking
                foreach ( $this->opts as $name => $value ) {
                        if( in_array( $name, array( 'namespace', 'target', 'contribs', 'year', 'month' ) ) ) {
                                continue;
@@ -267,14 +252,8 @@ class SpecialContributions extends SpecialPage {
                        ( $tagFilter ? Xml::tags( 'p', null, implode( '&nbsp;', $tagFilter ) ) : '' ) .
                        Xml::openElement( 'p' ) .
                        '<span style="white-space: nowrap">' .
-                       Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
-                       Xml::input( 'year', 4, $this->opts['year'], array('id' => 'year', 'maxlength' => 4) ) .
-                       '</span>' .
-                       ' '.
-                       '<span style="white-space: nowrap">' .
-                       Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
-                       Xml::monthSelector( $this->opts['month'], -1 ) . ' '.
-                       '</span>' .
+                       Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) .
+                       '</span>' . ' ' .
                        Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
                        Xml::closeElement( 'p' );