r84058 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84057‎ | r84058 | r84059 >
Date:22:17, 15 March 2011
Author:bawolff
Status:ok (Comments)
Tags:
Comment:
Add an hourcount parameter to limit results returned to those added to the category in the last X hours.

the guidelines for news sitemaps indicate they should only have stuff from the last 48 hours.
Parameter is off by default.
Modified paths:
  • /trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php
@@ -15,6 +15,7 @@
1616 * * notcategories = string ; default = null
1717 * * namespace = string ; default = null
1818 * * count = integer ; default = $wgDPLmaxResultCount = 50
 19+ * * hourcont = integer ; default -1 (disabled), how many hours before cutoff
1920 * * order = string ; default = descending
2021 * * ordermethod = string ; default = categoryadd
2122 * * redirects = string ; default = exclude
@@ -163,6 +164,24 @@
164165 break;
165166 }
166167
 168+ if ( $this->params['hourCount'] > 0
 169+ && $this->params['orderMethod'] !== 'lastedit' )
 170+ {
 171+ // Limit to last X number of hours added to category,
 172+ // if hourcont is positive and we're sorting by
 173+ // category add date.
 174+ // This feature is here because the Google News
 175+ // Sitemap usecase is only supposed to have
 176+ // articles published in last 2 days on it.
 177+ // Don't do anything with lastedit, since this option
 178+ // doesn't make sense with it (Do we even need that order method?)
 179+ $timeOffset = wfTimestamp( TS_UNIX ) - ( $this->params['hourCount'] * 3600 );
 180+ $MWTimestamp = wfTimestamp( TS_MW, $timeOffset );
 181+ if ( $MWTimestamp ) {
 182+ $conditions[] = 'c1.cl_timestamp > ' . $MWTimestamp;
 183+ }
 184+ }
 185+
167186 $currentTableNumber = 1;
168187 $categorylinks = $dbr->tableName( 'categorylinks' );
169188
@@ -223,6 +242,7 @@
224243 // $this->notCategories[] = $wgRequest->getArray('notcategory');
225244 $this->params['nameSpace'] = $wgContLang->getNsIndex( $wgRequest->getVal( 'namespace', 0 ) );
226245 $this->params['count'] = $wgRequest->getInt( 'count', $this->wgDPLmaxResultCount );
 246+ $this->params['hourCount'] = $wgRequest->getInt( 'hourcount', -1 );
227247
228248 if ( ( $this->params['count'] > $this->wgDPLmaxResultCount )
229249 || ( $this->params['count'] < 1 ) )

Comments

#Comment by MarkAHershberger (talk | contribs)   01:55, 20 April 2011

Why use -1 instead of 0? The way it is now, you allow them to specify 0 which would be pretty meaningless.

#Comment by 😂 (talk | contribs)   01:59, 20 April 2011

0 wouldn't trigger it, but I agree -1 isn't the most clear value.

#Comment by Bawolff (talk | contribs)   20:47, 7 May 2011

Specifying any of '0', '-1', or any non-numeric string disables it. Users can just specify ?hourcount=none to disable that, since its a non-numeric string.

Status & tagging log