class ImagePage extends Article {
/* private */ var $img; // Image object this page is shown for
+ /* private */ var $current;
/* private */ var $repo;
+ /* private */ var $time;
+ /* private */ var $fileLoaded;
var $mExtraDescription = false;
var $dupes;
global $wgRequest;
$time = is_null($time) ? $time : $wgRequest->getVal( 'filetimestamp' );
-
- $this->img = wfFindFile( $this->mTitle, $time );
+ $this->time = $time;
+ $this->dupes = null;
+ $this->repo = null;
+ }
+
+ protected function loadFile() {
+ if( $this->fileLoaded ) {
+ return true;
+ }
+ $this->img = wfFindFile( $this->mTitle, $this->time );
if ( !$this->img ) {
$this->img = wfLocalFile( $this->mTitle );
$this->current = $this->img;
} else {
- $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img;
+ $this->current = $this->time ? wfLocalFile( $this->mTitle ) : $this->img;
}
$this->repo = $this->img->getRepo();
- $this->dupes = null;
+ $this->fileLoaded = true;
}
/**
function view() {
global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
+ $this->loadFile();
if ( $this->mTitle->getNamespace() == NS_IMAGE && $this->img->getRedirected() ) {
if ( $this->mTitle->getDBkey() == $this->img->getName() ) {
}
public function getRedirectTarget() {
- if ( $this->img->isLocal() )
+ $this->loadFile();
+ if ( $this->img->isLocal() ) {
return parent::getRedirectTarget();
-
+ }
// Foreign image page
$from = $this->img->getRedirected();
$to = $this->img->getName();
- if ($from == $to) return null;
+ if ( $from == $to ) {
+ return null;
+ }
return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $to );
}
public function followRedirect() {
- if ( $this->img->isLocal() )
+ $this->loadFile();
+ if ( $this->img->isLocal() ) {
return parent::followRedirect();
-
+ }
$from = $this->img->getRedirected();
$to = $this->img->getName();
- if ($from == $to) return false;
+ if ( $from == $to ) {
+ return false;
+ }
return Title::makeTitle( NS_IMAGE, $to );
}
public function isRedirect( $text = false ) {
+ $this->loadFile();
if ( $this->img->isLocal() )
return parent::isRedirect( $text );
}
public function isLocal() {
+ $this->loadFile();
return $this->img->isLocal();
}
public function getFile() {
+ $this->loadFile();
return $this->img;
}
public function getDuplicates() {
- if ( !is_null($this->dupes) ) return $this->dupes;
-
- if ( !( $hash = $this->img->getSha1() ) )
+ $this->loadFile();
+ if ( !is_null($this->dupes) ) {
+ return $this->dupes;
+ }
+ if ( !( $hash = $this->img->getSha1() ) ) {
return $this->dupes = array();
+ }
$dupes = RepoGroup::singleton()->findBySha1( $hash );
-
// Remove duplicates with self and non matching file sizes
$self = $this->img->getRepoName().':'.$this->img->getName();
$size = $this->img->getSize();
* shared upload server if possible.
*/
function getContent() {
+ $this->loadFile();
if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
return '';
}
function openShowImage() {
global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
+ $this->loadFile();
+
$full_url = $this->img->getURL();
$linkAttribs = false;
$sizeSel = intval( $wgUser->getOption( 'imagesize') );
function printSharedImageText() {
global $wgOut, $wgUser;
+ $this->loadFile();
+
$descUrl = $this->img->getDescriptionUrl();
$descText = $this->img->getDescriptionText();
$s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
*/
function checkSharedConflict() {
global $wgOut, $wgUser;
+
$repoGroup = RepoGroup::singleton();
if( !$repoGroup->hasForeignRepos() ) {
return;
}
+
+ $this->loadFile();
if( !$this->img->isLocal() ) {
return;
}
}
function checkSharedConflictCallback( $repo ) {
+ $this->loadFile();
$dupfile = $repo->newFile( $this->img->getTitle() );
- if( $dupfile->exists() )
+ if( $dupfile->exists() ) {
$this->dupFile = $dupfile;
+ }
return $dupfile->exists();
}
function getUploadUrl() {
+ $this->loadFile();
$uploadTitle = SpecialPage::getTitleFor( 'Upload' );
return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
}
function uploadLinksBox() {
global $wgUser, $wgOut;
+ $this->loadFile();
if( !$this->img->isLocal() )
return;
$sk = $wgUser->getSkin();
+ $this->loadFile();
if ( $this->img->exists() ) {
$list = new ImageHistoryList( $sk, $this->current, $this->img );
$file = $this->current;
function imageDupes() {
global $wgOut, $wgUser;
-
+
+ $this->loadFile();
+
$dupes = $this->getDuplicates();
if ( count( $dupes ) == 0 ) return;
* Delete the file, or an earlier version of it
*/
public function delete() {
+ $this->loadFile();
if( !$this->img->exists() || !$this->img->isLocal() ) {
// Standard article deletion
Article::delete();
* Revert the file to an earlier version
*/
public function revert() {
+ $this->loadFile();
$reverter = new FileRevertForm( $this->img );
$reverter->execute();
}
* Override handling of action=purge
*/
function doPurge() {
+ $this->loadFile();
if( $this->img->exists() ) {
wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
$update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );