r23297 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23296‎ | r23297 | r23298 >
Date:17:27, 23 June 2007
Author:aaron
Status:old
Tags:
Comment:
*Add year/month selector to user contribs (bug 516)
Modified paths:
  • /trunk/phase3/includes/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)
  • /trunk/phase3/includes/XmlFunctions.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/XmlFunctions.php
@@ -18,6 +18,9 @@
1919 function HTMLnamespaceselector($selected = '', $allnamespaces = null, $includehidden=false) {
2020 return Xml::namespaceSelector( $selected, $allnamespaces, $includehidden );
2121 }
 22+function HTMLmonthelector($selected = '', $allmonths = null) {
 23+ return Xml::monthSelector( $selected, $allmonths );
 24+}
2225 function wfSpan( $text, $class, $attribs=array() ) {
2326 return Xml::span( $text, $class, $attribs );
2427 }
Index: trunk/phase3/includes/Xml.php
@@ -123,7 +123,38 @@
124124 $s .= "</select>\n";
125125 return $s;
126126 }
 127+
 128+ /**
 129+ * Create a date selector
 130+ *
 131+ * @param $selected Mixed: the month which should be selected, default ''
 132+ * @param $allmonths String: value of a special item denoting all month. Null to not include (default)
 133+ * @return String: Html string containing the month selector
 134+ */
 135+ public static function monthSelector($selected = '', $allmonths = null) {
 136+ if( is_null( $selected ) )
 137+ $selected = '';
 138+ $s = "\n<select id='month' name='month' class='monthselector'>\n";
 139+ $arr = Language::$mMonthGenMsgs;
 140+
 141+ if( !is_null($allmonths) ) {
 142+ $arr = array($allmonths => 'monthsall') + $arr;
 143+ }
 144+ foreach ($arr as $index => $name) {
 145+ $message = wfMsgHtml($name);
 146+ $index++; // Let January be 1
127147
 148+ if ($index === $selected) {
 149+ $s .= "\t" . self::element("option",
 150+ array("value" => $index, "selected" => "selected"), $message) . "\n";
 151+ } else {
 152+ $s .= "\t" . self::element("option", array("value" => $index), $message) . "\n";
 153+ }
 154+ }
 155+ $s .= "</select>\n";
 156+ return $s;
 157+ }
 158+
128159 /**
129160 *
130161 * @param $language The language code of the selected language
Index: trunk/phase3/includes/SpecialContributions.php
@@ -9,13 +9,19 @@
1010 var $messages, $target;
1111 var $namespace = '', $mDb;
1212
13 - function __construct( $target, $namespace = false ) {
 13+ function __construct( $target, $namespace = false, $year = false, $month = false ) {
1414 parent::__construct();
1515 foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
1616 $this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
1717 }
1818 $this->target = $target;
1919 $this->namespace = $namespace;
 20+
 21+ $year = intval($year);
 22+ $month = intval($month);
 23+
 24+ $this->year = ($year > 0 && $year < 10000) ? $year : false;
 25+ $this->month = ($month > 1 && $month < 13) ? $month : false;
2026 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
2127 }
2228
@@ -27,7 +33,7 @@
2834
2935 function getQueryInfo() {
3036 list( $index, $userCond ) = $this->getUserCond();
31 - $conds = array_merge( array( 'page_id=rev_page' ), $userCond, $this->getNamespaceCond() );
 37+ $conds = array_merge( array('page_id=rev_page'), $userCond, $this->getNamespaceCond(), $this->GetDateCond() );
3238
3339 return array(
3440 'tables' => array( 'page', 'revision' ),
@@ -62,6 +68,37 @@
6369 return array();
6470 }
6571 }
 72+
 73+ function getDateCond() {
 74+ $condition = array();
 75+
 76+ if ( $this->year || $this->month ) {
 77+ // Assume this year if only a month is given
 78+ if ( $this->year ) {
 79+ $year_start = $this->year;
 80+ } else {
 81+ $year_start = substr( wfTimestampNow(), 0, 4 );
 82+ }
 83+
 84+ if ( $this->month ) {
 85+ $month_start = str_pad($this->month, 2, '0', STR_PAD_LEFT);
 86+ $month_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
 87+ $year_end = $year_start;
 88+ } else {
 89+ $month_start = 0;
 90+ $month_end = 0;
 91+ $year_end = $year_start + 1;
 92+ }
 93+
 94+ $ts_start = str_pad($year_start . $month_start, 14, '0' );
 95+ $ts_end = str_pad($year_end . $month_end, 14, '0' );
 96+
 97+ $condition[] = "rev_timestamp >= $ts_start";
 98+ $condition[] = "rev_timestamp < $ts_end";
 99+ }
 100+
 101+ return $condition;
 102+ }
66103
67104 function getIndexField() {
68105 return 'rev_timestamp';
@@ -233,12 +270,26 @@
234271 if ( $wgUser->isAllowed( 'rollback' ) && $wgRequest->getBool( 'bot' ) ) {
235272 $options['bot'] = '1';
236273 }
 274+
 275+ if ( ( $month = $wgRequest->getVal( 'month', null ) ) !== null && $month !== '' ) {
 276+ $options['month'] = intval( $month );
 277+ } else {
 278+ $options['month'] = '';
 279+ }
 280+
 281+ if ( ( $year = $wgRequest->getVal( 'year', null ) ) !== null && $year !== '' ) {
 282+ $options['year'] = intval( $year );
 283+ } else if( $month ) {
 284+ $options['year'] = intval( substr( wfTimestampNow(), 0, 4 ) );
 285+ } else {
 286+ $options['year'] = '';
 287+ }
237288
238289 wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
239290
240291 $wgOut->addHTML( contributionsForm( $options ) );
241292
242 - $pager = new ContribsPager( $target, $options['namespace'] );
 293+ $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] );
243294 if ( !$pager->getNumRows() ) {
244295 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
245296 return;
@@ -334,7 +385,15 @@
335386 if ( !isset( $options['contribs'] ) ) {
336387 $options['contribs'] = 'user';
337388 }
 389+
 390+ if ( !isset( $options['year'] ) ) {
 391+ $options['year'] = '';
 392+ }
338393
 394+ if ( !isset( $options['month'] ) ) {
 395+ $options['month'] = '';
 396+ }
 397+
339398 if ( $options['contribs'] == 'newbie' ) {
340399 $options['target'] = '';
341400 }
@@ -355,7 +414,13 @@
356415 Xml::input( 'target', 20, $options['target']) . ' '.
357416 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
358417 Xml::namespaceSelector( $options['namespace'], '' ) .
 418+ Xml::openElement( 'p' ) .
 419+ Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
 420+ Xml::input( 'year', 4, $options['year'], array('id' => 'year', 'maxlength' => 4) ) . ' '.
 421+ Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
 422+ xml::monthSelector( $options['month'], -1 ) .
359423 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
 424+ Xml::closeElement( 'p' ) .
360425 '</fieldset>' .
361426 Xml::closeElement( 'form' );
362427 return $f;
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1908,6 +1908,9 @@
19091909 'uclinks' => 'View the last $1 changes; view the last $2 days.',
19101910 'uctop' => ' (top)',
19111911
 1912+'month' => 'Month:',
 1913+'year' => 'Year:',
 1914+
19121915 'sp-contributions-newest' => 'Newest',
19131916 'sp-contributions-oldest' => 'Oldest',
19141917 'sp-contributions-newer' => 'Newer $1',
@@ -2734,6 +2737,7 @@
27352738 'watchlistall1' => 'all',
27362739 'watchlistall2' => 'all',
27372740 'namespacesall' => 'all',
 2741+'monthsall' => 'all',
27382742
27392743 # E-mail address confirmation
27402744 'confirmemail' => 'Confirm E-mail address',

Follow-up revisions

RevisionCommit summaryAuthorDate
r23407Merged revisions 23203-23405 via svnmerge from...david23:00, 25 June 2007

Status & tagging log