MediaWiki  master
SpecialWantedfiles.php
Go to the documentation of this file.
1 <?php
31 
38 
40  private $repoGroup;
41 
47  public function __construct(
48  $repoGroup,
51  ) {
52  parent::__construct( is_string( $repoGroup ) ? $repoGroup : 'Wantedfiles' );
53  // This class is extended and therefor fallback to global state - T265301
54  $services = MediaWikiServices::getInstance();
55  $this->repoGroup = $repoGroup instanceof RepoGroup
56  ? $repoGroup
57  : $services->getRepoGroup();
58  $this->setDBLoadBalancer( $loadBalancer ?? $services->getDBLoadBalancer() );
59  $this->setLinkBatchFactory( $linkBatchFactory ?? $services->getLinkBatchFactory() );
60  }
61 
62  protected function getPageHeader() {
63  # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
64  # category would be used on main namespace pages, for those tricky wikipedia
65  # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
66  $catMessage = $this->msg( 'broken-file-category' )
67  ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
68  ->inContentLanguage();
69 
70  if ( !$catMessage->isDisabled() ) {
71  $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
72  } else {
73  $category = false;
74  }
75 
76  $noForeign = '';
77  if ( !$this->likelyToHaveFalsePositives() ) {
78  // Additional messages for grep:
79  // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
80  $noForeign = '-noforeign';
81  }
82 
83  if ( $category ) {
84  return $this
85  ->msg( 'wantedfiletext-cat' . $noForeign )
86  ->params( $category->getFullText() )
87  ->parseAsBlock();
88  } else {
89  return $this
90  ->msg( 'wantedfiletext-nocat' . $noForeign )
91  ->parseAsBlock();
92  }
93  }
94 
103  protected function likelyToHaveFalsePositives() {
104  return $this->repoGroup->hasForeignRepos();
105  }
106 
117  protected function forceExistenceCheck() {
118  return true;
119  }
120 
130  protected function existenceCheck( Title $title ) {
131  return (bool)$this->repoGroup->findFile( $title );
132  }
133 
134  public function getQueryInfo() {
135  return [
136  'tables' => [
137  'imagelinks',
138  'page',
139  'redirect',
140  'img1' => 'image',
141  'img2' => 'image',
142  ],
143  'fields' => [
144  'namespace' => NS_FILE,
145  'title' => 'il_to',
146  'value' => 'COUNT(*)'
147  ],
148  'conds' => [
149  'img1.img_name' => null,
150  // We also need to exclude file redirects
151  'img2.img_name' => null,
152  ],
153  'options' => [ 'GROUP BY' => 'il_to' ],
154  'join_conds' => [
155  'img1' => [ 'LEFT JOIN',
156  'il_to = img1.img_name'
157  ],
158  'page' => [ 'LEFT JOIN', [
159  'il_to = page_title',
160  'page_namespace' => NS_FILE,
161  ] ],
162  'redirect' => [ 'LEFT JOIN', [
163  'page_id = rd_from',
164  'rd_namespace' => NS_FILE,
165  'rd_interwiki' => ''
166  ] ],
167  'img2' => [ 'LEFT JOIN',
168  'rd_title = img2.img_name'
169  ]
170  ]
171  ];
172  }
173 
174  protected function getGroupName() {
175  return 'maintenance';
176  }
177 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:912
WantedFilesPage\getPageHeader
getPageHeader()
The content returned by this function will be output before any result.
Definition: SpecialWantedfiles.php:62
WantedFilesPage\$repoGroup
RepoGroup $repoGroup
Definition: SpecialWantedfiles.php:40
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
WantedFilesPage\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialWantedfiles.php:174
WantedFilesPage\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialWantedfiles.php:134
WantedFilesPage\__construct
__construct( $repoGroup, ILoadBalancer $loadBalancer=null, LinkBatchFactory $linkBatchFactory=null)
Definition: SpecialWantedfiles.php:47
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
QueryPage\setLinkBatchFactory
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:135
WantedFilesPage\likelyToHaveFalsePositives
likelyToHaveFalsePositives()
Whether foreign repos are likely to cause false positives.
Definition: SpecialWantedfiles.php:103
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
$title
$title
Definition: testCompression.php:38
WantedFilesPage\forceExistenceCheck
forceExistenceCheck()
KLUGE: The results may contain false positives for files that exist e.g.
Definition: SpecialWantedfiles.php:117
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:692
WantedFilesPage\existenceCheck
existenceCheck(Title $title)
Does the file exist?
Definition: SpecialWantedfiles.php:130
QueryPage\setDBLoadBalancer
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:892
QueryPage\$linkBatchFactory
LinkBatchFactory null $linkBatchFactory
Definition: QueryPage.php:74
Title
Represents a title within MediaWiki.
Definition: Title.php:47
WantedFilesPage
Querypage that lists the most wanted files.
Definition: SpecialWantedfiles.php:37
Page\PageReferenceValue
Immutable value object representing a page reference.
Definition: PageReferenceValue.php:42
RepoGroup
Prioritized list of file repositories.
Definition: RepoGroup.php:32
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
QueryPage\$loadBalancer
ILoadBalancer null $loadBalancer
Definition: QueryPage.php:71
NS_FILE
const NS_FILE
Definition: Defines.php:70
WantedQueryPage
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
Definition: WantedQueryPage.php:33
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81