MediaWiki  1.23.0
WikiFilePage.php
Go to the documentation of this file.
1 <?php
28 class WikiFilePage extends WikiPage {
32  protected $mFile = false; // !< File object
33  protected $mRepo = null; // !<
34  protected $mFileLoaded = false; // !<
35  protected $mDupes = null; // !<
36 
37  public function __construct( $title ) {
38  parent::__construct( $title );
39  $this->mDupes = null;
40  $this->mRepo = null;
41  }
42 
43  public function getActionOverrides() {
44  $overrides = parent::getActionOverrides();
45  $overrides['revert'] = 'RevertFileAction';
46  return $overrides;
47  }
48 
52  public function setFile( $file ) {
53  $this->mFile = $file;
54  $this->mFileLoaded = true;
55  }
56 
60  protected function loadFile() {
61  if ( $this->mFileLoaded ) {
62  return true;
63  }
64  $this->mFileLoaded = true;
65 
66  $this->mFile = wfFindFile( $this->mTitle );
67  if ( !$this->mFile ) {
68  $this->mFile = wfLocalFile( $this->mTitle ); // always a File
69  }
70  $this->mRepo = $this->mFile->getRepo();
71  return true;
72  }
73 
77  public function getRedirectTarget() {
78  $this->loadFile();
79  if ( $this->mFile->isLocal() ) {
80  return parent::getRedirectTarget();
81  }
82  // Foreign image page
83  $from = $this->mFile->getRedirected();
84  $to = $this->mFile->getName();
85  if ( $from == $to ) {
86  return null;
87  }
88  $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
90  }
91 
95  public function followRedirect() {
96  $this->loadFile();
97  if ( $this->mFile->isLocal() ) {
98  return parent::followRedirect();
99  }
100  $from = $this->mFile->getRedirected();
101  $to = $this->mFile->getName();
102  if ( $from == $to ) {
103  return false;
104  }
105  return Title::makeTitle( NS_FILE, $to );
106  }
107 
111  public function isRedirect() {
112  $this->loadFile();
113  if ( $this->mFile->isLocal() ) {
114  return parent::isRedirect();
115  }
116 
117  return (bool)$this->mFile->getRedirected();
118  }
119 
123  public function isLocal() {
124  $this->loadFile();
125  return $this->mFile->isLocal();
126  }
127 
131  public function getFile() {
132  $this->loadFile();
133  return $this->mFile;
134  }
135 
139  public function getDuplicates() {
140  $this->loadFile();
141  if ( !is_null( $this->mDupes ) ) {
142  return $this->mDupes;
143  }
144  $hash = $this->mFile->getSha1();
145  if ( !( $hash ) ) {
146  $this->mDupes = array();
147  return $this->mDupes;
148  }
149  $dupes = RepoGroup::singleton()->findBySha1( $hash );
150  // Remove duplicates with self and non matching file sizes
151  $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
152  $size = $this->mFile->getSize();
153 
157  foreach ( $dupes as $index => $file ) {
158  $key = $file->getRepoName() . ':' . $file->getName();
159  if ( $key == $self ) {
160  unset( $dupes[$index] );
161  }
162  if ( $file->getSize() != $size ) {
163  unset( $dupes[$index] );
164  }
165  }
166  $this->mDupes = $dupes;
167  return $this->mDupes;
168  }
169 
174  public function doPurge() {
175  $this->loadFile();
176  if ( $this->mFile->exists() ) {
177  wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
178  $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
179  $update->doUpdate();
180  $this->mFile->upgradeRow();
181  $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
182  } else {
183  wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile->getName() . "; limiting purge to cache only\n" );
184  // even if the file supposedly doesn't exist, force any cached information
185  // to be updated (in case the cached information is wrong)
186  $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
187  }
188  if ( $this->mRepo ) {
189  // Purge redirect cache
190  $this->mRepo->invalidateImageRedirect( $this->mTitle );
191  }
192  return parent::doPurge();
193  }
194 
204  public function getForeignCategories() {
205  $this->loadFile();
208 
209  if ( ! $file instanceof LocalFile ) {
210  wfDebug( __CLASS__ . '::' . __METHOD__ . " is not supported for this file\n" );
212  }
213 
215  $repo = $file->getRepo();
216  $dbr = $repo->getSlaveDB();
217 
218  $res = $dbr->select(
219  array( 'page', 'categorylinks' ),
220  array(
221  'page_title' => 'cl_to',
222  'page_namespace' => NS_CATEGORY,
223  ),
224  array(
225  'page_namespace' => $title->getNamespace(),
226  'page_title' => $title->getDBkey(),
227  ),
228  __METHOD__,
229  array(),
230  array( 'categorylinks' => array( 'INNER JOIN', 'page_id = cl_from' ) )
231  );
232 
234  }
235 }
FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: DatabaseUtility.php:230
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
TitleArray\newFromResult
static newFromResult( $res)
Definition: TitleArray.php:38
WikiFilePage\followRedirect
followRedirect()
Definition: WikiFilePage.php:94
$from
$from
Definition: importImages.php:90
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
NS_FILE
const NS_FILE
Definition: Defines.php:85
WikiFilePage\getFile
getFile()
Definition: WikiFilePage.php:130
WikiPage\$mTitle
Title $mTitle
Definition: WikiPage.php:42
$dbr
$dbr
Definition: testCompression.php:48
WikiFilePage\$mFileLoaded
$mFileLoaded
Definition: WikiFilePage.php:33
WikiFilePage\$mFile
File $mFile
Definition: WikiFilePage.php:31
WikiFilePage\setFile
setFile( $file)
Definition: WikiFilePage.php:51
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
WikiPage\$mRedirectTarget
Title $mRedirectTarget
Definition: WikiPage.php:65
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:46
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
HTMLCacheUpdate
Class to invalidate the HTML cache of all the pages linking to a given title.
Definition: HTMLCacheUpdate.php:29
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
WikiFilePage\__construct
__construct( $title)
Definition: WikiFilePage.php:36
WikiFilePage\loadFile
loadFile()
Definition: WikiFilePage.php:59
$size
$size
Definition: RandomTest.php:75
WikiFilePage\$mRepo
$mRepo
Definition: WikiFilePage.php:32
$hash
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks & $hash
Definition: hooks.txt:2697
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
WikiFilePage\getDuplicates
getDuplicates()
Definition: WikiFilePage.php:138
WikiFilePage\$mDupes
$mDupes
Definition: WikiFilePage.php:34
$self
$self
Definition: doMaintenance.php:54
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
WikiFilePage\getForeignCategories
getForeignCategories()
Get the categories this file is a member of on the wiki where it was uploaded.
Definition: WikiFilePage.php:203
wfFindFile
wfFindFile( $title, $options=array())
Find a file.
Definition: GlobalFunctions.php:3693
WikiFilePage\getRedirectTarget
getRedirectTarget()
Definition: WikiFilePage.php:76
WikiFilePage\doPurge
doPurge()
Override handling of action=purge.
Definition: WikiFilePage.php:173
WikiFilePage
Special handling for file pages.
Definition: WikiFilePage.php:28
WikiFilePage\getActionOverrides
getActionOverrides()
Returns overrides for action handlers.
Definition: WikiFilePage.php:42
WikiFilePage\isRedirect
isRedirect()
Definition: WikiFilePage.php:110
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:3704
WikiFilePage\isLocal
isLocal()
Definition: WikiFilePage.php:122
$res
$res
Definition: database.txt:21