X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialWantedcategories.php;h=c8ba4acb0720f23843eee0fac6afbab2dabfef34;hb=aa5e15357aab7365815c154fd86bdaa6f968b97a;hp=ecd20cee265193cd171927dded557799c6495432;hpb=a6b161381667de1ffbfc3298e2b1c6496803b03e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialWantedcategories.php b/includes/specials/SpecialWantedcategories.php index ecd20cee26..c8ba4acb07 100644 --- a/includes/specials/SpecialWantedcategories.php +++ b/includes/specials/SpecialWantedcategories.php @@ -29,25 +29,57 @@ * @ingroup SpecialPage */ class WantedCategoriesPage extends WantedQueryPage { + private $currentCategoryCounts; function __construct( $name = 'Wantedcategories' ) { parent::__construct( $name ); } function getQueryInfo() { - return array ( - 'tables' => array ( 'categorylinks', 'page' ), - 'fields' => array ( 'namespace' => NS_CATEGORY, + return array( + 'tables' => array( 'categorylinks', 'page' ), + 'fields' => array( 'namespace' => NS_CATEGORY, 'title' => 'cl_to', 'value' => 'COUNT(*)' ), - 'conds' => array ( 'page_title IS NULL' ), - 'options' => array ( 'GROUP BY' => 'cl_to' ), - 'join_conds' => array ( 'page' => array ( 'LEFT JOIN', - array ( 'page_title = cl_to', + 'conds' => array( 'page_title IS NULL' ), + 'options' => array( 'GROUP BY' => 'cl_to' ), + 'join_conds' => array( 'page' => array( 'LEFT JOIN', + array( 'page_title = cl_to', 'page_namespace' => NS_CATEGORY ) ) ) ); } + 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 = "$plink"; + } + + // 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 ); }