r84194 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84193‎ | r84194 | r84195 >
Date:18:55, 17 March 2011
Author:bawolff
Status:ok
Tags:
Comment:
There's a lot of parameters in this extension that are include, exclude or only.
Make the getParam method use class constants to represent these. I suppose it doesn't matter,
but this feels nicer to me.
Modified paths:
  • /trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php
@@ -28,6 +28,10 @@
2929
3030 var $maxCacheTime = 43200; // 12 hours. Chosen rather arbitrarily for now. Might want to tweak.
3131
 32+ const OPT_INCLUDE = 0;
 33+ const OPT_ONLY = 1;
 34+ const OPT_EXCLUDE = 2;
 35+
3236 /**
3337 * Constructor
3438 **/
@@ -267,35 +271,35 @@
268272 // If flagged revisions is in use, check which options selected.
269273 // FIXME: double check the default options; what should it default to?
270274 if ( function_exists( 'efLoadFlaggedRevs' ) ) {
271 - $filterSet = array( 'only', 'exclude' );
 275+ $filterSet = array( self::OPT_ONLY, self::OPT_EXCLUDE );
272276 # Either involves the same JOIN here...
273277 if ( in_array( $params['stable'], $filterSet ) || in_array( $params['quality'], $filterSet ) ) {
274278 $joins['flaggedpages'] = array( 'LEFT JOIN', 'page_id = fp_page_id' );
275279 }
276280
277281 switch( $params['stable'] ) {
278 - case 'only':
 282+ case self::OPT_ONLY:
279283 $conditions[] = 'fp_stable IS NOT NULL ';
280284 break;
281 - case 'exclude':
 285+ case self::OPT_EXCLUDE:
282286 $conditions['fp_stable'] = null;
283287 break;
284288 }
285289 switch( $params['quality'] ) {
286 - case 'only':
 290+ case self::OPT_ONLY:
287291 $conditions[] = 'fp_quality >= 1';
288292 break;
289 - case 'exclude':
 293+ case self::OPT_EXCLUDE:
290294 $conditions['fp_quality'] = 0;
291295 break;
292296 }
293297 }
294298
295299 switch ( $params['redirects'] ) {
296 - case 'only':
 300+ case self::OPT_ONLY:
297301 $conditions['page_is_redirect'] = 1;
298302 break;
299 - case 'exclude':
 303+ case self::OPT_EXCLUDE:
300304 $conditions['page_is_redirect'] = 0;
301305 break;
302306 }
@@ -389,9 +393,12 @@
390394
391395 $params['order'] = $wgRequest->getVal( 'order', 'descending' );
392396 $params['orderMethod'] = $wgRequest->getVal( 'ordermethod', 'categoryadd' );
393 - $params['redirects'] = $wgRequest->getVal( 'redirects', 'exclude' );
394 - $params['stable'] = $wgRequest->getVal( 'stable', 'only' );
395 - $params['quality'] = $wgRequest->getVal( 'qualitypages', 'only' );
 397+
 398+ $params['redirects'] = $this->getIEOVal( 'redirects', self::OPT_EXCLUDE );
 399+ $params['stable'] = $this->getIEOVal( 'stable', self::OPT_ONLY );
 400+ $params['quality'] = $this->getIEOVal( 'qualitypages', self::OPT_ONLY );
 401+
 402+ // feed parameter is validated later in the execute method.
396403 $params['feed'] = $wgRequest->getVal( 'feed', 'sitemap' );
397404
398405 $params['catCount'] = count( $categories );
@@ -417,7 +424,29 @@
418425 }
419426 return array( $params, $categories, $notCategories );
420427 }
 428+
421429 /**
 430+ * Turn an include, exclude, or only (I, E, or O) parameter into
 431+ * a class constant.
 432+ * @param $val String the name of the url parameter
 433+ * @param $default Integer Class constant to return if none match
 434+ * @return Integer Class constant corresponding to value.
 435+ */
 436+ private function getIEOVal ( $valName, $default = self::OPT_INCLUDE ) {
 437+ global $wgRequest;
 438+ $val = $wgRequest->getVal( $valName );
 439+ switch ( $val ) {
 440+ case 'only':
 441+ return self::OPT_ONLY;
 442+ case 'include':
 443+ return self::OPT_INCLUDE;
 444+ case 'exclude':
 445+ return self::OPT_EXCLUDE;
 446+ default:
 447+ return $default;
 448+ }
 449+ }
 450+ /**
422451 * Decode the namespace url parameter.
423452 * @param $ns String Either numeric ns number, ns name, or special value :all:
424453 * @return Mixed Integer or false Namespace number or false for no ns filtering.

Status & tagging log