Debian Codegraph @

includes/specials/SpecialLonelyPages.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\Languages\LanguageConverterFactory;
25 use MediaWiki\Linker\LinksMigration;
26 use MediaWiki\SpecialPage\PageQueryPage;
27 use MediaWiki\Title\NamespaceInfo;
28 use Wikimedia\Rdbms\IConnectionProvider;
29
30 /**
31 * List of articles with no article linking to them,
32 * thus being lonely.
33 *
34 * @ingroup SpecialPage
35 */
36 class SpecialLonelyPages extends PageQueryPage {
37
38 private NamespaceInfo $namespaceInfo;
39 private LinksMigration $linksMigration;
40
41 /**
42 * @param NamespaceInfo $namespaceInfo
43 * @param IConnectionProvider $dbProvider
44 * @param LinkBatchFactory $linkBatchFactory
45 * @param LanguageConverterFactory $languageConverterFactory
46 * @param LinksMigration $linksMigration
47 */
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
136 /** @deprecated class alias since 1.41 */
137 class_alias( SpecialLonelyPages::class, 'SpecialLonelyPages' );