From fc69f9f54c78c614c60d24c8ac86957c0113180e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 27 Oct 2008 07:18:36 +0000 Subject: [PATCH] (bug 16046) Add show/hide for types that flood logs --- includes/DefaultSettings.php | 8 +++++ includes/LogEventsList.php | 57 ++++++++++++++++++++++++++++--- includes/specials/SpecialLog.php | 5 ++- languages/messages/MessagesEn.php | 1 + maintenance/language/messages.inc | 1 + 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4c21ac4489..ea3c851eea 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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. diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index a4f90567a7..2f5664c112 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -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") : "" ) . - "

" . $this->getDateMenu( $year, $month ) . "\n" . + "

" . $this->getDateMenu( $y, $m ) . "\n" . + ( empty($filter) ? "

".$this->getFilterLinks( $type, $filter )."\n" : "" ) . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "

\n" . - "" ); + "" + ); + } + + 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 diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index 15ccaf0833..492c2608a7 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -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 ) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c77514cd73..3ea7f1dd77 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 69cbdcbbdc..a95a769263 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2149,6 +2149,7 @@ $wgMessageStructure = array( 'patrol-log-line', 'patrol-log-auto', 'patrol-log-diff', + 'logshowhide-patrol' ), 'imagedeletion' => array( 'deletedrevision', -- 2.20.1