MediaWiki
REL1_24
|
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 00046 public function setFile( $file ) { 00047 $this->mFile = $file; 00048 $this->mFileLoaded = true; 00049 } 00050 00054 protected function loadFile() { 00055 if ( $this->mFileLoaded ) { 00056 return true; 00057 } 00058 $this->mFileLoaded = true; 00059 00060 $this->mFile = wfFindFile( $this->mTitle ); 00061 if ( !$this->mFile ) { 00062 $this->mFile = wfLocalFile( $this->mTitle ); // always a File 00063 } 00064 $this->mRepo = $this->mFile->getRepo(); 00065 return true; 00066 } 00067 00071 public function getRedirectTarget() { 00072 $this->loadFile(); 00073 if ( $this->mFile->isLocal() ) { 00074 return parent::getRedirectTarget(); 00075 } 00076 // Foreign image page 00077 $from = $this->mFile->getRedirected(); 00078 $to = $this->mFile->getName(); 00079 if ( $from == $to ) { 00080 return null; 00081 } 00082 $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to ); 00083 return $this->mRedirectTarget; 00084 } 00085 00089 public function followRedirect() { 00090 $this->loadFile(); 00091 if ( $this->mFile->isLocal() ) { 00092 return parent::followRedirect(); 00093 } 00094 $from = $this->mFile->getRedirected(); 00095 $to = $this->mFile->getName(); 00096 if ( $from == $to ) { 00097 return false; 00098 } 00099 return Title::makeTitle( NS_FILE, $to ); 00100 } 00101 00105 public function isRedirect() { 00106 $this->loadFile(); 00107 if ( $this->mFile->isLocal() ) { 00108 return parent::isRedirect(); 00109 } 00110 00111 return (bool)$this->mFile->getRedirected(); 00112 } 00113 00117 public function isLocal() { 00118 $this->loadFile(); 00119 return $this->mFile->isLocal(); 00120 } 00121 00125 public function getFile() { 00126 $this->loadFile(); 00127 return $this->mFile; 00128 } 00129 00133 public function getDuplicates() { 00134 $this->loadFile(); 00135 if ( !is_null( $this->mDupes ) ) { 00136 return $this->mDupes; 00137 } 00138 $hash = $this->mFile->getSha1(); 00139 if ( !( $hash ) ) { 00140 $this->mDupes = array(); 00141 return $this->mDupes; 00142 } 00143 $dupes = RepoGroup::singleton()->findBySha1( $hash ); 00144 // Remove duplicates with self and non matching file sizes 00145 $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName(); 00146 $size = $this->mFile->getSize(); 00147 00151 foreach ( $dupes as $index => $file ) { 00152 $key = $file->getRepoName() . ':' . $file->getName(); 00153 if ( $key == $self ) { 00154 unset( $dupes[$index] ); 00155 } 00156 if ( $file->getSize() != $size ) { 00157 unset( $dupes[$index] ); 00158 } 00159 } 00160 $this->mDupes = $dupes; 00161 return $this->mDupes; 00162 } 00163 00168 public function doPurge() { 00169 $this->loadFile(); 00170 if ( $this->mFile->exists() ) { 00171 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" ); 00172 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ); 00173 $update->doUpdate(); 00174 $this->mFile->upgradeRow(); 00175 $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) ); 00176 } else { 00177 wfDebug( 'ImagePage::doPurge no image for ' 00178 . $this->mFile->getName() . "; limiting purge to cache only\n" ); 00179 // even if the file supposedly doesn't exist, force any cached information 00180 // to be updated (in case the cached information is wrong) 00181 $this->mFile->purgeCache( array( 'forThumbRefresh' => true ) ); 00182 } 00183 if ( $this->mRepo ) { 00184 // Purge redirect cache 00185 $this->mRepo->invalidateImageRedirect( $this->mTitle ); 00186 } 00187 return parent::doPurge(); 00188 } 00189 00199 public function getForeignCategories() { 00200 $this->loadFile(); 00201 $title = $this->mTitle; 00202 $file = $this->mFile; 00203 00204 if ( !$file instanceof LocalFile ) { 00205 wfDebug( __CLASS__ . '::' . __METHOD__ . " is not supported for this file\n" ); 00206 return TitleArray::newFromResult( new FakeResultWrapper( array() ) ); 00207 } 00208 00210 $repo = $file->getRepo(); 00211 $dbr = $repo->getSlaveDB(); 00212 00213 $res = $dbr->select( 00214 array( 'page', 'categorylinks' ), 00215 array( 00216 'page_title' => 'cl_to', 00217 'page_namespace' => NS_CATEGORY, 00218 ), 00219 array( 00220 'page_namespace' => $title->getNamespace(), 00221 'page_title' => $title->getDBkey(), 00222 ), 00223 __METHOD__, 00224 array(), 00225 array( 'categorylinks' => array( 'INNER JOIN', 'page_id = cl_from' ) ) 00226 ); 00227 00228 return TitleArray::newFromResult( $res ); 00229 } 00230 }