MediaWiki  master
SpecialMostLinkedTemplates.php
Go to the documentation of this file.
1 <?php
30 
38 
40  private $linksMigration;
41 
47  public function __construct(
51  ) {
52  parent::__construct( 'Mostlinkedtemplates' );
53  $this->setDBLoadBalancer( $loadBalancer );
54  $this->setLinkBatchFactory( $linkBatchFactory );
55  $this->linksMigration = $linksMigration;
56  }
57 
63  public function isExpensive() {
64  return true;
65  }
66 
72  public function isSyndicated() {
73  return false;
74  }
75 
81  public function sortDescending() {
82  return true;
83  }
84 
85  public function getQueryInfo() {
86  $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
87  list( $ns, $title ) = $this->linksMigration->getTitleFields( 'templatelinks' );
88  return [
89  'tables' => $queryInfo['tables'],
90  'fields' => [
91  'namespace' => $ns,
92  'title' => $title,
93  'value' => 'COUNT(*)'
94  ],
95  'options' => [ 'GROUP BY' => [ $ns, $title ] ],
96  'join_conds' => $queryInfo['joins']
97  ];
98  }
99 
106  public function preprocessResults( $db, $res ) {
108  }
109 
117  public function formatResult( $skin, $result ) {
118  $title = Title::makeTitleSafe( $result->namespace, $result->title );
119  if ( !$title ) {
120  return Html::element(
121  'span',
122  [ 'class' => 'mw-invalidtitle' ],
124  $this->getContext(),
125  $result->namespace,
126  $result->title
127  )
128  );
129  }
130 
131  return $this->getLanguage()->specialList(
132  $this->getLinkRenderer()->makeLink( $title ),
133  $this->makeWlhLink( $title, $result )
134  );
135  }
136 
144  private function makeWlhLink( $title, $result ) {
145  $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
146  $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
147 
148  return $this->getLinkRenderer()->makeLink( $wlh, $label );
149  }
150 
151  protected function getGroupName() {
152  return 'highuse';
153  }
154 }
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:187
Service for compat reading of links tables.
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:42
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:877
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:895
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:75
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:136
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:72
Special page lists templates with a large number of transclusion links, i.e.
sortDescending()
Sort the results in descending order?
preprocessResults( $db, $res)
Pre-cache page existence to speed up link generation.
makeWlhLink( $title, $result)
Make a "what links here" link for a given title.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
isSyndicated()
Is there a feed available?
__construct(ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
isExpensive()
Is this report expensive, i.e should it be cached?
formatResult( $skin, $result)
Format a result row.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
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,...
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.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:664
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:39
Database cluster connection, tracking, load balancing, and transaction manager interface.
Result wrapper for grabbing data queried from an IDatabase object.