From 742f648d3bf5e1462ffde5187ec6eb0a27d355a4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 23 Jun 2007 17:27:39 +0000 Subject: [PATCH] *Add year/month selector to user contribs (bug 516) --- includes/SpecialContributions.php | 71 +++++++++++++++++++++++++++++-- includes/Xml.php | 31 ++++++++++++++ includes/XmlFunctions.php | 3 ++ languages/messages/MessagesEn.php | 4 ++ 4 files changed, 106 insertions(+), 3 deletions(-) diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index 74a6a95f1e..124188bf19 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -9,13 +9,19 @@ 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 > 1 && $month < 13) ? $month : false; $this->mDb = wfGetDB( DB_SLAVE, 'contributions' ); } @@ -27,7 +33,7 @@ class ContribsPager extends IndexPager { function getQueryInfo() { list( $index, $userCond ) = $this->getUserCond(); - $conds = array_merge( array( 'page_id=rev_page' ), $userCond, $this->getNamespaceCond() ); + $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond(), $this->GetDateCond() ); return array( 'tables' => array( 'page', 'revision' ), @@ -62,6 +68,37 @@ class ContribsPager extends IndexPager { return array(); } } + + function getDateCond() { + $condition = array(); + + 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_start = str_pad($this->month, 2, '0', STR_PAD_LEFT); + $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT); + $year_end = $year_start; + } else { + $month_start = 0; + $month_end = 0; + $year_end = $year_start + 1; + } + + $ts_start = str_pad($year_start . $month_start, 14, '0' ); + $ts_end = str_pad($year_end . $month_end, 14, '0' ); + + $condition[] = "rev_timestamp >= $ts_start"; + $condition[] = "rev_timestamp < $ts_end"; + } + + return $condition; + } function getIndexField() { return 'rev_timestamp'; @@ -233,12 +270,26 @@ function wfSpecialContributions( $par = null ) { if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) { $options['bot'] = '1'; } + + if ( ( $month = $wgRequest->getVal( 'month', null ) ) !== null && $month !== '' ) { + $options['month'] = intval( $month ); + } else { + $options['month'] = ''; + } + + if ( ( $year = $wgRequest->getVal( 'year', null ) ) !== null && $year !== '' ) { + $options['year'] = intval( $year ); + } else if( $month ) { + $options['year'] = intval( substr( wfTimestampNow(), 0, 4 ) ); + } else { + $options['year'] = ''; + } wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id ); $wgOut->addHTML( contributionsForm( $options ) ); - $pager = new ContribsPager( $target, $options['namespace'] ); + $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] ); if ( !$pager->getNumRows() ) { $wgOut->addWikiText( wfMsg( 'nocontribs' ) ); return; @@ -334,6 +385,14 @@ function contributionsForm( $options ) { if ( !isset( $options['contribs'] ) ) { $options['contribs'] = 'user'; } + + if ( !isset( $options['year'] ) ) { + $options['year'] = ''; + } + + if ( !isset( $options['month'] ) ) { + $options['month'] = ''; + } if ( $options['contribs'] == 'newbie' ) { $options['target'] = ''; @@ -355,7 +414,13 @@ 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 b7a035ab26..88f8351238 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -123,6 +123,37 @@ 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) + * @return String: Html string containing the month selector + */ + public static function monthSelector($selected = '', $allmonths = null) { + if( is_null( $selected ) ) + $selected = ''; + $s = "\n\n"; + return $s; + } /** * diff --git a/includes/XmlFunctions.php b/includes/XmlFunctions.php index 326c495325..8779b4fe00 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 2966534054..7f21d1b012 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1908,6 +1908,9 @@ Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions 'uclinks' => 'View the last $1 changes; view the last $2 days.', 'uctop' => ' (top)', +'month' => 'Month:', +'year' => 'Year:', + 'sp-contributions-newest' => 'Newest', 'sp-contributions-oldest' => 'Oldest', 'sp-contributions-newer' => 'Newer $1', @@ -2734,6 +2737,7 @@ is collapsed. Others will be hidden by default. 'watchlistall1' => 'all', 'watchlistall2' => 'all', 'namespacesall' => 'all', +'monthsall' => 'all', # E-mail address confirmation 'confirmemail' => 'Confirm E-mail address', -- 2.20.1