Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php |
— | — | @@ -20,9 +20,15 @@ |
21 | 21 | * @file |
22 | 22 | * @ingroup SpecialPage CollabWatchlist |
23 | 23 | */ |
24 | | -class SpecialCollabWatchlist extends SpecialPage { |
25 | | - function __construct() { |
26 | | - parent::__construct( 'CollabWatchlist' ); |
| 24 | +class SpecialCollabWatchlist extends SpecialWatchlist { |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor |
| 28 | + */ |
| 29 | + public function __construct(){ |
| 30 | + //XXX That's a nasty, SpecialWatchlist should have a corresponding constructor, |
| 31 | + // or expose the methods we need publicly |
| 32 | + SpecialPage::__construct( 'CollabWatchlist' ); |
27 | 33 | } |
28 | 34 | |
29 | 35 | /** |
— | — | @@ -314,20 +320,20 @@ |
315 | 321 | ) . '<br />'; |
316 | 322 | } |
317 | 323 | |
318 | | - $cutofflinks = "\n" . $this->wlCutoffLinks( $days, 'CollabWatchlist', $nondefaults ) . "<br />\n"; |
| 324 | + $cutofflinks = "\n" . self::cutoffLinks( $days, 'CollabWatchlist', $nondefaults ) . "<br />\n"; |
319 | 325 | |
320 | 326 | $thisTitle = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
321 | 327 | |
322 | 328 | # Spit out some control panel links |
323 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); |
324 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); |
325 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); |
326 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); |
327 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); |
328 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'collabwatchlistshowhidelistusers', 'hideListUser', $hideListUser ); |
| 329 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); |
| 330 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); |
| 331 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons ); |
| 332 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); |
| 333 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); |
| 334 | + $links[] = self::showHideLink( $nondefaults, 'collabwatchlistshowhidelistusers', 'hideListUser', $hideListUser ); |
329 | 335 | |
330 | 336 | if ( $wgUser->useRCPatrol() ) { |
331 | | - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); |
| 337 | + $links[] = self::showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); |
332 | 338 | } |
333 | 339 | |
334 | 340 | # Namespace filter and put the whole form together. |
— | — | @@ -443,114 +449,14 @@ |
444 | 450 | $dbr->freeResult( $res ); |
445 | 451 | $wgOut->addHTML( $s ); |
446 | 452 | } |
447 | | - |
448 | | - function wlShowHideLink( $options, $message, $name, $value ) { |
449 | | - global $wgUser; |
450 | | - |
451 | | - $showLinktext = wfMsgHtml( 'show' ); |
452 | | - $hideLinktext = wfMsgHtml( 'hide' ); |
453 | | - $title = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
454 | | - $skin = $wgUser->getSkin(); |
455 | | - |
456 | | - $label = $value ? $showLinktext : $hideLinktext; |
457 | | - $options[$name] = 1 - (int) $value; |
458 | | - |
459 | | - return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) ); |
460 | | - } |
461 | 453 | |
462 | 454 | /** |
463 | | - * Creates a link for the days query parameter with hours |
464 | | - * @param $h The number of hours |
465 | | - * @param $page String: The name of the target page for the link |
466 | | - * @param $options Mixed: Additional query parameters |
467 | | - * @return String: Html for the link |
468 | | - */ |
469 | | - function wlHoursLink( $h, $page, $options = array() ) { |
470 | | - global $wgUser, $wgLang, $wgContLang; |
471 | | - |
472 | | - $sk = $wgUser->getSkin(); |
473 | | - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
474 | | - $options['days'] = ( $h / 24.0 ); |
475 | | - |
476 | | - $s = $sk->linkKnown( |
477 | | - $title, |
478 | | - $wgLang->formatNum( $h ), |
479 | | - array(), |
480 | | - $options |
481 | | - ); |
482 | | - |
483 | | - return $s; |
484 | | - } |
485 | | - |
486 | | - /** |
487 | | - * Creates a link for the days query parameter with days |
488 | | - * @param $d The number of days |
489 | | - * @param $page String: The name of the target page for the link |
490 | | - * @param $options Mixed: Additional query parameters |
491 | | - * @return String: Html for the link |
492 | | - */ |
493 | | - function wlDaysLink( $d, $page, $options = array() ) { |
494 | | - global $wgUser, $wgLang, $wgContLang; |
495 | | - |
496 | | - $sk = $wgUser->getSkin(); |
497 | | - $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
498 | | - $options['days'] = $d; |
499 | | - $message = ( $d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); |
500 | | - |
501 | | - $s = $sk->linkKnown( |
502 | | - $title, |
503 | | - $message, |
504 | | - array(), |
505 | | - $options |
506 | | - ); |
507 | | - |
508 | | - return $s; |
509 | | - } |
510 | | - |
511 | | - /** |
512 | 455 | * Returns html |
513 | | - */ |
514 | | - function wlCutoffLinks( $days, $page = 'CollabWatchlist', $options = array() ) { |
515 | | - global $wgLang; |
516 | | - |
517 | | - $hours = array( 1, 2, 6, 12 ); |
518 | | - $days = array( 1, 3, 7 ); |
519 | | - $i = 0; |
520 | | - foreach ( $hours as $h ) { |
521 | | - $hours[$i++] = $this->wlHoursLink( $h, $page, $options ); |
522 | | - } |
523 | | - $i = 0; |
524 | | - foreach ( $days as $d ) { |
525 | | - $days[$i++] = $this->wlDaysLink( $d, $page, $options ); |
526 | | - } |
527 | | - return wfMsgExt( 'wlshowlast', |
528 | | - array( 'parseinline', 'replaceafter' ), |
529 | | - $wgLang->pipeList( $hours ), |
530 | | - $wgLang->pipeList( $days ), |
531 | | - $this->wlDaysLink( 0, $page, $options ) ); |
532 | | - } |
533 | | - |
534 | | - /** |
535 | | - * Count the number of items on a user's watchlist |
536 | 456 | * |
537 | | - * @param $talk Include talk pages |
538 | | - * @return integer |
| 457 | + * @return string |
539 | 458 | */ |
540 | | - function wlCountItems( &$user, $talk = true ) { |
541 | | - $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
542 | | - |
543 | | - # Fetch the raw count |
544 | | - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', |
545 | | - array( 'wl_user' => $user->mId ), 'wlCountItems' ); |
546 | | - $row = $dbr->fetchObject( $res ); |
547 | | - $count = $row->count; |
548 | | - $dbr->freeResult( $res ); |
549 | | - |
550 | | - # Halve to remove talk pages if needed |
551 | | - if ( !$talk ) |
552 | | - $count = floor( $count / 2 ); |
553 | | - |
554 | | - return( $count ); |
| 459 | + protected static function cutoffLinks( $days, $page = 'Watchlist', $options = array() ) { |
| 460 | + return SpecialWatchlist::cutoffLinks( $days, $page, $options ); |
555 | 461 | } |
556 | 462 | |
557 | 463 | /** Returns an array of maps representing collab watchlist tags. The following fields are present |