SpecialWantedcategories: Show more current information when in cached mode
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 8 Dec 2013 14:39:25 +0000 (15:39 +0100)
committerBrian Wolff <bawolff+wn@gmail.com>
Thu, 12 Dec 2013 18:41:46 +0000 (18:41 +0000)
Usability improvements I thought up when trying to through nearly
500 entries on this page on pl.wp.

* Strike items on the list if the category was created or emptied
  since the last update
* Show current number of items if it's different from the original one

Change-Id: Ifcc534f19fb60732bcd40f75ddca390106ebe28e

includes/specials/SpecialWantedcategories.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index d2ffdb9..c8ba4ac 100644 (file)
@@ -29,6 +29,7 @@
  * @ingroup SpecialPage
  */
 class WantedCategoriesPage extends WantedQueryPage {
+       private $currentCategoryCounts;
 
        function __construct( $name = 'Wantedcategories' ) {
                parent::__construct( $name );
@@ -48,6 +49,37 @@ class WantedCategoriesPage extends WantedQueryPage {
                );
        }
 
+       function preprocessResults( $db, $res ) {
+               parent::preprocessResults( $db, $res );
+
+               $this->currentCategoryCounts = array();
+
+               if ( !$res->numRows() || !$this->isCached() ) {
+                       return;
+               }
+
+               // Fetch (hopefully) up-to-date numbers of pages in each category.
+               // This should be fast enough as we limit the list to a reasonable length.
+
+               $allCategories = array();
+               foreach ( $res as $row ) {
+                       $allCategories[] = $row->title;
+               }
+
+               $categoryRes = $db->select(
+                       'category',
+                       array( 'cat_title', 'cat_pages' ),
+                       array( 'cat_title' => $allCategories ),
+                       __METHOD__
+               );
+               foreach ( $categoryRes as $row ) {
+                       $this->currentCategoryCounts[ $row->cat_title ] = $row->cat_pages;
+               }
+
+               // Back to start for display
+               $res->seek( 0 );
+       }
+
        /**
         * @param Skin $skin
         * @param object $result Result row
@@ -59,17 +91,37 @@ class WantedCategoriesPage extends WantedQueryPage {
                $nt = Title::makeTitle( $result->namespace, $result->title );
                $text = htmlspecialchars( $wgContLang->convert( $nt->getText() ) );
 
-               $plink = $this->isCached() ?
-                       Linker::link( $nt, $text ) :
-                       Linker::link(
+               if ( !$this->isCached() ) {
+                       // We can assume the freshest data
+                       $plink = Linker::link(
                                $nt,
                                $text,
                                array(),
                                array(),
                                array( 'broken' )
                        );
+                       $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
+               } else {
+                       $plink = Linker::link( $nt, $text );
+
+                       $currentValue = isset( $this->currentCategoryCounts[ $result->title ] )
+                               ? $this->currentCategoryCounts[ $result->title ]
+                               : 0;
+
+                       // If the category has been created or emptied since the list was refreshed, strike it
+                       if ( $nt->isKnown() || $currentValue === 0 ) {
+                               $plink = "<del>$plink</del>";
+                       }
+
+                       // Show the current number of category entries if it changed
+                       if ( $currentValue !== $result->value ) {
+                               $nlinks = $this->msg( 'nmemberschanged' )
+                                       ->numParams( $result->value, $currentValue )->escaped();
+                       } else {
+                               $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
+                       }
+               }
 
-               $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
                return $this->getLanguage()->specialList( $plink, $nlinks );
        }
 
index c5b328b..f3e1fb4 100644 (file)
@@ -2685,6 +2685,7 @@ It now redirects to [[$2]].',
 'ninterwikis'                     => '$1 {{PLURAL:$1|interwiki|interwikis}}',
 'nlinks'                          => '$1 {{PLURAL:$1|link|links}}',
 'nmembers'                        => '$1 {{PLURAL:$1|member|members}}',
+'nmemberschanged'                 => '$1 → $2 {{PLURAL:$2|member|members}}',
 'nrevisions'                      => '$1 {{PLURAL:$1|revision|revisions}}',
 'nviews'                          => '$1 {{PLURAL:$1|view|views}}',
 'nimagelinks'                     => 'Used on $1 {{PLURAL:$1|page|pages}}',
index 74922a6..4304736 100644 (file)
@@ -4849,6 +4849,7 @@ Parameters:
 * $1 - the number of interwiki links",
 'nlinks' => 'This appears in brackets after each entry on the special page [[Special:MostLinked]]. $1 is the number of wiki links.',
 'nmembers' => 'Appears in brackets after each category listed on the special page [[Special:WantedCategories]]. $1 is the number of members of the category.',
+'nmemberschanged' => 'Appears in brackets after each category listed on the special page [[Special:WantedCategories]] if the number of pages in the category has changed since the list was last refreshed. $1 is the original number of members of the category, $2 is the current one.',
 'nrevisions' => 'Used as link text in [[Special:FewestRevisions]].
 
 The link points to the page history (action=history).
index 4a5145f..aeb9453 100644 (file)
@@ -1743,6 +1743,7 @@ $wgMessageStructure = array(
                'ninterwikis',
                'nlinks',
                'nmembers',
+               'nmemberschanged',
                'nrevisions',
                'nviews',
                'nimagelinks',