3 * Special handling for file pages
7 class WikiFilePage
extends WikiPage
{
8 protected $mFile = false; // !< File object
9 protected $mRepo = null; // !<
10 protected $mFileLoaded = false; // !<
11 protected $mDupes = null; // !<
13 function __construct( $title ) {
14 parent
::__construct( $title );
23 public function setFile( $file ) {
25 $this->mFileLoaded
= true;
28 protected function loadFile() {
29 if ( $this->mFileLoaded
) {
32 $this->mFileLoaded
= true;
35 if ( !$this->mFile
) {
36 $this->mFile
= wfFindFile( $this->mTitle
);
37 if ( !$this->mFile
) {
38 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
41 $this->mRepo
= $this->mFile
->getRepo();
44 public function getRedirectTarget() {
46 if ( $this->mFile
->isLocal() ) {
47 return parent
::getRedirectTarget();
50 $from = $this->mFile
->getRedirected();
51 $to = $this->mFile
->getName();
55 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
58 public function followRedirect() {
60 if ( $this->mFile
->isLocal() ) {
61 return parent
::followRedirect();
63 $from = $this->mFile
->getRedirected();
64 $to = $this->mFile
->getName();
68 return Title
::makeTitle( NS_FILE
, $to );
71 public function isRedirect( $text = false ) {
73 if ( $this->mFile
->isLocal() ) {
74 return parent
::isRedirect( $text );
77 return (bool)$this->mFile
->getRedirected();
80 public function isLocal() {
82 return $this->mFile
->isLocal();
85 public function getFile() {
90 public function getDuplicates() {
92 if ( !is_null( $this->mDupes
) ) {
95 $hash = $this->mFile
->getSha1();
97 return $this->mDupes
= array();
99 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
100 // Remove duplicates with self and non matching file sizes
101 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
102 $size = $this->mFile
->getSize();
103 foreach ( $dupes as $index => $file ) {
104 $key = $file->getRepoName() . ':' . $file->getName();
105 if ( $key == $self ) {
106 unset( $dupes[$index] );
108 if ( $file->getSize() != $size ) {
109 unset( $dupes[$index] );
112 $this->mDupes
= $dupes;
113 return $this->mDupes
;
117 * Override handling of action=purge
119 public function doPurge() {
121 if ( $this->mFile
->exists() ) {
122 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
123 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
125 $this->mFile
->upgradeRow();
126 $this->mFile
->purgeCache();
128 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
129 // even if the file supposedly doesn't exist, force any cached information
130 // to be updated (in case the cached information is wrong)
131 $this->mFile
->purgeCache();