Sumit has uploaded a new change for review. https://gerrit.wikimedia.org/r/281113
Change subject: Allow date ranges in Special:Contributions ...................................................................... Allow date ranges in Special:Contributions Adds the functionality to set date ranges in Special:Contributions. Does not add a day filter. Bug: T120733 Change-Id: I7021f1f751c5331bcdb17e9cb0df1c1849663274 --- M includes/Xml.php M includes/actions/HistoryAction.php M includes/logging/LogPager.php M includes/pager/ReverseChronologicalPager.php M includes/specials/SpecialContributions.php M includes/specials/pagers/ContribsPager.php M languages/i18n/en.json M languages/i18n/qqq.json 8 files changed, 69 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/13/281113/1 diff --git a/includes/Xml.php b/includes/Xml.php index 43f7217..7366130 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -144,7 +144,7 @@ public static function monthSelector( $selected = '', $allmonths = null, $id = 'month' ) { global $wgLang; $options = []; - $data = new XmlSelect( 'month', $id, $selected ); + $data = new XmlSelect( $id, $id, $selected ); if ( is_null( $selected ) ) { $selected = ''; } @@ -164,7 +164,7 @@ * @param int $month * @return string Formatted HTML */ - public static function dateMenu( $year, $month ) { + public static function dateMenu( $year, $month, $prefix = '' ) { # Offset overrides year/month selection if ( $month && $month !== -1 ) { $encMonth = intval( $month ); @@ -184,11 +184,11 @@ } else { $encYear = ''; } - $inputAttribs = [ 'id' => 'year', 'maxlength' => 4, 'size' => 7 ]; - return self::label( wfMessage( 'year' )->text(), 'year' ) . ' ' . - Html::input( 'year', $encYear, 'number', $inputAttribs ) . ' ' . - self::label( wfMessage( 'month' )->text(), 'month' ) . ' ' . - self::monthSelector( $encMonth, -1 ); + $inputAttribs = [ 'id' => $prefix . 'year', 'maxlength' => 4, 'size' => 7 ]; + return self::label( wfMessage( $prefix . 'year' )->text(), $prefix . 'year' ) . ' ' . + Html::input( $prefix . 'year', $encYear, 'number', $inputAttribs ) . ' ' . + self::label( wfMessage( $prefix . 'month' )->text(), $prefix . 'month' ) . ' ' . + self::monthSelector( $encMonth, -1, $prefix . 'month' ); } /** diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 5ec10e6..66b13b3 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -384,7 +384,7 @@ parent::__construct( $historyPage->getContext() ); $this->historyPage = $historyPage; $this->tagFilter = $tagFilter; - $this->getDateCond( $year, $month ); + $this->mOffset = $this->getDateCond( $year, $month ); $this->conds = $conds; $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() ); } diff --git a/includes/logging/LogPager.php b/includes/logging/LogPager.php index 8518c91..8fb987c 100644 --- a/includes/logging/LogPager.php +++ b/includes/logging/LogPager.php @@ -68,7 +68,7 @@ $this->limitType( $types ); // also excludes hidden types $this->limitPerformer( $performer ); $this->limitTitle( $title, $pattern ); - $this->getDateCond( $year, $month ); + $this->mOffset = $this->getDateCond( $year, $month ); $this->mTagFilter = $tagFilter; $this->mDb = wfGetDB( DB_SLAVE, 'logpager' ); diff --git a/includes/pager/ReverseChronologicalPager.php b/includes/pager/ReverseChronologicalPager.php index 31c9c6d..e862b6d 100644 --- a/includes/pager/ReverseChronologicalPager.php +++ b/includes/pager/ReverseChronologicalPager.php @@ -52,7 +52,6 @@ $firstLastLinks = $this->msg( 'parentheses' )->rawParams( "{$pagingLinks['first']}" . $this->msg( 'pipe-separator' )->escaped() . "{$pagingLinks['last']}" )->escaped(); - $this->mNavigationBar = $firstLastLinks . ' ' . $this->msg( 'viewprevnext' )->rawParams( $pagingLinks['prev'], $pagingLinks['next'], $limits )->escaped(); @@ -60,7 +59,7 @@ return $this->mNavigationBar; } - function getDateCond( $year, $month ) { + function getDateCond( $year, $month, $dir = 1 ) { $year = intval( $year ); $month = intval( $month ); @@ -90,16 +89,19 @@ } if ( $this->mMonth ) { - $month = $this->mMonth + 1; + $month = $dir == 1?$this->mMonth + 1:$this->mMonth - 1; // For December, we want January 1 of the next year - if ( $month > 12 ) { + if ( $month > 12 && $dir == 1 ) { $month = 1; $year++; + } elseif ( $month < 1 && $dir == 0 ) { + $month = 12; + $year--; } } else { // No month implies we want up to the end of the year in question - $month = 1; - $year++; + $month = $dir == 1?1:12; + $year = $dir == 1?$year + 1:$year - 1; } // Y2K38 bug @@ -107,8 +109,8 @@ $year = 2032; } - $ymd = (int)sprintf( "%04d%02d01", $year, $month ); - + $ymd = $dir == 1?(int)sprintf( "%04d%02d01", $year, $month ): + (int)sprintf( "%04d%02d30", $year, $month ); if ( $ymd > 20320101 ) { $ymd = 20320101; } @@ -116,7 +118,6 @@ // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup $timestamp = MWTimestamp::getInstance( "${ymd}000000" ); $timestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) ); - - $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() ); + return $this->mDb->timestamp( $timestamp->getTimestamp() ); } } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 431b556..373df48 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -125,9 +125,13 @@ if ( $skip ) { $this->opts['year'] = ''; $this->opts['month'] = ''; + $this->opts['toyear'] = ''; + $this->opts['tomonth'] = ''; } else { $this->opts['year'] = $request->getIntOrNull( 'year' ); $this->opts['month'] = $request->getIntOrNull( 'month' ); + $this->opts['toyear'] = $request->getIntOrNull( 'toyear' ); + $this->opts['tomonth'] = $request->getIntOrNull( 'tomonth' ); } $feedType = $request->getVal( 'feed' ); @@ -160,6 +164,13 @@ $feedParams['month'] = $this->opts['month']; } + if ( $feedType && $this->opts['toyear'] !== null ) { + $feedParams['toyear'] = $this->opts['toyear']; + } + if ( $feedType && $this->opts['tomonth'] !== null ) { + $feedParams['tomonth'] = $this->opts['tomonth']; + } + if ( $feedType ) { // Maintain some level of backwards compatibility // If people request feeds using the old parameters, redirect to API @@ -185,6 +196,8 @@ 'tagfilter' => $this->opts['tagfilter'], 'year' => $this->opts['year'], 'month' => $this->opts['month'], + 'toyear' => $this->opts['toyear'], + 'tomonth' => $this->opts['tomonth'], 'deletedOnly' => $this->opts['deletedOnly'], 'topOnly' => $this->opts['topOnly'], 'newOnly' => $this->opts['newOnly'], @@ -425,6 +438,14 @@ $this->opts['month'] = ''; } + if ( !isset( $this->opts['toyear'] ) ) { + $this->opts['toyear'] = ''; + } + + if ( !isset( $this->opts['tomonth'] ) ) { + $this->opts['tomonth'] = ''; + } + if ( $this->opts['contribs'] == 'newbie' ) { $this->opts['target'] = ''; } @@ -459,6 +480,8 @@ 'contribs', 'year', 'month', + 'toyear', + 'tomonth', 'topOnly', 'newOnly', 'associated', @@ -621,10 +644,19 @@ implode( '', $filters ) ); - $dateSelectionAndSubmit = Xml::tags( 'td', [ 'colspan' => 2 ], + $fromDateSelectionAndSubmit = Xml::tags( 'td', [ 'colspan' => 2 ], Xml::dateMenu( $this->opts['year'] === '' ? MWTimestamp::getInstance()->format( 'Y' ) : $this->opts['year'], $this->opts['month'] + ) . ' ' + ); + + $toDateSelectionAndSubmit = Xml::tags( 'td', [ 'colspan' => 2 ], + Xml::dateMenu( + $this->opts['toyear'] === '' ? MWTimestamp::getInstance()->format( 'Y' ) : + $this->opts['toyear'], + $this->opts['tomonth'] === ''? 1:$this->opts['tomonth'], + 'to' ) . ' ' . Html::submitButton( $this->msg( 'sp-contributions-submit' )->text(), @@ -638,7 +670,8 @@ Html::rawElement( 'tr', [], $namespaceSelection ) . "\n" . Html::rawElement( 'tr', [], $filterSelection ) . "\n" . Html::rawElement( 'tr', [], $extraOptions ) . "\n" . - Html::rawElement( 'tr', [], $dateSelectionAndSubmit ) . "\n" + Html::rawElement( 'tr', [], $fromDateSelectionAndSubmit ) . "\n" . + Html::rawElement( 'tr', [], $toDateSelectionAndSubmit ) . "\n" ); $explain = $this->msg( 'sp-contributions-explain' ); diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index d90c37b..5991af3 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -31,6 +31,7 @@ public $namespace = ''; public $mDb; public $preventClickjacking = false; + private $toTime; /** @var IDatabase */ public $mDbSecondary; @@ -67,7 +68,11 @@ $year = isset( $options['year'] ) ? $options['year'] : false; $month = isset( $options['month'] ) ? $options['month'] : false; - $this->getDateCond( $year, $month ); + $toyear = isset( $options['toyear'] ) ? $options['toyear'] : false; + $tomonth = isset( $options['tomonth'] ) ? $options['tomonth'] : false; + $this->toTime = $this->getDateCond( $toyear, $tomonth, 0 ); + + $this->mOffset = $this->getDateCond( $year, $month ); // Most of this code will use the 'contributions' group DB, which can map to slaves // with extra user based indexes or partioning by user. The additional metadata @@ -156,6 +161,8 @@ $user = $this->getUser(); $conds = array_merge( $userCond, $this->getNamespaceCond() ); + // add ending time + $conds[] = 'rev_timestamp > ' . $this->mDb->addQuotes( $this->toTime ); // Paranoia: avoid brute force searches (bug 17342) if ( !$user->isAllowed( 'deletedhistory' ) ) { diff --git a/languages/i18n/en.json b/languages/i18n/en.json index b7c0ac6..dff6545 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2253,7 +2253,9 @@ "nocontribs": "No changes were found matching these criteria.", "uctop": "(current)", "month": "From month (and earlier):", + "tomonth": "Until month (and later):", "year": "From year (and earlier):", + "toyear": "Until year (and later):", "sp-contributions-newbies": "Show contributions of new accounts only", "sp-contributions-newbies-sub": "For new accounts", "sp-contributions-newbies-title": "User contributions for new accounts", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 379fe79..84805ec 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2428,8 +2428,10 @@ "contributions-userdoesnotexist": "This message is used in [[Special:Contributions]]. It is used to tell the user that the name he searched for doesn't exists.\n\nParameters:\n* $1 - a username\n\n{{identical|userdoesnotexist}}", "nocontribs": "Used in [[Special:Contributions]] and [[Special:DeletedContributions]].\n\nSee examples: [[Special:Contributions/x]] and [[Special:DeletedContributions/x]].\n\nParameters:\n* $1 - (Unused) the user name", "uctop": "This message is used in [[Special:Contributions]]. It is used to show that a particular edit was the last made to a page. Example: 09:57, 11 February 2008 (hist) (diff) Pagenameā (edit summary) (current)\n{{Identical|Current}}", - "month": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for a dropdown box to select a specific month to view the edits made in that month, and the earlier months. See also {{msg-mw|year}}.", - "year": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for an input box to select a specific year to view the edits made in that year, and the earlier years.\n\nSee also:\n* {{msg-mw|month}}", + "month": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for a dropdown box to select a specific month to view the edits made in that month, and the earlier months till tomonth. See also {{msg-mw|year}}.", + "tomonth": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for a dropdown box to select a specific month to view the edits made till that month. See also {{msg-mw|year}}.", + "year": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for an input box to select a specific year to view the edits made in that year till toyear.\n\nSee also:\n* {{msg-mw|month}}", + "toyear": "Used in [[Special:Contributions]] and history pages ([{{fullurl:Sandbox|action=history}} example]), as label for an input box to select a specific year to limit the edits to that year.\n\nSee also:\n* {{msg-mw|month}}", "sp-contributions-newbies": "Text of radio button on special page [[Special:Contributions]].", "sp-contributions-newbies-sub": "Note at the top of the page of results for a search on [[Special:Contributions]] where 'Show contributions for new accounts only' has been selected.", "sp-contributions-newbies-title": "The page title in your browser bar, but not the page title.\n\nSee also:\n* {{msg-mw|Sp-contributions-newbies-sub}}", -- To view, visit https://gerrit.wikimedia.org/r/281113 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7021f1f751c5331bcdb17e9cb0df1c1849663274 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Sumit <asthana.sumi...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits