MediaWiki  master
SpecialWantedfiles.php
Go to the documentation of this file.
1 <?php
30 
37 
39  private $repoGroup;
40 
46  public function __construct(
47  RepoGroup $repoGroup,
48  ILoadBalancer $loadBalancer,
49  LinkBatchFactory $linkBatchFactory
50  ) {
51  parent::__construct( 'Wantedfiles' );
52  $this->repoGroup = $repoGroup;
53  $this->setDBLoadBalancer( $loadBalancer );
54  $this->setLinkBatchFactory( $linkBatchFactory );
55  }
56 
57  protected function getPageHeader() {
58  # Specifically setting to use "Wanted Files" (NS_MAIN) as title, so as to get what
59  # category would be used on main namespace pages, for those tricky wikipedia
60  # admins who like to do {{#ifeq:{{NAMESPACE}}|foo|bar|....}}.
61  $catMessage = $this->msg( 'broken-file-category' )
62  ->page( PageReferenceValue::localReference( NS_MAIN, "Wanted Files" ) )
63  ->inContentLanguage();
64 
65  if ( !$catMessage->isDisabled() ) {
66  $category = Title::makeTitleSafe( NS_CATEGORY, $catMessage->text() );
67  } else {
68  $category = false;
69  }
70 
71  $noForeign = '';
72  if ( !$this->likelyToHaveFalsePositives() ) {
73  // Additional messages for grep:
74  // wantedfiletext-cat-noforeign, wantedfiletext-nocat-noforeign
75  $noForeign = '-noforeign';
76  }
77 
78  if ( $category ) {
79  return $this
80  ->msg( 'wantedfiletext-cat' . $noForeign )
81  ->params( $category->getFullText() )
82  ->parseAsBlock();
83  } else {
84  return $this
85  ->msg( 'wantedfiletext-nocat' . $noForeign )
86  ->parseAsBlock();
87  }
88  }
89 
98  protected function likelyToHaveFalsePositives() {
99  return $this->repoGroup->hasForeignRepos();
100  }
101 
112  protected function forceExistenceCheck() {
113  return true;
114  }
115 
125  protected function existenceCheck( Title $title ) {
126  return (bool)$this->repoGroup->findFile( $title );
127  }
128 
129  public function getQueryInfo() {
130  return [
131  'tables' => [
132  'imagelinks',
133  'page',
134  'redirect',
135  'img1' => 'image',
136  'img2' => 'image',
137  ],
138  'fields' => [
139  'namespace' => NS_FILE,
140  'title' => 'il_to',
141  'value' => 'COUNT(*)'
142  ],
143  'conds' => [
144  'img1.img_name' => null,
145  // We also need to exclude file redirects
146  'img2.img_name' => null,
147  ],
148  'options' => [ 'GROUP BY' => 'il_to' ],
149  'join_conds' => [
150  'img1' => [ 'LEFT JOIN',
151  'il_to = img1.img_name'
152  ],
153  'page' => [ 'LEFT JOIN', [
154  'il_to = page_title',
155  'page_namespace' => NS_FILE,
156  ] ],
157  'redirect' => [ 'LEFT JOIN', [
158  'page_id = rd_from',
159  'rd_namespace' => NS_FILE,
160  'rd_interwiki' => ''
161  ] ],
162  'img2' => [ 'LEFT JOIN',
163  'rd_title = img2.img_name'
164  ]
165  ]
166  ];
167  }
168 
169  protected function getGroupName() {
170  return 'maintenance';
171  }
172 }
const NS_FILE
Definition: Defines.php:70
const NS_MAIN
Definition: Defines.php:64
const NS_CATEGORY
Definition: Defines.php:78
Immutable value object representing a page reference.
setDBLoadBalancer(ILoadBalancer $loadBalancer)
Definition: QueryPage.php:916
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Definition: QueryPage.php:136
Prioritized list of file repositories.
Definition: RepoGroup.php:29
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Represents a title within MediaWiki.
Definition: Title.php:52
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:667
Querypage that lists the most wanted files.
existenceCheck(Title $title)
Does the file exist?
getPageHeader()
The content returned by this function will be output before any result.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
likelyToHaveFalsePositives()
Whether foreign repos are likely to cause false positives.
__construct(RepoGroup $repoGroup, ILoadBalancer $loadBalancer, LinkBatchFactory $linkBatchFactory)
forceExistenceCheck()
KLUGE: The results may contain false positives for files that exist e.g.
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
Create and track the database connections and transactions for a given database cluster.