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;
44 if ( !$this->mFile
) {
45 $this->mFile
= wfFindFile( $this->mTitle
);
46 if ( !$this->mFile
) {
47 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
50 $this->mRepo
= $this->mFile
->getRepo();
55 * @return mixed|null|Title
57 public function getRedirectTarget() {
59 if ( $this->mFile
->isLocal() ) {
60 return parent
::getRedirectTarget();
63 $from = $this->mFile
->getRedirected();
64 $to = $this->mFile
->getName();
68 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
72 * @return bool|mixed|Title
74 public function followRedirect() {
76 if ( $this->mFile
->isLocal() ) {
77 return parent
::followRedirect();
79 $from = $this->mFile
->getRedirected();
80 $to = $this->mFile
->getName();
84 return Title
::makeTitle( NS_FILE
, $to );
91 public function isRedirect( $text = false ) {
93 if ( $this->mFile
->isLocal() ) {
94 return parent
::isRedirect( $text );
97 return (bool)$this->mFile
->getRedirected();
103 public function isLocal() {
105 return $this->mFile
->isLocal();
111 public function getFile() {
119 public function getDuplicates() {
121 if ( !is_null( $this->mDupes
) ) {
122 return $this->mDupes
;
124 $hash = $this->mFile
->getSha1();
126 return $this->mDupes
= array();
128 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
129 // Remove duplicates with self and non matching file sizes
130 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
131 $size = $this->mFile
->getSize();
136 foreach ( $dupes as $index => $file ) {
137 $key = $file->getRepoName() . ':' . $file->getName();
138 if ( $key == $self ) {
139 unset( $dupes[$index] );
141 if ( $file->getSize() != $size ) {
142 unset( $dupes[$index] );
145 $this->mDupes
= $dupes;
146 return $this->mDupes
;
150 * Override handling of action=purge
152 public function doPurge() {
154 if ( $this->mFile
->exists() ) {
155 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
156 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
158 $this->mFile
->upgradeRow();
159 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
161 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
162 // even if the file supposedly doesn't exist, force any cached information
163 // to be updated (in case the cached information is wrong)
164 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
166 return parent
::doPurge();