Change behavior of Special:Watchlist when user's watchlist is empty
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 22 Dec 2013 13:24:12 +0000 (14:24 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 16 Jan 2014 18:30:16 +0000 (19:30 +0100)
Previously it would display nothing but a message saying that "You
have no items on your watchlist.", not even any information about what
we are looking at or a link to edit watchlist's contents.

Now the full view is displayed, with the old message placed instead of
"N pages on your watchlist, not counting talk pages." at the top.

Change-Id: Ice9be8bb0686c3c20712d814f08a5171380bf45d

includes/specials/SpecialWatchlist.php

index fc48421..c664e31 100644 (file)
@@ -71,14 +71,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $this->outputHeader();
                $this->addModules();
 
-               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
-
-               $this->numItems = $this->countItems( $dbr ); // TODO kill me
-               if ( $this->numItems == 0 ) {
-                       $output->addWikiMsg( 'nowatchlist' );
-                       return;
-               }
-
                // Fetch results, prepare a batch link existence check query
                $conds = $this->buildMainQueryConds( $opts );
                $rows = $this->doMainQuery( $conds, $opts );
@@ -516,18 +508,25 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $form = "";
                $user = $this->getUser();
 
-               # Show watchlist header
+               $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
+               $numItems = $this->countItems( $dbr );
+
+               // Show watchlist header
                $form .= "<p>";
-               $form .= $this->msg( 'watchlist-details' )->numParams( $this->numItems )->parse() . "\n";
-               if ( $wgEnotifWatchlist && $user->getOption( 'enotifwatchlistpages' ) ) {
-                       $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
-               }
-               if ( $wgShowUpdatedMarker ) {
-                       $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
+               if ( $numItems == 0 ) {
+                       $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
+               } else {
+                       $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
+                       if ( $wgEnotifWatchlist && $user->getOption( 'enotifwatchlistpages' ) ) {
+                               $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
+                       }
+                       if ( $wgShowUpdatedMarker ) {
+                               $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
+                       }
                }
                $form .= "</p>";
 
-               if ( $wgShowUpdatedMarker ) {
+               if ( $numItems > 0 && $wgShowUpdatedMarker ) {
                        $form .= Xml::openElement( 'form', array( 'method' => 'post',
                                'action' => $this->getPageTitle()->getLocalURL(),
                                'id' => 'mw-watchlist-resetbutton' ) ) . "\n" .