Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| SpecialFewestRevisions | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getQueryInfo | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
20 | |||
| preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\Html\Html; |
| 10 | use MediaWiki\Language\ILanguageConverter; |
| 11 | use MediaWiki\Languages\LanguageConverterFactory; |
| 12 | use MediaWiki\Linker\Linker; |
| 13 | use MediaWiki\Page\LinkBatchFactory; |
| 14 | use MediaWiki\Skin\Skin; |
| 15 | use MediaWiki\SpecialPage\QueryPage; |
| 16 | use MediaWiki\Title\NamespaceInfo; |
| 17 | use MediaWiki\Title\Title; |
| 18 | use stdClass; |
| 19 | use Wikimedia\HtmlArmor\HtmlArmor; |
| 20 | use Wikimedia\Rdbms\IConnectionProvider; |
| 21 | use Wikimedia\Rdbms\IReadableDatabase; |
| 22 | use Wikimedia\Rdbms\IResultWrapper; |
| 23 | |
| 24 | /** |
| 25 | * List articles with the fewest revisions. |
| 26 | * |
| 27 | * @ingroup SpecialPage |
| 28 | * @author Martin Drashkov |
| 29 | */ |
| 30 | class SpecialFewestRevisions extends QueryPage { |
| 31 | |
| 32 | private NamespaceInfo $namespaceInfo; |
| 33 | private ILanguageConverter $languageConverter; |
| 34 | |
| 35 | public function __construct( |
| 36 | NamespaceInfo $namespaceInfo, |
| 37 | IConnectionProvider $dbProvider, |
| 38 | LinkBatchFactory $linkBatchFactory, |
| 39 | LanguageConverterFactory $languageConverterFactory |
| 40 | ) { |
| 41 | parent::__construct( 'Fewestrevisions' ); |
| 42 | $this->namespaceInfo = $namespaceInfo; |
| 43 | $this->setDatabaseProvider( $dbProvider ); |
| 44 | $this->setLinkBatchFactory( $linkBatchFactory ); |
| 45 | $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ); |
| 46 | } |
| 47 | |
| 48 | /** @inheritDoc */ |
| 49 | public function isExpensive() { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | /** @inheritDoc */ |
| 54 | public function isSyndicated() { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | /** @inheritDoc */ |
| 59 | public function getQueryInfo() { |
| 60 | return [ |
| 61 | 'tables' => [ 'revision', 'page' ], |
| 62 | 'fields' => [ |
| 63 | 'namespace' => 'page_namespace', |
| 64 | 'title' => 'page_title', |
| 65 | 'value' => 'COUNT(*)', |
| 66 | ], |
| 67 | 'conds' => [ |
| 68 | 'page_namespace' => $this->namespaceInfo->getContentNamespaces(), |
| 69 | 'page_id = rev_page', |
| 70 | 'page_is_redirect' => 0, |
| 71 | ], |
| 72 | 'options' => [ |
| 73 | 'GROUP BY' => [ 'page_namespace', 'page_title' ] |
| 74 | ] |
| 75 | ]; |
| 76 | } |
| 77 | |
| 78 | /** @inheritDoc */ |
| 79 | protected function sortDescending() { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @param Skin $skin |
| 85 | * @param stdClass $result Database row |
| 86 | * @return string |
| 87 | */ |
| 88 | public function formatResult( $skin, $result ) { |
| 89 | $nt = Title::makeTitleSafe( $result->namespace, $result->title ); |
| 90 | if ( !$nt ) { |
| 91 | return Html::element( |
| 92 | 'span', |
| 93 | [ 'class' => 'mw-invalidtitle' ], |
| 94 | Linker::getInvalidTitleDescription( |
| 95 | $this->getContext(), |
| 96 | $result->namespace, |
| 97 | $result->title |
| 98 | ) |
| 99 | ); |
| 100 | } |
| 101 | $linkRenderer = $this->getLinkRenderer(); |
| 102 | |
| 103 | $text = $this->languageConverter->convertHtml( $nt->getPrefixedText() ); |
| 104 | $plink = $linkRenderer->makeLink( $nt, new HtmlArmor( $text ) ); |
| 105 | |
| 106 | $nl = $this->msg( 'nrevisions' )->numParams( $result->value )->text(); |
| 107 | $redirect = isset( $result->redirect ) && $result->redirect ? |
| 108 | ' - ' . $this->msg( 'isredirect' )->escaped() : ''; |
| 109 | $nlink = $linkRenderer->makeKnownLink( |
| 110 | $nt, |
| 111 | $nl, |
| 112 | [], |
| 113 | [ 'action' => 'history' ] |
| 114 | ) . $redirect; |
| 115 | |
| 116 | return $this->getLanguage()->specialList( $plink, $nlink ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Cache page existence for performance |
| 121 | * |
| 122 | * @param IReadableDatabase $db |
| 123 | * @param IResultWrapper $res |
| 124 | */ |
| 125 | protected function preprocessResults( $db, $res ) { |
| 126 | $this->executeLBFromResultWrapper( $res ); |
| 127 | } |
| 128 | |
| 129 | /** @inheritDoc */ |
| 130 | protected function getGroupName() { |
| 131 | return 'maintenance'; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** @deprecated class alias since 1.41 */ |
| 136 | class_alias( SpecialFewestRevisions::class, 'SpecialFewestRevisions' ); |