| 1 |
<?php |
| 2 |
|
| 3 |
urch |
| 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 MediaWiki\Cache\LinkBatchFactory; |
| 26 |
use MediaWiki\Html\Html; |
| 27 |
use MediaWiki\Linker\Linker; |
| 28 |
use MediaWiki\Linker\LinksMigration; |
| 29 |
use MediaWiki\SpecialPage\QueryPage; |
| 30 |
use MediaWiki\SpecialPage\SpecialPage; |
| 31 |
use MediaWiki\Title\Title; |
| 32 |
use Skin; |
| 33 |
use stdClass; |
| 34 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 35 |
use Wikimedia\Rdbms\IDatabase; |
| 36 |
use Wikimedia\Rdbms\IResultWrapper; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
om> |
| 43 |
|
| 44 |
|
| 45 |
class SpecialMostLinked extends QueryPage { |
| 46 |
|
| 47 |
private LinksMigration $linksMigration; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function __construct( |
| 55 |
IConnectionProvider $dbProvider, |
| 56 |
LinkBatchFactory $linkBatchFactory, |
| 57 |
LinksMigration $linksMigration |
| 58 |
) { |
| 59 |
parent::__construct( 'Mostlinked' ); |
| 60 |
$this->setDatabaseProvider( $dbProvider ); |
| 61 |
$this->setLinkBatchFactory( $linkBatchFactory ); |
| 62 |
$this->linksMigration = $linksMigration; |
| 63 |
} |
| 64 |
|
| 65 |
public function isExpensive() { |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
public function isSyndicated() { |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
public function getQueryInfo() { |
| 74 |
[ $ns, $title ] = $this->linksMigration->getTitleFields( 'pagelinks' ); |
| 75 |
$queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks' ); |
| 76 |
return [ |
| 77 |
'tables' => $queryInfo['tables'], |
| 78 |
'fields' => [ |
| 79 |
'namespace' => $ns, |
| 80 |
'title' => $title, |
| 81 |
'value' => 'COUNT(*)' |
| 82 |
], |
| 83 |
'options' => [ |
| 84 |
'HAVING' => 'COUNT(*) > 1', |
| 85 |
'GROUP BY' => [ $ns, $title ], |
| 86 |
], |
| 87 |
'join_conds' => $queryInfo['joins'], |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function preprocessResults( $db, $res ) { |
| 98 |
$this->executeLBFromResultWrapper( $res ); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
private function makeWlhLink( $title, $caption ) { |
| 109 |
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() ); |
| 110 |
|
| 111 |
$linkRenderer = $this->getLinkRenderer(); |
| 112 |
return $linkRenderer->makeKnownLink( $wlh, $caption ); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public function formatResult( $skin, $result ) { |
| 124 |
$title = Title::makeTitleSafe( $result->namespace, $result->title ); |
| 125 |
if ( !$title ) { |
| 126 |
return Html::element( |
| 127 |
'span', |
| 128 |
[ 'class' => 'mw-invalidtitle' ], |
| 129 |
Linker::getInvalidTitleDescription( |
| 130 |
$this->getContext(), |
| 131 |
$result->namespace, |
| 132 |
$result->title ) |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
$linkRenderer = $this->getLinkRenderer(); |
| 137 |
$link = $linkRenderer->makeLink( $title ); |
| 138 |
$wlh = $this->makeWlhLink( |
| 139 |
$title, |
| 140 |
$this->msg( 'nlinks' )->numParams( $result->value )->text() |
| 141 |
); |
| 142 |
|
| 143 |
return $this->getLanguage()->specialList( $link, $wlh ); |
| 144 |
} |
| 145 |
|
| 146 |
protected function getGroupName() { |
| 147 |
return 'highuse'; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
class_alias( SpecialMostLinked::class, 'SpecialMostLinked' ); |