From f7f2b225d100675b13189f65c09db564ecb9a6d7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 6 Jul 2007 22:05:29 +0000 Subject: [PATCH] *Re-add contribs year/month filter. Now it simply jumps to a certain offset. --- includes/SpecialContributions.php | 74 +++++++++++++++++++++++++++++-- includes/Xml.php | 22 +++++++++ includes/XmlFunctions.php | 3 ++ languages/messages/MessagesEn.php | 4 +- 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index 68ae831f7b..627ded26db 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -9,13 +9,21 @@ class ContribsPager extends IndexPager { var $messages, $target; var $namespace = '', $mDb; - function __construct( $target, $namespace = false ) { + function __construct( $target, $namespace = false, $year = false, $month = false ) { parent::__construct(); foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) { $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') ); } $this->target = $target; $this->namespace = $namespace; + + $year = intval($year); + $month = intval($month); + + $this->year = ($year > 0 && $year < 10000) ? $year : false; + $this->month = ($month > 0 && $month < 13) ? $month : false; + $this->GetDateCond(); + $this->mDb = wfGetDB( DB_SLAVE, 'contributions' ); } @@ -63,6 +71,28 @@ class ContribsPager extends IndexPager { } } + function getDateCond() { + if ( $this->year || $this->month ) { + // Assume this year if only a month is given + if ( $this->year ) { + $year_start = $this->year; + } else { + $year_start = substr( wfTimestampNow(), 0, 4 ); + } + + if ( $this->month ) { + $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT); + $year_end = $year_start; + } else { + $month_end = 0; + $year_end = $year_start + 1; + } + $ts_end = str_pad($year_end . $month_end, 14, '0' ); + + $this->mOffset = $ts_end; + } + } + function getIndexField() { return 'rev_timestamp'; } @@ -234,11 +264,33 @@ function wfSpecialContributions( $par = null ) { $options['bot'] = '1'; } + $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev'; + # Offset overrides year/month selection + if ( ( $month = $wgRequest->getIntOrNull( 'month' ) ) !== null && $month !== -1 ) { + $options['month'] = intval( $month ); + } else { + $options['month'] = ''; + } + if ( ( $year = $wgRequest->getIntOrNull( 'year' ) ) !== null ) { + $options['year'] = intval( $year ); + } else if( $options['month'] ) { + $options['year'] = intval( substr( wfTimestampNow(), 0, 4 ) ); + } else { + $options['year'] = ''; + } + wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id ); $wgOut->addHTML( contributionsForm( $options ) ); + # Show original selected options, don't apply them so as to allow paging + $_GET['year'] = ''; // hack for Pager + $_GET['month'] = ''; // hack for Pager + if( $skip ) { + $options['year'] = ''; + $options['month'] = ''; + } - $pager = new ContribsPager( $target, $options['namespace'] ); + $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] ); if ( !$pager->getNumRows() ) { $wgOut->addWikiText( wfMsg( 'nocontribs' ) ); return; @@ -335,6 +387,14 @@ function contributionsForm( $options ) { $options['contribs'] = 'user'; } + if ( !isset( $options['year'] ) ) { + $options['year'] = ''; + } + + if ( !isset( $options['month'] ) ) { + $options['month'] = ''; + } + if ( $options['contribs'] == 'newbie' ) { $options['target'] = ''; } @@ -342,7 +402,7 @@ function contributionsForm( $options ) { $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); foreach ( $options as $name => $value ) { - if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) { + if ( in_array( $name, array( 'namespace', 'target', 'contribs', 'year', 'month' ) ) ) { continue; } $f .= "\t" . Xml::hidden( $name, $value ) . "\n"; @@ -355,11 +415,17 @@ function contributionsForm( $options ) { Xml::input( 'target', 20, $options['target']) . ' '. Xml::label( wfMsg( 'namespace' ), 'namespace' ) . Xml::namespaceSelector( $options['namespace'], '' ) . + Xml::openElement( 'p' ) . + Xml::label( wfMsg( 'year' ), 'year' ) . ' '. + Xml::input( 'year', 4, $options['year'], array('id' => 'year', 'maxlength' => 4) ) . ' '. + Xml::label( wfMsg( 'month' ), 'month' ) . ' '. + xml::monthSelector( $options['month'], -1 ) . ' '. Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) . + Xml::closeElement( 'p' ) . '' . Xml::closeElement( 'form' ); return $f; } - +?> diff --git a/includes/Xml.php b/includes/Xml.php index 1eeba94ec3..97c889886f 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -123,6 +123,28 @@ class Xml { $s .= "\n"; return $s; } + + /** + * Create a date selector + * + * @param $selected Mixed: the month which should be selected, default '' + * @param $allmonths String: value of a special item denoting all month. Null to not include (default) + * @param string $id Element identifier + * @return String: Html string containing the month selector + */ + public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) { + global $wgLang; + $options = array(); + if( is_null( $selected ) ) + $selected = ''; + if( !is_null( $allmonths ) ) + $options[] = self::option( wfMsg( 'monthsall' ), $allmonths, $selected === $allmonths ); + for( $i = 1; $i < 13; $i++ ) + $options[] = self::option( $wgLang->getMonthName( $i ), $i, $selected === $i ); + return self::openElement( 'select', array( 'id' => $id, 'name' => 'month' ) ) + . implode( "\n", $options ) + . self::closeElement( 'select' ); + } /** * diff --git a/includes/XmlFunctions.php b/includes/XmlFunctions.php index 076ca207a5..0241284961 100644 --- a/includes/XmlFunctions.php +++ b/includes/XmlFunctions.php @@ -18,6 +18,9 @@ function wfCloseElement( $element ) { function HTMLnamespaceselector($selected = '', $allnamespaces = null, $includehidden=false) { return Xml::namespaceSelector( $selected, $allnamespaces, $includehidden ); } +function HTMLmonthelector($selected = '', $allmonths = null) { + return Xml::monthSelector( $selected, $allmonths ); +} function wfSpan( $text, $class, $attribs=array() ) { return Xml::span( $text, $class, $attribs ); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 504456860a..8abc3ecab5 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1900,8 +1900,8 @@ Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions 'ucnote' => "Below are this user's last $1 changes in the last $2 days.", 'uclinks' => 'View the last $1 changes; view the last $2 days.', 'uctop' => ' (top)', -'month' => 'Month:', -'year' => 'Year:', +'month' => 'From month (and earlier):', +'year' => 'From year (and earlier):', 'sp-contributions-newest' => 'Newest', 'sp-contributions-oldest' => 'Oldest', -- 2.20.1