MediaWiki  master
SpecialMostInterwikis.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Specials;
25 
30 use NamespaceInfo;
31 use QueryPage;
32 use Skin;
33 use stdClass;
37 
44 
46  private $namespaceInfo;
47 
53  public function __construct(
54  NamespaceInfo $namespaceInfo,
55  IConnectionProvider $dbProvider,
56  LinkBatchFactory $linkBatchFactory
57  ) {
58  parent::__construct( 'Mostinterwikis' );
59  $this->namespaceInfo = $namespaceInfo;
60  $this->setDatabaseProvider( $dbProvider );
61  $this->setLinkBatchFactory( $linkBatchFactory );
62  }
63 
64  public function isExpensive() {
65  return true;
66  }
67 
68  public function isSyndicated() {
69  return false;
70  }
71 
72  public function getQueryInfo() {
73  return [
74  'tables' => [
75  'langlinks',
76  'page'
77  ], 'fields' => [
78  'namespace' => 'page_namespace',
79  'title' => 'page_title',
80  'value' => 'COUNT(*)'
81  ], 'conds' => [
82  'page_namespace' => $this->namespaceInfo->getContentNamespaces()
83  ], 'options' => [
84  'HAVING' => 'COUNT(*) > 1',
85  'GROUP BY' => [
86  'page_namespace',
87  'page_title'
88  ]
89  ], 'join_conds' => [
90  'page' => [
91  'LEFT JOIN',
92  'page_id = ll_from'
93  ]
94  ]
95  ];
96  }
97 
104  public function preprocessResults( $db, $res ) {
106  }
107 
113  public function formatResult( $skin, $result ) {
114  $title = Title::makeTitleSafe( $result->namespace, $result->title );
115  if ( !$title ) {
116  return Html::element(
117  'span',
118  [ 'class' => 'mw-invalidtitle' ],
120  $this->getContext(),
121  $result->namespace,
122  $result->title
123  )
124  );
125  }
126 
127  $linkRenderer = $this->getLinkRenderer();
128  if ( $this->isCached() ) {
129  $link = $linkRenderer->makeLink( $title );
130  } else {
131  $link = $linkRenderer->makeKnownLink( $title );
132  }
133 
134  $count = $this->msg( 'ninterwikis' )->numParams( $result->value )->escaped();
135 
136  return $this->getLanguage()->specialList( $link, $count );
137  }
138 
139  protected function getGroupName() {
140  return 'highuse';
141  }
142 }
143 
148 class_alias( SpecialMostInterwikis::class, 'SpecialMostInterwikis' );
This class is a collection of static functions that serve two purposes:
Definition: Html.php:55
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:240
Some internal bits split of from Skin.php.
Definition: Linker.php:67
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:225
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...
Represents a title within MediaWiki.
Definition: Title.php:82
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:719
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
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:65
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition: QueryPage.php:964
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:925
isCached()
Whether or not the output of the page in question is retrieved from the database cache.
Definition: QueryPage.php:337
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:162
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:57
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.
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.