From 3d4fab1d95453c29ef2196e8e45535d1f1489e8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Sun, 31 Jul 2005 17:56:51 +0000 Subject: [PATCH] * Special:Watchlist allowed only one type of limit at a time * moved appendToArrayIfNotDefault to GlobalFunctions * changed some html message in Special:Watchlist to wiki text or plain text --- RELEASE-NOTES | 1 + includes/GlobalFunctions.php | 12 +++++ includes/SpecialRecentchanges.php | 34 ++++--------- includes/SpecialWatchlist.php | 85 +++++++++++++++++++------------ 4 files changed, 76 insertions(+), 56 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 44d71cea59..d4376bfcf2 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -631,6 +631,7 @@ of MediaWiki:Newpagetext) to &action=edit, if page is new. === Changes since 1.5beta4 === * Fix Special:Allmessages under PHP 5 +* (bug ????) Special:Watchlist allowed only one type of limit at a time === Caveats === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a694c96cfe..7673e64cc3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1304,4 +1304,16 @@ function wfEncryptPassword( $userid, $password ) { return $p; } +/** + * Appends to second array if $value differs from that in $default + */ +function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) { + if ( is_null( $changed ) ) { + wfDebugDieBacktrace('GlobalFunctions::wfAppendToArrayIfNotDefault got null'); + } + if ( $default[$key] !== $value ) { + $changed[$key] = $value; + } +} + ?> diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 8ad4899d7e..7405e688e1 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -131,7 +131,7 @@ function wfSpecialRecentchanges( $par, $specialPage ) { $hidem .= $hidebots ? ' AND rc_bot=0' : ''; $hidem .= $hideliu ? ' AND rc_user=0' : ''; $hidem .= $hidepatrolled ? ' AND rc_patrolled=0' : ''; - $hidem .= is_null( $namespace ) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace; + $hidem .= is_null( $namespace ) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace; // This is the big thing! @@ -176,15 +176,15 @@ function wfSpecialRecentchanges( $par, $specialPage ) { // Dump everything here $nondefaults = array(); - appendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults); - appendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults); - appendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'limit', $limit , $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideminor', $hideminor, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hidebots', $hidebots, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideliu', $hideliu, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hidepatrolled', $hidepatrolled, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'from', $from, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'namespace', $namespace, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'invert', $invert, $defaults, $nondefaults); // Add end of the texts $wgOut->addHTML( '
' . rcOptionsPanel( $defaults, $nondefaults ) ); @@ -563,18 +563,4 @@ function rcFormatDiff( $row ) { return $comment; } - -/** - * Appends to second array if $value differs from that in $default - */ -function appendToArrayIfNotDefault( $key, $value, $default, &$changed ) -{ - if ( is_null( $changed ) ) { - die(); - } - if ( $default[$key] !== $value ) { - $changed[$key] = $value; - } -} - ?> diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index e6fabf80fa..56f48fcc42 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -33,11 +33,20 @@ function wfSpecialWatchlist( $par ) { return; } + $defaults = array( + /* float */ 'days' => 3.0, /* or 0.5, watch further below */ + /* bool */ 'hideOwn' => false, + ); + + extract($defaults); + # Get query variables $days = $wgRequest->getVal( 'days' ); + $hideOwn = $wgRequest->getBool( 'hideOwn' ); + + # Watchlist editing $action = $wgRequest->getVal( 'action' ); $remove = $wgRequest->getVal( 'remove' ); - $hideOwn = $wgRequest->getBool( 'hideOwn' ); $id = $wgRequest->getArray( 'id' ); $uid = $wgUser->getID(); @@ -45,7 +54,7 @@ function wfSpecialWatchlist( $par ) { $wgUser->clearAllNotifications( $uid ); } - + # Deleting items from watchlist if(($action == 'submit') && isset($remove) && is_array($id)) { $wgOut->addWikiText( wfMsg( 'removingchecked' ) ); $wgOut->addHTML( '

' ); @@ -92,18 +101,24 @@ function wfSpecialWatchlist( $par ) { return; } - if ( is_null( $days ) ) { - $big = 1000; + if( is_null($days) || !is_numeric($days) ) { + $big = 1000; /* The magical big */ if($nitems > $big) { # Set default cutoff shorter - $days = (12.0 / 24.0); # 12 hours... + $days = $defaults['days'] = (12.0 / 24.0); # 12 hours... } else { - $days = 3; # longer cutoff for shortlisters + $days = $defaults['days']; # default cutoff for shortlisters } } else { $days = floatval($days); } + // Dump everything here + $nondefaults = array(); + + wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideOwn', $hideOwn, $defaults, $nondefaults); + if ( $days <= 0 ) { $docutoff = ''; $cutoff = false; @@ -119,6 +134,7 @@ function wfSpecialWatchlist( $par ) { } + /* Edit watchlist form */ if($wgRequest->getBool('edit') || $par == 'edit' ) { $wgOut->addWikiText( wfMsg( 'watchlistcontains', $wgLang->formatNum( $nitems ) ) . "\n\n" . wfMsg( 'watcheditlist' ) ); @@ -139,12 +155,12 @@ function wfSpecialWatchlist( $par ) { while( $s = $dbr->fetchObject( $res ) ) { $list[$s->wl_namespace][] = $s->wl_title; } - + // TODO: Display a TOC foreach($list as $ns => $titles) { if (Namespace::isTalk($ns)) continue; - if ($ns != NS_MAIN) + if ($ns != NS_MAIN) $wgOut->addHTML( '

' . $wgContLang->getFormattedNsText( $ns ) . '

' ); $wgOut->addHTML( '