(bug 16046) Add show/hide for types that flood logs
authorAaron Schulz <aaron@users.mediawiki.org>
Mon, 27 Oct 2008 07:18:36 +0000 (07:18 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Mon, 27 Oct 2008 07:18:36 +0000 (07:18 +0000)
includes/DefaultSettings.php
includes/LogEventsList.php
includes/specials/SpecialLog.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 4c21ac4..ea3c851 100644 (file)
@@ -2704,6 +2704,14 @@ $wgLogRestrictions = array(
        'suppress' => 'suppressionlog'
 );
 
+/**
+ * Show/hide links on Special:Log will be shown for these log types
+ * This is associative array of log => (hidden by default)
+ */
+$wgFilterLogTypes = array(
+       'patrol' => true
+);
+
 /**
  * Lists the message key string for each log type. The localized messages
  * will be listed in the user interface.
index a4f9056..2f5664c 100644 (file)
@@ -62,10 +62,11 @@ class LogEventsList {
         * @param string $user,
         * @param string $page,
         * @param string $pattern
-        * @param int $year
-        * @parm int $month
+        * @param int $y year
+        * @param int $y month
+        * @param bool $filter
         */
-       public function showOptions( $type='', $user='', $page='', $pattern='', $year='', $month='' ) {
+       public function showOptions( $type='', $user='', $page='', $pattern='', $y='', $m='', $filter=null ) {
                global $wgScript, $wgMiserMode;
                $action = htmlspecialchars( $wgScript );
                $title = SpecialPage::getTitleFor( 'Log' );
@@ -78,9 +79,42 @@ class LogEventsList {
                        $this->getUserInput( $user ) . "\n" .
                        $this->getTitleInput( $page ) . "\n" .
                        ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
-                       "<p>" . $this->getDateMenu( $year, $month ) . "\n" .
+                       "<p>" . $this->getDateMenu( $y, $m ) . "\n" .
+                       ( empty($filter) ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) .
                        Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
-                       "</fieldset></form>" );
+                       "</fieldset></form>"
+               );
+       }
+       
+       private function getFilterLinks( $logtype, $filter ) {
+               global $wgTitle;
+               // show/hide links
+               $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
+               // Option value -> message mapping
+               $links = array();
+               foreach( $filter as $type => $val ) {
+                       $onoff = 1 - intval($val);
+                       $link = $this->skin->makeKnownLinkObj( $wgTitle, $showhide[$onoff],
+                               wfArrayToCGI( array( "hide{$type}log" => $onoff ), $this->getDefaultQuery() )
+                       );
+                       $links[$type] = wfMsgHtml( "logshowhide-{$type}", $link );
+               }
+               // Build links
+               return implode( ' | ', $links );
+       }
+       
+       private function getDefaultQuery() {
+               if ( !isset( $this->mDefaultQuery ) ) {
+                       $this->mDefaultQuery = $_GET;
+                       unset( $this->mDefaultQuery['title'] );
+                       unset( $this->mDefaultQuery['dir'] );
+                       unset( $this->mDefaultQuery['offset'] );
+                       unset( $this->mDefaultQuery['limit'] );
+                       unset( $this->mDefaultQuery['order'] );
+                       unset( $this->mDefaultQuery['month'] );
+                       unset( $this->mDefaultQuery['year'] );
+               }
+               return $this->mDefaultQuery;
        }
 
        /**
@@ -460,6 +494,19 @@ class LogPager extends ReverseChronologicalPager {
                return $query;
        }
 
+       public function getFilterParams() {
+               global $wgFilterLogTypes, $wgUser, $wgRequest;
+               $filters = array();
+               foreach( $wgFilterLogTypes as $type => $default ) {
+                       // Avoid silly filtering
+                       if( $type !== $this->type && ($type !== 'patrol' || $wgUser->useNPPatrol()) ) {
+                               $filters[$type] = $wgRequest->getInt( "hide{$type}log", $default );
+                               $this->mConds[] = 'log_type != '.$this->mDb->addQuotes( $this->mDb->strencode($type) );
+                       }
+               }
+               return $filters;
+       }
+
        /**
         * Set the log reader to return only entries of the given type.
         * Type restrictions enforced here
index 15ccaf0..492c260 100644 (file)
@@ -51,15 +51,14 @@ function wfSpecialLog( $par = '' ) {
                $y = '';
                $m = '';
        }
-       # Create a LogPager item to get the results and a LogEventsList
-       # item to format them...
+       # Create a LogPager item to get the results and a LogEventsList item to format them...
        $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
        $pager = new LogPager( $loglist, $type, $user, $title, $pattern, array(), $y, $m );
        # Set title and add header
        $loglist->showHeader( $pager->getType() );
        # Show form options
        $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
-               $pager->getYear(), $pager->getMonth() );
+               $pager->getYear(), $pager->getMonth(), $pager->getFilterParams() );
        # Insert list
        $logBody = $pager->getBody();
        if( $logBody ) {
index c77514c..3ea7f1d 100644 (file)
@@ -2126,6 +2126,7 @@ Each row contains links to the first and second redirect, as well as the target
 You can narrow down the view by selecting a log type, the user name (case-sensitive), or the affected page (also case-sensitive).',
 'logempty'             => 'No matching items in log.',
 'log-title-wildcard'   => 'Search titles starting with this text',
+'logshowhide-patrol'   => '$1 patrol log',
 
 # Special:AllPages
 'allpages'          => 'All pages',
index 69cbdcb..a95a769 100644 (file)
@@ -2149,6 +2149,7 @@ $wgMessageStructure = array(
                'patrol-log-line',
                'patrol-log-auto',
                'patrol-log-diff',
+               'logshowhide-patrol'
        ),
        'imagedeletion' => array(
                'deletedrevision',