MediaWiki  master
SpecialMostInterwikis.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Specials;
25 
32 use Skin;
33 use stdClass;
37 
44 
45  private NamespaceInfo $namespaceInfo;
46 
52  public function __construct(
53  NamespaceInfo $namespaceInfo,
54  IConnectionProvider $dbProvider,
55  LinkBatchFactory $linkBatchFactory
56  ) {
57  parent::__construct( 'Mostinterwikis' );
58  $this->namespaceInfo = $namespaceInfo;
59  $this->setDatabaseProvider( $dbProvider );
60  $this->setLinkBatchFactory( $linkBatchFactory );
61  }
62 
63  public function isExpensive() {
64  return true;
65  }
66 
67  public function isSyndicated() {
68  return false;
69  }
70 
71  public function getQueryInfo() {
72  return [
73  'tables' => [
74  'langlinks',
75  'page'
76  ], 'fields' => [
77  'namespace' => 'page_namespace',
78  'title' => 'page_title',
79  'value' => 'COUNT(*)'
80  ], 'conds' => [
81  'page_namespace' => $this->namespaceInfo->getContentNamespaces()
82  ], 'options' => [
83  'HAVING' => 'COUNT(*) > 1',
84  'GROUP BY' => [
85  'page_namespace',
86  'page_title'
87  ]
88  ], 'join_conds' => [
89  'page' => [
90  'LEFT JOIN',
91  'page_id = ll_from'
92  ]
93  ]
94  ];
95  }
96 
103  public function preprocessResults( $db, $res ) {
104  $this->executeLBFromResultWrapper( $res );
105  }
106 
112  public function formatResult( $skin, $result ) {
113  $title = Title::makeTitleSafe( $result->namespace, $result->title );
114  if ( !$title ) {
115  return Html::element(
116  'span',
117  [ 'class' => 'mw-invalidtitle' ],
119  $this->getContext(),
120  $result->namespace,
121  $result->title
122  )
123  );
124  }
125 
126  $linkRenderer = $this->getLinkRenderer();
127  if ( $this->isCached() ) {
128  $link = $linkRenderer->makeLink( $title );
129  } else {
130  $link = $linkRenderer->makeKnownLink( $title );
131  }
132 
133  $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
134 
135  return $this->getLanguage()->specialList( $link, $count );
136  }
137 
138  protected function getGroupName() {
139  return 'highuse';
140  }
141 }
142 
147 class_alias( SpecialMostInterwikis::class, 'SpecialMostInterwikis' );
This class is a collection of static functions that serve two purposes:
Definition: Html.php:57
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:264
Some internal bits split of from Skin.php.
Definition: Linker.php:65
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:229
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition: QueryPage.php:88
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition: QueryPage.php:985
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:360
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
Definition: QueryPage.php:946
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:185
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getLanguage()
Shortcut to get user's language.
A special page that listed pages that have highest interwiki count.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
isExpensive()
Should this query page only be updated offline on large wikis?
__construct(NamespaceInfo $namespaceInfo, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory)
preprocessResults( $db, $res)
Pre-fill the link cache.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Represents a title within MediaWiki.
Definition: Title.php:76
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
The base class for all skins.
Definition: Skin.php:60
Provide primary and replica IDatabase connections.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:36
Result wrapper for grabbing data queried from an IDatabase object.