MediaWiki  REL1_22
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         $overrides = parent::getActionOverrides();
00045         $overrides['revert'] = 'RevertFileAction';
00046         return $overrides;
00047     }
00048 
00052     public function setFile( $file ) {
00053         $this->mFile = $file;
00054         $this->mFileLoaded = true;
00055     }
00056 
00060     protected function loadFile() {
00061         if ( $this->mFileLoaded ) {
00062             return true;
00063         }
00064         $this->mFileLoaded = true;
00065 
00066         $this->mFile = wfFindFile( $this->mTitle );
00067         if ( !$this->mFile ) {
00068             $this->mFile = wfLocalFile( $this->mTitle ); // always a File
00069         }
00070         $this->mRepo = $this->mFile->getRepo();
00071         return true;
00072     }
00073 
00077     public function getRedirectTarget() {
00078         $this->loadFile();
00079         if ( $this->mFile->isLocal() ) {
00080             return parent::getRedirectTarget();
00081         }
00082         // Foreign image page
00083         $from = $this->mFile->getRedirected();
00084         $to = $this->mFile->getName();
00085         if ( $from == $to ) {
00086             return null;
00087         }
00088         return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
00089     }
00090 
00094     public function followRedirect() {
00095         $this->loadFile();
00096         if ( $this->mFile->isLocal() ) {
00097             return parent::followRedirect();
00098         }
00099         $from = $this->mFile->getRedirected();
00100         $to = $this->mFile->getName();
00101         if ( $from == $to ) {
00102             return false;
00103         }
00104         return Title::makeTitle( NS_FILE, $to );
00105     }
00106 
00110     public function isRedirect() {
00111         $this->loadFile();
00112         if ( $this->mFile->isLocal() ) {
00113             return parent::isRedirect();
00114         }
00115 
00116         return (bool)$this->mFile->getRedirected();
00117     }
00118 
00122     public function isLocal() {
00123         $this->loadFile();
00124         return $this->mFile->isLocal();
00125     }
00126 
00130     public function getFile() {
00131         $this->loadFile();
00132         return $this->mFile;
00133     }
00134 
00138     public function getDuplicates() {
00139         $this->loadFile();
00140         if ( !is_null( $this->mDupes ) ) {
00141             return $this->mDupes;
00142         }
00143         $hash = $this->mFile->getSha1();
00144         if ( !( $hash ) ) {
00145             return $this->mDupes = array();
00146         }
00147         $dupes = RepoGroup::singleton()->findBySha1( $hash );
00148         // Remove duplicates with self and non matching file sizes
00149         $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
00150         $size = $this->mFile->getSize();
00151 
00155         foreach ( $dupes as $index => $file ) {
00156             $key = $file->getRepoName() . ':' . $file->getName();
00157             if ( $key == $self ) {
00158                 unset( $dupes[$index] );
00159             }
00160             if ( $file->getSize() != $size ) {
00161                 unset( $dupes[$index] );
00162             }
00163         }
00164         $this->mDupes = $dupes;
00165         return $this->mDupes;
00166     }
00167 
00172     public function doPurge() {
00173         $this->loadFile();
00174         if ( $this->mFile->exists() ) {
00175             wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
00176             $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
00177             $update->doUpdate();
00178             $this->mFile->upgradeRow();
00179             $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
00180         } else {
00181             wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile->getName() . "; limiting purge to cache only\n" );
00182             // even if the file supposedly doesn't exist, force any cached information
00183             // to be updated (in case the cached information is wrong)
00184             $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) );
00185         }
00186         if ( $this->mRepo ) {
00187             // Purge redirect cache
00188             $this->mRepo->invalidateImageRedirect( $this->mTitle );
00189         }
00190         return parent::doPurge();
00191     }
00192 }