MediaWiki  REL1_20
WikiFilePage.php
Go to the documentation of this file.
00001 <?php
00028 class WikiFilePage extends WikiPage {
00032         protected $mFile = false;                               // !< File object
00033         protected $mRepo = null;                            // !<
00034         protected $mFileLoaded = false;             // !<
00035         protected $mDupes = null;                               // !<
00036 
00037         public function __construct( $title ) {
00038                 parent::__construct( $title );
00039                 $this->mDupes = null;
00040                 $this->mRepo = null;
00041         }
00042 
00043         public function getActionOverrides() {
00044                 return array( 'revert' => 'RevertFileAction' );
00045         }
00046 
00050         public function setFile( $file ) {
00051                 $this->mFile = $file;
00052                 $this->mFileLoaded = true;
00053         }
00054 
00058         protected function loadFile() {
00059                 if ( $this->mFileLoaded ) {
00060                         return true;
00061                 }
00062                 $this->mFileLoaded = true;
00063 
00064                 $this->mFile = wfFindFile( $this->mTitle );
00065                 if ( !$this->mFile ) {
00066                         $this->mFile = wfLocalFile( $this->mTitle ); // always a File
00067                 }
00068                 $this->mRepo = $this->mFile->getRepo();
00069                 return true;
00070         }
00071 
00075         public function getRedirectTarget() {
00076                 $this->loadFile();
00077                 if ( $this->mFile->isLocal() ) {
00078                         return parent::getRedirectTarget();
00079                 }
00080                 // Foreign image page
00081                 $from = $this->mFile->getRedirected();
00082                 $to = $this->mFile->getName();
00083                 if ( $from == $to ) {
00084                         return null;
00085                 }
00086                 return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
00087         }
00088 
00092         public function followRedirect() {
00093                 $this->loadFile();
00094                 if ( $this->mFile->isLocal() ) {
00095                         return parent::followRedirect();
00096                 }
00097                 $from = $this->mFile->getRedirected();
00098                 $to = $this->mFile->getName();
00099                 if ( $from == $to ) {
00100                         return false;
00101                 }
00102                 return Title::makeTitle( NS_FILE, $to );
00103         }
00104 
00109         public function isRedirect( $text = false ) {
00110                 $this->loadFile();
00111                 if ( $this->mFile->isLocal() ) {
00112                         return parent::isRedirect( $text );
00113                 }
00114 
00115                 return (bool)$this->mFile->getRedirected();
00116         }
00117 
00121         public function isLocal() {
00122                 $this->loadFile();
00123                 return $this->mFile->isLocal();
00124         }
00125 
00129         public function getFile() {
00130                 $this->loadFile();
00131                 return $this->mFile;
00132         }
00133 
00137         public function getDuplicates() {
00138                 $this->loadFile();
00139                 if ( !is_null( $this->mDupes ) ) {
00140                         return $this->mDupes;
00141                 }
00142                 $hash = $this->mFile->getSha1();
00143                 if ( !( $hash ) ) {
00144                         return $this->mDupes = array();
00145                 }
00146                 $dupes = RepoGroup::singleton()->findBySha1( $hash );
00147                 // Remove duplicates with self and non matching file sizes
00148                 $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
00149                 $size = $this->mFile->getSize();
00150 
00154                 foreach ( $dupes as $index => $file ) {
00155                         $key = $file->getRepoName() . ':' . $file->getName();
00156                         if ( $key == $self ) {
00157                                 unset( $dupes[$index] );
00158                         }
00159                         if ( $file->getSize() != $size ) {
00160                                 unset( $dupes[$index] );
00161                         }
00162                 }
00163                 $this->mDupes = $dupes;
00164                 return $this->mDupes;
00165         }
00166 
00171         public function doPurge() {
00172                 $this->loadFile();
00173                 if ( $this->mFile->exists() ) {
00174                         wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
00175                         $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
00176                         $update->doUpdate();
00177                         $this->mFile->upgradeRow();
00178                         $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
00179                 } else {
00180                         wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile->getName() . "; limiting purge to cache only\n" );
00181                         // even if the file supposedly doesn't exist, force any cached information
00182                         // to be updated (in case the cached information is wrong)
00183                         $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
00184                 }
00185                 return parent::doPurge();
00186         }
00187 }