Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -28,6 +28,10 @@ |
29 | 29 | |
30 | 30 | var $maxCacheTime = 43200; // 12 hours. Chosen rather arbitrarily for now. Might want to tweak. |
31 | 31 | |
| 32 | + const OPT_INCLUDE = 0; |
| 33 | + const OPT_ONLY = 1; |
| 34 | + const OPT_EXCLUDE = 2; |
| 35 | + |
32 | 36 | /** |
33 | 37 | * Constructor |
34 | 38 | **/ |
— | — | @@ -267,35 +271,35 @@ |
268 | 272 | // If flagged revisions is in use, check which options selected. |
269 | 273 | // FIXME: double check the default options; what should it default to? |
270 | 274 | if ( function_exists( 'efLoadFlaggedRevs' ) ) { |
271 | | - $filterSet = array( 'only', 'exclude' ); |
| 275 | + $filterSet = array( self::OPT_ONLY, self::OPT_EXCLUDE ); |
272 | 276 | # Either involves the same JOIN here... |
273 | 277 | if ( in_array( $params['stable'], $filterSet ) || in_array( $params['quality'], $filterSet ) ) { |
274 | 278 | $joins['flaggedpages'] = array( 'LEFT JOIN', 'page_id = fp_page_id' ); |
275 | 279 | } |
276 | 280 | |
277 | 281 | switch( $params['stable'] ) { |
278 | | - case 'only': |
| 282 | + case self::OPT_ONLY: |
279 | 283 | $conditions[] = 'fp_stable IS NOT NULL '; |
280 | 284 | break; |
281 | | - case 'exclude': |
| 285 | + case self::OPT_EXCLUDE: |
282 | 286 | $conditions['fp_stable'] = null; |
283 | 287 | break; |
284 | 288 | } |
285 | 289 | switch( $params['quality'] ) { |
286 | | - case 'only': |
| 290 | + case self::OPT_ONLY: |
287 | 291 | $conditions[] = 'fp_quality >= 1'; |
288 | 292 | break; |
289 | | - case 'exclude': |
| 293 | + case self::OPT_EXCLUDE: |
290 | 294 | $conditions['fp_quality'] = 0; |
291 | 295 | break; |
292 | 296 | } |
293 | 297 | } |
294 | 298 | |
295 | 299 | switch ( $params['redirects'] ) { |
296 | | - case 'only': |
| 300 | + case self::OPT_ONLY: |
297 | 301 | $conditions['page_is_redirect'] = 1; |
298 | 302 | break; |
299 | | - case 'exclude': |
| 303 | + case self::OPT_EXCLUDE: |
300 | 304 | $conditions['page_is_redirect'] = 0; |
301 | 305 | break; |
302 | 306 | } |
— | — | @@ -389,9 +393,12 @@ |
390 | 394 | |
391 | 395 | $params['order'] = $wgRequest->getVal( 'order', 'descending' ); |
392 | 396 | $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. |
396 | 403 | $params['feed'] = $wgRequest->getVal( 'feed', 'sitemap' ); |
397 | 404 | |
398 | 405 | $params['catCount'] = count( $categories ); |
— | — | @@ -417,7 +424,29 @@ |
418 | 425 | } |
419 | 426 | return array( $params, $categories, $notCategories ); |
420 | 427 | } |
| 428 | + |
421 | 429 | /** |
| 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 | + /** |
422 | 451 | * Decode the namespace url parameter. |
423 | 452 | * @param $ns String Either numeric ns number, ns name, or special value :all: |
424 | 453 | * @return Mixed Integer or false Namespace number or false for no ns filtering. |