Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| SpecialMostLinked | |
0.00% |
0 / 47 |
|
0.00% |
0 / 9 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
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 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| getRecacheDB | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| makeWlhLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Specials; |
| 10 | |
| 11 | use MediaWiki\Deferred\LinksUpdate\PageLinksTable; |
| 12 | use MediaWiki\Html\Html; |
| 13 | use MediaWiki\Linker\Linker; |
| 14 | use MediaWiki\Linker\LinksMigration; |
| 15 | use MediaWiki\Page\LinkBatchFactory; |
| 16 | use MediaWiki\Skin\Skin; |
| 17 | use MediaWiki\SpecialPage\QueryPage; |
| 18 | use MediaWiki\SpecialPage\SpecialPage; |
| 19 | use MediaWiki\Title\Title; |
| 20 | use stdClass; |
| 21 | use Wikimedia\Rdbms\IConnectionProvider; |
| 22 | use Wikimedia\Rdbms\IReadableDatabase; |
| 23 | use Wikimedia\Rdbms\IResultWrapper; |
| 24 | |
| 25 | /** |
| 26 | * List of pages ordered by the number of pages linking to them. |
| 27 | * |
| 28 | * @ingroup SpecialPage |
| 29 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 30 | * @author Rob Church <robchur@gmail.com> |
| 31 | */ |
| 32 | class SpecialMostLinked extends QueryPage { |
| 33 | |
| 34 | private LinksMigration $linksMigration; |
| 35 | |
| 36 | public function __construct( |
| 37 | IConnectionProvider $dbProvider, |
| 38 | LinkBatchFactory $linkBatchFactory, |
| 39 | LinksMigration $linksMigration |
| 40 | ) { |
| 41 | parent::__construct( 'Mostlinked' ); |
| 42 | $this->setDatabaseProvider( $dbProvider ); |
| 43 | $this->setLinkBatchFactory( $linkBatchFactory ); |
| 44 | $this->linksMigration = $linksMigration; |
| 45 | } |
| 46 | |
| 47 | /** @inheritDoc */ |
| 48 | public function isExpensive() { |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | /** @inheritDoc */ |
| 53 | public function isSyndicated() { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /** @inheritDoc */ |
| 58 | public function getQueryInfo() { |
| 59 | [ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' ); |
| 60 | $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' ); |
| 61 | return [ |
| 62 | 'tables' => $queryInfo['tables'], |
| 63 | 'fields' => [ |
| 64 | 'namespace' => $ns, |
| 65 | 'title' => $title, |
| 66 | 'value' => 'COUNT(*)' |
| 67 | ], |
| 68 | 'options' => [ |
| 69 | 'HAVING' => 'COUNT(*) > 1', |
| 70 | 'GROUP BY' => [ $ns, $title ], |
| 71 | ], |
| 72 | 'join_conds' => $queryInfo['joins'], |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | /** @inheritDoc */ |
| 77 | protected function getRecacheDB() { |
| 78 | return $this->getDatabaseProvider()->getReplicaDatabase( |
| 79 | PageLinksTable::VIRTUAL_DOMAIN, |
| 80 | 'vslow' |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Pre-fill the link cache |
| 86 | * |
| 87 | * @param IReadableDatabase $db |
| 88 | * @param IResultWrapper $res |
| 89 | */ |
| 90 | public function preprocessResults( $db, $res ) { |
| 91 | $this->executeLBFromResultWrapper( $res ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Make a link to "what links here" for the specified title |
| 96 | * |
| 97 | * @param Title $title Title being queried |
| 98 | * @param string $caption Text to display on the link |
| 99 | * @return string |
| 100 | */ |
| 101 | private function makeWlhLink( $title, $caption ) { |
| 102 | $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() ); |
| 103 | |
| 104 | $linkRenderer = $this->getLinkRenderer(); |
| 105 | return $linkRenderer->makeKnownLink( $wlh, $caption ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Make links to the page corresponding to the item, |
| 110 | * and the "what links here" page for it |
| 111 | * |
| 112 | * @param Skin $skin Skin to be used |
| 113 | * @param stdClass $result Result row |
| 114 | * @return string |
| 115 | */ |
| 116 | public function formatResult( $skin, $result ) { |
| 117 | $title = Title::makeTitleSafe( $result->namespace, $result->title ); |
| 118 | if ( !$title ) { |
| 119 | return Html::element( |
| 120 | 'span', |
| 121 | [ 'class' => 'mw-invalidtitle' ], |
| 122 | Linker::getInvalidTitleDescription( |
| 123 | $this->getContext(), |
| 124 | $result->namespace, |
| 125 | $result->title ) |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | $linkRenderer = $this->getLinkRenderer(); |
| 130 | $link = $linkRenderer->makeLink( $title ); |
| 131 | $wlh = $this->makeWlhLink( |
| 132 | $title, |
| 133 | $this->msg( 'nlinks' )->numParams( $result->value )->text() |
| 134 | ); |
| 135 | |
| 136 | return $this->getLanguage()->specialList( $link, $wlh ); |
| 137 | } |
| 138 | |
| 139 | /** @inheritDoc */ |
| 140 | protected function getGroupName() { |
| 141 | return 'highuse'; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Retain the old class name for backwards compatibility. |
| 147 | * @deprecated since 1.41 |
| 148 | */ |
| 149 | class_alias( SpecialMostLinked::class, 'SpecialMostLinked' ); |