MediaWiki  master
SpecialMostLinkedTemplates.php
Go to the documentation of this file.
1 <?php
25 namespace MediaWiki\Specials;
26 
34 use Skin;
35 use stdClass;
39 
47 
48  private LinksMigration $linksMigration;
49 
55  public function __construct(
56  IConnectionProvider $dbProvider,
57  LinkBatchFactory $linkBatchFactory,
58  LinksMigration $linksMigration
59  ) {
60  parent::__construct( 'Mostlinkedtemplates' );
61  $this->setDatabaseProvider( $dbProvider );
62  $this->setLinkBatchFactory( $linkBatchFactory );
63  $this->linksMigration = $linksMigration;
64  }
65 
71  public function isExpensive() {
72  return true;
73  }
74 
80  public function isSyndicated() {
81  return false;
82  }
83 
89  public function sortDescending() {
90  return true;
91  }
92 
93  public function getQueryInfo() {
94  $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
95  [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' );
96  return [
97  'tables' => $queryInfo['tables'],
98  'fields' => [
99  'namespace' => $ns,
100  'title' => $title,
101  'value' => 'COUNT(*)'
102  ],
103  'options' => [ 'GROUP BY' => [ $ns, $title ] ],
104  'join_conds' => $queryInfo['joins']
105  ];
106  }
107 
114  public function preprocessResults( $db, $res ) {
115  $this->executeLBFromResultWrapper( $res );
116  }
117 
125  public function formatResult( $skin, $result ) {
126  $title = Title::makeTitleSafe( $result->namespace, $result->title );
127  if ( !$title ) {
128  return Html::element(
129  'span',
130  [ 'class' => 'mw-invalidtitle' ],
132  $this->getContext(),
133  $result->namespace,
134  $result->title
135  )
136  );
137  }
138 
139  return $this->getLanguage()->specialList(
140  $this->getLinkRenderer()->makeLink( $title ),
141  $this->makeWlhLink( $title, $result )
142  );
143  }
144 
152  private function makeWlhLink( $title, $result ) {
153  $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
154  $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text();
155 
156  return $this->getLinkRenderer()->makeLink( $wlh, $label );
157  }
158 
159  protected function getGroupName() {
160  return 'highuse';
161  }
162 }
163 
168 class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' );
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
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:88
setDatabaseProvider(IConnectionProvider $databaseProvider)
Definition: QueryPage.php:985
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
Parent class for all special pages.
Definition: SpecialPage.php:65
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.
Special page lists templates with a large number of transclusion links, i.e.
isExpensive()
Is this report expensive, i.e should it be cached?
preprocessResults( $db, $res)
Pre-cache page existence to speed up link generation.
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
sortDescending()
Sort the results in descending order?
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: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.