MediaWiki  master
SpecialMostLinked.php
Go to the documentation of this file.
1 <?php
32 
39 
44  public function __construct(
47  ) {
48  parent::__construct( 'Mostlinked' );
49  $this->setDBLoadBalancer( $loadBalancer );
50  $this->setLinkBatchFactory( $linkBatchFactory );
51  }
52 
53  public function isExpensive() {
54  return true;
55  }
56 
57  public function isSyndicated() {
58  return false;
59  }
60 
61  public function getQueryInfo() {
62  return [
63  'tables' => [ 'pagelinks', 'page' ],
64  'fields' => [
65  'namespace' => 'pl_namespace',
66  'title' => 'pl_title',
67  'value' => 'COUNT(*)',
68  'page_namespace'
69  ],
70  'options' => [
71  'HAVING' => 'COUNT(*) > 1',
72  'GROUP BY' => [
73  'pl_namespace', 'pl_title',
74  'page_namespace'
75  ]
76  ],
77  'join_conds' => [
78  'page' => [
79  'LEFT JOIN',
80  [
81  'page_namespace = pl_namespace',
82  'page_title = pl_title'
83  ]
84  ]
85  ]
86  ];
87  }
88 
95  public function preprocessResults( $db, $res ) {
97  }
98 
106  private function makeWlhLink( $title, $caption ) {
107  $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
108 
109  $linkRenderer = $this->getLinkRenderer();
110  return $linkRenderer->makeKnownLink( $wlh, $caption );
111  }
112 
121  public function formatResult( $skin, $result ) {
122  $title = Title::makeTitleSafe( $result->namespace, $result->title );
123  if ( !$title ) {
124  return Html::element(
125  'span',
126  [ 'class' => 'mw-invalidtitle' ],
128  $this->getContext(),
129  $result->namespace,
130  $result->title )
131  );
132  }
133 
134  $linkRenderer = $this->getLinkRenderer();
135  $link = $linkRenderer->makeLink( $title );
136  $wlh = $this->makeWlhLink(
137  $title,
138  $this->msg( 'nlinks' )->numParams( $result->value )->text()
139  );
140 
141  return $this->getLanguage()->specialList( $link, $wlh );
142  }
143 
144  protected function getGroupName() {
145  return 'highuse';
146  }
147 }
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialMostLinked\preprocessResults
preprocessResults( $db, $res)
Pre-fill the link cache.
Definition: SpecialMostLinked.php:95
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
SpecialMostLinked\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialMostLinked.php:61
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:107
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:185
$res
$res
Definition: testCompression.php:57
QueryPage
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:41
QueryPage\executeLBFromResultWrapper
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:874
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:135
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
SpecialMostLinked\formatResult
formatResult( $skin, $result)
Make links to the page corresponding to the item, and the "what links here" page for it.
Definition: SpecialMostLinked.php:121
$title
$title
Definition: testCompression.php:38
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:764
SpecialMostLinked
A special page to show pages ordered by the number of pages linking to them.
Definition: SpecialMostLinked.php:38
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:689
SpecialMostLinked\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialMostLinked.php:144
SpecialMostLinked\__construct
__construct(ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
Definition: SpecialMostLinked.php:44
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
SpecialMostLinked\isSyndicated
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
Definition: SpecialMostLinked.php:57
SpecialMostLinked\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialMostLinked.php:53
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
SpecialMostLinked\makeWlhLink
makeWlhLink( $title, $caption)
Make a link to "what links here" for the specified title.
Definition: SpecialMostLinked.php:106
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81