r23803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23802‎ | r23803 | r23804 >
Date:22:05, 6 July 2007
Author:aaron
Status:old
Tags:
Comment:
*Re-add contribs year/month filter. Now it simply jumps to a certain offset.
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,6 +123,28 @@
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+ * @param string $id Element identifier
 134+ * @return String: Html string containing the month selector
 135+ */
 136+ public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) {
 137+ global $wgLang;
 138+ $options = array();
 139+ if( is_null( $selected ) )
 140+ $selected = '';
 141+ if( !is_null( $allmonths ) )
 142+ $options[] = self::option( wfMsg( 'monthsall' ), $allmonths, $selected === $allmonths );
 143+ for( $i = 1; $i < 13; $i++ )
 144+ $options[] = self::option( $wgLang->getMonthName( $i ), $i, $selected === $i );
 145+ return self::openElement( 'select', array( 'id' => $id, 'name' => 'month' ) )
 146+ . implode( "\n", $options )
 147+ . self::closeElement( 'select' );
 148+ }
127149
128150 /**
129151 *
Index: trunk/phase3/includes/SpecialContributions.php
@@ -9,13 +9,21 @@
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 > 0 && $month < 13) ? $month : false;
 26+ $this->GetDateCond();
 27+
2028 $this->mDb = wfGetDB( DB_SLAVE, 'contributions' );
2129 }
2230
@@ -63,6 +71,28 @@
6472 }
6573 }
6674
 75+ function getDateCond() {
 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_end = str_pad($this->month + 1, 2, '0', STR_PAD_LEFT);
 86+ $year_end = $year_start;
 87+ } else {
 88+ $month_end = 0;
 89+ $year_end = $year_start + 1;
 90+ }
 91+ $ts_end = str_pad($year_end . $month_end, 14, '0' );
 92+
 93+ $this->mOffset = $ts_end;
 94+ }
 95+ }
 96+
6797 function getIndexField() {
6898 return 'rev_timestamp';
6999 }
@@ -234,11 +264,33 @@
235265 $options['bot'] = '1';
236266 }
237267
 268+ $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev';
 269+ # Offset overrides year/month selection
 270+ if ( ( $month = $wgRequest->getIntOrNull( 'month' ) ) !== null && $month !== -1 ) {
 271+ $options['month'] = intval( $month );
 272+ } else {
 273+ $options['month'] = '';
 274+ }
 275+ if ( ( $year = $wgRequest->getIntOrNull( 'year' ) ) !== null ) {
 276+ $options['year'] = intval( $year );
 277+ } else if( $options['month'] ) {
 278+ $options['year'] = intval( substr( wfTimestampNow(), 0, 4 ) );
 279+ } else {
 280+ $options['year'] = '';
 281+ }
 282+
238283 wfRunHooks( 'SpecialContributionsBeforeMainOutput', $id );
239284
240285 $wgOut->addHTML( contributionsForm( $options ) );
 286+ # Show original selected options, don't apply them so as to allow paging
 287+ $_GET['year'] = ''; // hack for Pager
 288+ $_GET['month'] = ''; // hack for Pager
 289+ if( $skip ) {
 290+ $options['year'] = '';
 291+ $options['month'] = '';
 292+ }
241293
242 - $pager = new ContribsPager( $target, $options['namespace'] );
 294+ $pager = new ContribsPager( $target, $options['namespace'], $options['year'], $options['month'] );
243295 if ( !$pager->getNumRows() ) {
244296 $wgOut->addWikiText( wfMsg( 'nocontribs' ) );
245297 return;
@@ -335,6 +387,14 @@
336388 $options['contribs'] = 'user';
337389 }
338390
 391+ if ( !isset( $options['year'] ) ) {
 392+ $options['year'] = '';
 393+ }
 394+
 395+ if ( !isset( $options['month'] ) ) {
 396+ $options['month'] = '';
 397+ }
 398+
339399 if ( $options['contribs'] == 'newbie' ) {
340400 $options['target'] = '';
341401 }
@@ -342,7 +402,7 @@
343403 $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
344404
345405 foreach ( $options as $name => $value ) {
346 - if ( in_array( $name, array( 'namespace', 'target', 'contribs' ) ) ) {
 406+ if ( in_array( $name, array( 'namespace', 'target', 'contribs', 'year', 'month' ) ) ) {
347407 continue;
348408 }
349409 $f .= "\t" . Xml::hidden( $name, $value ) . "\n";
@@ -355,11 +415,17 @@
356416 Xml::input( 'target', 20, $options['target']) . ' '.
357417 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
358418 Xml::namespaceSelector( $options['namespace'], '' ) .
 419+ Xml::openElement( 'p' ) .
 420+ Xml::label( wfMsg( 'year' ), 'year' ) . ' '.
 421+ Xml::input( 'year', 4, $options['year'], array('id' => 'year', 'maxlength' => 4) ) . ' '.
 422+ Xml::label( wfMsg( 'month' ), 'month' ) . ' '.
 423+ xml::monthSelector( $options['month'], -1 ) . ' '.
359424 Xml::submitButton( wfMsg( 'sp-contributions-submit' ) ) .
 425+ Xml::closeElement( 'p' ) .
360426 '</fieldset>' .
361427 Xml::closeElement( 'form' );
362428 return $f;
363429 }
364430
365431
366 -
 432+?>
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1900,8 +1900,8 @@
19011901 'ucnote' => "Below are this user's last <b>$1</b> changes in the last <b>$2</b> days.",
19021902 'uclinks' => 'View the last $1 changes; view the last $2 days.',
19031903 'uctop' => ' (top)',
1904 -'month' => 'Month:',
1905 -'year' => 'Year:',
 1904+'month' => 'From month (and earlier):',
 1905+'year' => 'From year (and earlier):',
19061906
19071907 'sp-contributions-newest' => 'Newest',
19081908 'sp-contributions-oldest' => 'Oldest',

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log