r93829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93828‎ | r93829 | r93830 >
Date:14:26, 3 August 2011
Author:flohack
Status:deferred
Tags:
Comment:
Now inheriting from SpecialWatchlist to re-use some code from them
Modified paths:
  • /trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php
@@ -20,9 +20,15 @@
2121 * @file
2222 * @ingroup SpecialPage CollabWatchlist
2323 */
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' );
2733 }
2834
2935 /**
@@ -314,20 +320,20 @@
315321 ) . '<br />';
316322 }
317323
318 - $cutofflinks = "\n" . $this->wlCutoffLinks( $days, 'CollabWatchlist', $nondefaults ) . "<br />\n";
 324+ $cutofflinks = "\n" . self::cutoffLinks( $days, 'CollabWatchlist', $nondefaults ) . "<br />\n";
319325
320326 $thisTitle = SpecialPage::getTitleFor( 'CollabWatchlist' );
321327
322328 # 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 );
329335
330336 if ( $wgUser->useRCPatrol() ) {
331 - $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
 337+ $links[] = self::showHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
332338 }
333339
334340 # Namespace filter and put the whole form together.
@@ -443,114 +449,14 @@
444450 $dbr->freeResult( $res );
445451 $wgOut->addHTML( $s );
446452 }
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 - }
461453
462454 /**
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 - /**
512455 * 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
536456 *
537 - * @param $talk Include talk pages
538 - * @return integer
 457+ * @return string
539458 */
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 );
555461 }
556462
557463 /** Returns an array of maps representing collab watchlist tags. The following fields are present

Follow-up revisions

RevisionCommit summaryAuthorDate
r93833Removed the inversion checkbox, as it was quite useless IMHO; Fixed a bug int...flohack15:38, 3 August 2011

Status & tagging log