MediaWiki master
SpecialLonelyPages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
29
37
38 private NamespaceInfo $namespaceInfo;
39 private LinksMigration $linksMigration;
40
48 public function __construct(
49 NamespaceInfo $namespaceInfo,
50 IConnectionProvider $dbProvider,
51 LinkBatchFactory $linkBatchFactory,
52 LanguageConverterFactory $languageConverterFactory,
53 LinksMigration $linksMigration
54 ) {
55 parent::__construct( 'Lonelypages' );
56 $this->namespaceInfo = $namespaceInfo;
57 $this->setDatabaseProvider( $dbProvider );
58 $this->setLinkBatchFactory( $linkBatchFactory );
59 $this->setLanguageConverter( $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ) );
60 $this->linksMigration = $linksMigration;
61 }
62
63 protected function getPageHeader() {
64 return $this->msg( 'lonelypagestext' )->parseAsBlock();
65 }
66
67 protected function sortDescending() {
68 return false;
69 }
70
71 public function isExpensive() {
72 return true;
73 }
74
75 public function isSyndicated() {
76 return false;
77 }
78
79 public function getQueryInfo() {
80 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks', 'pagelinks', 'LEFT JOIN' );
81 $tables = [ 'page', 'linktarget', 'templatelinks', 'pagelinks' ];
82 $conds = [
83 'pl_from' => null,
84 'page_namespace' => $this->namespaceInfo->getContentNamespaces(),
85 'page_is_redirect' => 0,
86 'tl_from' => null,
87 ];
88 $joinConds = [
89 'templatelinks' => [ 'LEFT JOIN', [ 'tl_target_id=lt_id' ] ],
90 'linktarget' => [
91 'LEFT JOIN', [
92 "lt_namespace = page_namespace",
93 "lt_title = page_title"
94 ]
95 ]
96 ];
97
98 if ( !in_array( 'linktarget', $queryInfo['tables'] ) ) {
99 $joinConds['pagelinks'] = [
100 'LEFT JOIN', [
101 "pl_namespace = page_namespace",
102 "pl_title = page_title"
103 ]
104 ];
105 }
106
107 // Allow extensions to modify the query
108 $this->getHookRunner()->onLonelyPagesQuery( $tables, $conds, $joinConds );
109
110 return [
111 'tables' => $tables,
112 'fields' => [
113 'namespace' => 'page_namespace',
114 'title' => 'page_title',
115 ],
116 'conds' => $conds,
117 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] )
118 ];
119 }
120
121 protected function getOrderFields() {
122 // For some crazy reason ordering by a constant
123 // causes a filesort in MySQL 5
124 if ( count( $this->namespaceInfo->getContentNamespaces() ) > 1 ) {
125 return [ 'page_namespace', 'page_title' ];
126 } else {
127 return [ 'page_title' ];
128 }
129 }
130
131 protected function getGroupName() {
132 return 'maintenance';
133 }
134}
135
137class_alias( SpecialLonelyPages::class, 'SpecialLonelyPages' );
An interface for creating language converters.
getLanguageConverter( $language=null)
Provide a LanguageConverter for given language.
Service for compat reading of links tables.
Variant of QueryPage which formats the result as a simple link to the page.
setLanguageConverter(ILanguageConverter $languageConverter)
setDatabaseProvider(IConnectionProvider $databaseProvider)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
List of articles with no article linking to them, thus being lonely.
isExpensive()
Should this query page only be updated offline on large wikis?
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
getPageHeader()
The content returned by this function will be output before any result.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
sortDescending()
Override to sort by increasing values.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.
getOrderFields()
Subclasses return an array of fields to order by here.
__construct(NamespaceInfo $namespaceInfo, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LanguageConverterFactory $languageConverterFactory, LinksMigration $linksMigration)
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Provide primary and replica IDatabase connections.