/**
* Constructor
*/
-function wfSpecialRecentchanges( $par ) {
+function wfSpecialRecentchanges( $par, $specialPage ) {
global $wgUser, $wgOut, $wgLang, $wgContLang, $wgTitle, $wgMemc, $wgDBname;
global $wgRequest, $wgSitename, $wgLanguageCode, $wgContLanguageCode;
global $wgFeedClasses, $wgUseRCPatrol;
# Get query parameters
$feedFormat = $wgRequest->getVal( 'feed' );
- $defaultDays = $wgUser->getOption( 'rcdays' );
- if ( !$defaultDays ) { $defaultDays = 3; }
+ $defaults = array(
+ /* int */ 'days' => $wgUser->getDefaultOption('rcdays'),
+ /* int */ 'limit' => $wgUser->getDefaultOption('rclimit'),
+ /* bool */ 'hideminor' => false,
+ /* bool */ 'hidebots' => true,
+ /* bool */ 'hideliu' => false,
+ /* bool */ 'hidepatrolled' => false,
+ /* text */ 'from' => '',
+ /* text */ 'namespace' => null,
+ /* bool */ 'invert' => false,
+ );
+
+ extract($defaults);
+
+
+ $days = $wgUser->getOption( 'rcdays' );
+ if ( !$days ) { $days = $defaults['days']; }
+ $days = $wgRequest->getInt( 'days', $days );
+
+ $limit = $wgUser->getOption( 'rclimit' );
+ if ( !$limit ) { $limit = $defaults['limit']; }
+
+ # list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
+ $limit = $wgRequest->getInt( 'limit', $limit );
+
+ /* order of selection: url > preferences > default */
+ $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor') ? true : $defaults['hideminor'] );
- $days = $wgRequest->getInt( 'days', $defaultDays );
- $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0;
- list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
# As a feed, use limited settings only
if( $feedFormat ) {
- $from = null;
- $hidebots = 1;
- $hideliu = 0;
- $hidepatrolled = 0;
global $wgFeedLimit;
if( $limit > $wgFeedLimit ) {
- $limit = $wgFeedLimit;
+ $options['limit'] = $wgFeedLimit;
}
+
} else {
- $from = $wgRequest->getText( 'from' );
- $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0;
- $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0;
- $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', false ) ? 1 : 0;
-
+
+ $namespace = $wgRequest->getIntOrNull( 'namespace' );
+ $invert = $wgRequest->getBool( 'invert', $defaults['invert'] );
+ $hidebots = $wgRequest->getBool( 'hidebots', $defaults['hidebots'] );
+ $hideliu = $wgRequest->getBool( 'hideliu', $defaults['hideliu'] );
+ $hidepatrolled = $wgRequest->getBool( 'hidepatrolled', $defaults['hidepatrolled'] );
+ $from = $wgRequest->getVal( 'from', $defaults['from'] );
+
# Get query parameters from path
if( $par ) {
$bits = preg_split( '/\s*,\s*/', trim( $par ) );
- if( in_array( 'hidebots', $bits ) ) $hidebots = 1;
- if( in_array( 'bots', $bits ) ) $hidebots = 0;
- if( in_array( 'hideminor', $bits ) ) $hideminor = 1;
- if( in_array( 'minor', $bits ) ) $hideminor = 0;
- if( in_array( 'hideliu', $bits) ) $hideliu = 1;
- if( in_array( 'hidepatrolled', $bits) ) $hidepatrolled = 1;
+ foreach ( $bits as $bit ) {
+ if ( 'hidebots' == $bit ) $hidebots = 1;
+ if ( 'bots' == $bit ) $hidebots = 0;
+ if ( 'hideminor' == $bit ) $hideminor = 1;
+ if ( 'minor' == $bit ) $hideminor = 0;
+ if ( 'hideliu' == $bit ) $hideliu = 1;
+ if ( 'hidepatrolled' == $bit ) $hidepatrolled = 1;
+
+ if ( is_numeric( $bit ) ) {
+ $limit = $bit;
+ }
+
+ if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
+ $limit = $m[1];
+ }
+
+ if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
+ $days = $m[1];
+ }
+ }
}
}
+ if ( $limit < 0 || $limit > 5000 ) $limit = $defaults['limit'];
+
# Database connection and caching
$dbr =& wfGetDB( DB_SLAVE );
extract( $dbr->tableNames( 'recentchanges', 'watchlist' ) );
+ $cutoff_unixtime = time() - ( $days * 86400 );
+ $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
+ $cutoff = $dbr->timestamp( $cutoff_unixtime );
+ if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
+ $cutoff = $dbr->timestamp($from);
+ } else {
+ $from = $defaults['from'];
+ }
+
# 10 seconds server-side caching max
$wgOut->setSquidMaxage( 10 );
}
}
- # Output header
- $rctext = wfMsgForContent( "recentchangestext" );
- $wgOut->addWikiText( $rctext );
-
-
- $now = wfTimestampNow();
- $cutoff_unixtime = time() - ( $days * 86400 );
- $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
- $cutoff = $dbr->timestamp( $cutoff_unixtime );
- if(preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW,$cutoff)) {
- $cutoff = $dbr->timestamp($from);
- } else {
- unset($from);
- }
-
- $sk = $wgUser->getSkin();
-
- $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
+ $hidem = $hideminor ? 'AND rc_minor=0' : '';
+ $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 = ( $hideminor ) ? 'AND rc_minor=0' : '';
- $hidem .= ( $hidebots ) ? ' AND rc_bot=0' : '';
- $hidem .= ( $hideliu ) ? ' AND rc_user=0' : '';
- $hidem .= ( $hidepatrolled )? ' AND rc_patrolled=0' : '';
-
- $urlparams = array( 'hideminor' => $hideminor, 'hideliu' => $hideliu,
- 'hidebots' => $hidebots, 'hidepatrolled' => $hidepatrolled,
- 'limit' => $limit );
- $hideparams = wfArrayToCGI( $urlparams );
-
- $minorLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
- $showhide[1-$hideminor], wfArrayToCGI( array( 'hideminor' => 1-$hideminor ), $urlparams ) );
- $botLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
- $showhide[1-$hidebots], wfArrayToCGI( array( 'hidebots' => 1-$hidebots ), $urlparams ) );
- $liuLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
- $showhide[1-$hideliu], wfArrayToCGI( array( 'hideliu' => 1-$hideliu ), $urlparams ) );
- $patrLink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
- $showhide[1-$hidepatrolled], wfArrayToCGI( array( 'hidepatrolled' => 1-$hidepatrolled ), $urlparams ) );
+ // This is the big thing!
$uid = $wgUser->getID();
// Perform query
- $sql2 = "SELECT $recentchanges.*" . ($uid ? ",wl_user,wl_notificationtimestamp" : "") . " FROM $recentchanges " .
+ $sql2 = "SELECT *" . ($uid ? ",wl_user,wl_notificationtimestamp" : "") . " FROM $recentchanges " .
($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") .
"WHERE rc_timestamp > '{$cutoff}' {$hidem} " .
"ORDER BY rc_timestamp DESC LIMIT {$limit}";
// Run existence checks
$batch->execute( $wgLinkCache );
- if(isset($from)) {
- $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $limit ),
- $wgLang->timeanddate( $from, true ) );
- } else {
- $note = wfMsg( 'rcnote', $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
- }
- $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
-
- $note = rcDayLimitLinks( $days, $limit, 'Recentchanges', $hideparams, false, $minorLink, $botLink, $liuLink, $patrLink );
-
- $note .= "<br />\n" . wfMsg( 'rclistfrom',
- $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
- $wgLang->timeanddate( $now, true ), $hideparams.'&from='.$now ) );
-
- $wgOut->addHTML( $note."\n" );
-
if( $feedFormat ) {
rcOutputFeed( $rows, $feedFormat, $limit, $hideminor, $lastmod );
} else {
+
# Web output...
+
+ // Output header
+ if ( !$specialPage->including() ) {
+ $wgOut->addWikiText( wfMsgForContent( "recentchangestext" ) );
+
+ // 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);
+
+ // Add end of the texts
+ $wgOut->addHTML( '<div class="rcoptions">' . rcOptionsPanel( $defaults, $nondefaults ) );
+ $wgOut->addHTML( rcNamespaceForm( $namespace, $invert, $nondefaults) . '</div>');
+ }
+
+ // And now for the content
+ $sk = $wgUser->getSkin();
$wgOut->setSyndicated( true );
$list =& new ChangesList( $sk );
$s = $list->beginRecentChangesList();
$rc->counter = $counter++;
if ($wgShowUpdatedMarker
- && $wgUser->getOption( 'showupdated' )
&& !empty( $obj->wl_notificationtimestamp )
&& ($obj->rc_timestamp >= $obj->wl_notificationtimestamp)) {
$rc->notificationtimestamp = true;
}
/**
- * Used also by Recentchangeslinked
+ * Used by Recentchangeslinked
*/
function rcDayLimitLinks( $days, $limit, $page='Recentchanges', $more='', $doall = false, $minorLink = '',
$botLink = '', $liuLink = '', $patrLink = '' ) {
return $note;
}
+
+/**
+ * Makes change an option link which carries all the other options
+ */
+function makeOptionsLink( $title, $override, $options ) {
+ global $wgUser, $wgLang, $wgContLang;
+ $sk = $wgUser->getSkin();
+ return $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchanges' ),
+ $title, wfArrayToCGI( $override, $options ) );
+}
+
+/**
+ * Creates the options panel
+ */
+function rcOptionsPanel( $defaults, $nondefaults ) {
+ global $wgLang;
+
+ $options = $nondefaults + $defaults;
+
+ if( $options['from'] )
+ $note = wfMsg( 'rcnotefrom', $wgLang->formatNum( $options['limit'] ), $wgLang->timeanddate( $options['from'], true ) );
+ else
+ $note = wfMsg( 'rcnote', $wgLang->formatNum( $options['limit'] ), $wgLang->formatNum( $options['days'] ) );
+
+ // limit links
+ $cl = '';
+ $options_limit = array(50, 100, 250, 500);
+ $i = 0;
+ while ( $i+1 < count($options_limit) ) {
+ $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) . ' | ' ;
+ $i++;
+ }
+ $cl .= makeOptionsLink( $options_limit[$i], array( 'limit' => $options_limit[$i] ), $nondefaults) ;
+
+ // day links, reset 'from' to none
+ $dl = '';
+ $options_days = array(1, 3, 7, 14, 30);
+ $i = 0;
+ while ( $i+1 < count($options_days) ) {
+ $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) . ' | ' ;
+ $i++;
+ }
+ $dl .= makeOptionsLink( $options_days[$i], array( 'days' => $options_days[$i], 'from' => '' ), $nondefaults) ;
+
+ // show/hide links
+ $showhide = array( wfMsg( 'show' ), wfMsg( 'hide' ));
+ $minorLink = makeOptionsLink( $showhide[1-$options['hideminor']],
+ array( 'hideminor' => 1-$options['hideminor'] ), $nondefaults);
+ $botLink = makeOptionsLink( $showhide[1-$options['hidebots']],
+ array( 'hidebots' => 1-$options['hidebots'] ), $nondefaults);
+ $liuLink = makeOptionsLink( $showhide[1-$options['hideliu']],
+ array( 'hideliu' => 1-$options['hideliu'] ), $nondefaults);
+ $patrLink = makeOptionsLink( $showhide[1-$options['hidepatrolled']],
+ array( 'hidepatrolled' => 1-$options['hidepatrolled'] ), $nondefaults);
+
+ $hl = wfMsg( 'showhideminor', $minorLink, $botLink, $liuLink, $patrLink );
+
+ // show from this onward link
+ $now = $wgLang->timeanddate( wfTimestampNow(), true );
+ $tl = makeOptionsLink( $now, array( 'from' => wfTimestampNow()), $nondefaults );
+
+ $rclinks = wfMsg( 'rclinks', $cl, $dl, $hl );
+ $rclistfrom = wfMsg( 'rclistfrom', $tl );
+ return "$note<br />$rclinks<br />$rclistfrom";
+
+}
+
+/**<F2>
+ * Creates the choose namespace selection
+ *
+ * @access private
+ *
+ * @param mixed $namespace The key of the currently selected namespace, empty string
+ * if there is none
+ * @param bool $invert Whether to invert the namespace selection
+ * @param array $nondefaults An array of non default options to be remembered
+ *
+ * @return string
+ */
+function rcNamespaceForm ( $namespace, $invert, $nondefaults ) {
+ global $wgContLang, $wgScript;
+ $t = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
+
+ $namespaceselect = "<select name='namespace' id='nsselectbox'>";
+ $namespaceselect .= '<option value="" ' . ($namespace === '' ? ' selected="selected"' : '') . '>' . wfMsg( 'contributionsall' ) . '</option>';
+ $arr = $wgContLang->getFormattedNamespaces();
+ foreach ( $arr as $ns => $name ) {
+ if( $ns < NS_MAIN )
+ continue;
+ $n = $ns === NS_MAIN ? wfMsg ( 'blanknamespace' ) : $name;
+ $sel = $namespace === (string) $ns ? ' selected="selected"' : '';
+ $namespaceselect .= "<option value='$ns'$sel>$n</option>";
+ }
+ $namespaceselect .= '</select>';
+
+ $out = '';
+ $out .= "<div class='namespaceselector'><form method='get' action='{$wgScript}'>\n";
+ foreach ( $nondefaults as $key => $value ) {
+ if ($key != 'namespace' && $key != 'invert')
+ $out .= "<input type='hidden' name='$key' value='$value' />";
+ }
+
+ $submitbutton = '<input type="submit" value="' . wfMsg( 'allpagessubmit' ) . '" />';
+ $invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" . ( $invert ? ' checked="checked"' : '' ) . ' />';
+
+
+ $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
+ $out .= "
+<div id='nsselect' class='recentchanges'>
+ <label for='nsselectbox'>" . wfMsg('namespace') . "</label>
+ $namespaceselect $submitbutton $invertbox <label for='nsinvert'>" . wfMsg('invert') . "</label>
+</div>";
+ $out .= '</form></div>';
+ return $out;
+}
+
+
/**
* Format a diff for the newsfeed
*/
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;
+ }
+}
+
?>