| 1 |
<?php |
| 2 |
|
| 3 |
ason |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Specials; |
| 24 |
|
| 25 |
use HtmlArmor; |
| 26 |
use MediaWiki\Cache\LinkBatchFactory; |
| 27 |
use MediaWiki\Language\ILanguageConverter; |
| 28 |
use MediaWiki\Languages\LanguageConverterFactory; |
| 29 |
use MediaWiki\SpecialPage\WantedQueryPage; |
| 30 |
use MediaWiki\Title\Title; |
| 31 |
use Skin; |
| 32 |
use stdClass; |
| 33 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class SpecialWantedCategories extends WantedQueryPage { |
| 41 |
|
| 42 |
private $currentCategoryCounts; |
| 43 |
|
| 44 |
private ILanguageConverter $languageConverter; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function __construct( |
| 52 |
IConnectionProvider $dbProvider, |
| 53 |
LinkBatchFactory $linkBatchFactory, |
| 54 |
LanguageConverterFactory $languageConverterFactory |
| 55 |
) { |
| 56 |
parent::__construct( 'Wantedcategories' ); |
| 57 |
$this->setDatabaseProvider( $dbProvider ); |
| 58 |
$this->setLinkBatchFactory( $linkBatchFactory ); |
| 59 |
$this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ); |
| 60 |
} |
| 61 |
|
| 62 |
public function getQueryInfo() { |
| 63 |
return [ |
| 64 |
'tables' => [ 'categorylinks', 'page' ], |
| 65 |
'fields' => [ |
| 66 |
'namespace' => NS_CATEGORY, |
| 67 |
'title' => 'cl_to', |
| 68 |
'value' => 'COUNT(*)' |
| 69 |
], |
| 70 |
'conds' => [ 'page_title' => null ], |
| 71 |
'options' => [ 'GROUP BY' => 'cl_to' ], |
| 72 |
'join_conds' => [ 'page' => [ 'LEFT JOIN', |
| 73 |
[ 'page_title = cl_to', |
| 74 |
'page_namespace' => NS_CATEGORY ] ] ] |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
public function preprocessResults( $db, $res ) { |
| 79 |
parent::preprocessResults( $db, $res ); |
| 80 |
|
| 81 |
$this->currentCategoryCounts = []; |
| 82 |
|
| 83 |
if ( !$res->numRows() || !$this->isCached() ) { |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
$allCategories = []; |
| 91 |
foreach ( $res as $row ) { |
| 92 |
$allCategories[] = $row->title; |
| 93 |
} |
| 94 |
|
| 95 |
$categoryRes = $db->newSelectQueryBuilder() |
| 96 |
->select( [ 'cat_title', 'cat_pages' ] ) |
| 97 |
->from( 'category' ) |
| 98 |
->where( [ 'cat_title' => $allCategories ] ) |
| 99 |
->caller( __METHOD__ )->fetchResultSet(); |
| 100 |
foreach ( $categoryRes as $row ) { |
| 101 |
$this->currentCategoryCounts[$row->cat_title] = intval( $row->cat_pages ); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
$res->seek( 0 ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public function formatResult( $skin, $result ) { |
| 114 |
$nt = Title::makeTitle( $result->namespace, $result->title ); |
| 115 |
|
| 116 |
$text = new HtmlArmor( $this->languageConverter->convertHtml( $nt->getText() ) ); |
| 117 |
|
| 118 |
if ( !$this->isCached() ) { |
| 119 |
|
| 120 |
$plink = $this->getLinkRenderer()->makeBrokenLink( |
| 121 |
$nt, |
| 122 |
$text |
| 123 |
); |
| 124 |
$nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); |
| 125 |
} else { |
| 126 |
$plink = $this->getLinkRenderer()->makeLink( $nt, $text ); |
| 127 |
|
| 128 |
$currentValue = $this->currentCategoryCounts[$result->title] ?? 0; |
| 129 |
$cachedValue = intval( $result->value ); |
| 130 |
|
| 131 |
|
| 132 |
if ( $nt->isKnown() || $currentValue === 0 ) { |
| 133 |
$plink = "<del>$plink</del>"; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
if ( $currentValue !== $cachedValue ) { |
| 138 |
$nlinks = $this->msg( 'nmemberschanged' ) |
| 139 |
->numParams( $cachedValue, $currentValue )->escaped(); |
| 140 |
} else { |
| 141 |
$nlinks = $this->msg( 'nmembers' )->numParams( $cachedValue )->escaped(); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
return $this->getLanguage()->specialList( $plink, $nlinks ); |
| 146 |
} |
| 147 |
|
| 148 |
protected function getGroupName() { |
| 149 |
return 'maintenance'; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
class_alias( SpecialWantedCategories::class, 'SpecialWantedCategories' ); |