3 * Special handling for file pages
7 class WikiFilePage
extends WikiPage
{
11 protected $mFile = false; // !< File object
12 protected $mRepo = null; // !<
13 protected $mFileLoaded = false; // !<
14 protected $mDupes = null; // !<
16 public function __construct( $title ) {
17 parent
::__construct( $title );
22 public function getActionOverrides() {
23 return array( 'revert' => 'RevertFileAction' );
29 public function setFile( $file ) {
31 $this->mFileLoaded
= true;
37 protected function loadFile() {
38 if ( $this->mFileLoaded
) {
41 $this->mFileLoaded
= true;
43 $this->mFile
= wfFindFile( $this->mTitle
);
44 if ( !$this->mFile
) {
45 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
47 $this->mRepo
= $this->mFile
->getRepo();
52 * @return mixed|null|Title
54 public function getRedirectTarget() {
56 if ( $this->mFile
->isLocal() ) {
57 return parent
::getRedirectTarget();
60 $from = $this->mFile
->getRedirected();
61 $to = $this->mFile
->getName();
65 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
69 * @return bool|mixed|Title
71 public function followRedirect() {
73 if ( $this->mFile
->isLocal() ) {
74 return parent
::followRedirect();
76 $from = $this->mFile
->getRedirected();
77 $to = $this->mFile
->getName();
81 return Title
::makeTitle( NS_FILE
, $to );
88 public function isRedirect( $text = false ) {
90 if ( $this->mFile
->isLocal() ) {
91 return parent
::isRedirect( $text );
94 return (bool)$this->mFile
->getRedirected();
100 public function isLocal() {
102 return $this->mFile
->isLocal();
108 public function getFile() {
116 public function getDuplicates() {
118 if ( !is_null( $this->mDupes
) ) {
119 return $this->mDupes
;
121 $hash = $this->mFile
->getSha1();
123 return $this->mDupes
= array();
125 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
126 // Remove duplicates with self and non matching file sizes
127 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
128 $size = $this->mFile
->getSize();
133 foreach ( $dupes as $index => $file ) {
134 $key = $file->getRepoName() . ':' . $file->getName();
135 if ( $key == $self ) {
136 unset( $dupes[$index] );
138 if ( $file->getSize() != $size ) {
139 unset( $dupes[$index] );
142 $this->mDupes
= $dupes;
143 return $this->mDupes
;
147 * Override handling of action=purge
150 public function doPurge() {
152 if ( $this->mFile
->exists() ) {
153 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
154 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
156 $this->mFile
->upgradeRow();
157 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
159 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
160 // even if the file supposedly doesn't exist, force any cached information
161 // to be updated (in case the cached information is wrong)
162 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
164 return parent
::doPurge();