3 * Special handling for file pages
7 class WikiFilePage
extends WikiPage
{
11 protected $mFile = false; // !< File object
12 protected $mRepo = null; // !<
13 protected $mFileLoaded = false; // !<
14 protected $mDupes = null; // !<
16 public function __construct( $title ) {
17 parent
::__construct( $title );
22 public function getActionOverrides() {
23 return array( 'revert' => 'RevertFileAction' );
30 public function setFile( $file ) {
32 $this->mFileLoaded
= true;
35 protected function loadFile() {
36 if ( $this->mFileLoaded
) {
39 $this->mFileLoaded
= true;
42 if ( !$this->mFile
) {
43 $this->mFile
= wfFindFile( $this->mTitle
);
44 if ( !$this->mFile
) {
45 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
48 $this->mRepo
= $this->mFile
->getRepo();
52 public function getRedirectTarget() {
54 if ( $this->mFile
->isLocal() ) {
55 return parent
::getRedirectTarget();
58 $from = $this->mFile
->getRedirected();
59 $to = $this->mFile
->getName();
63 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
66 public function followRedirect() {
68 if ( $this->mFile
->isLocal() ) {
69 return parent
::followRedirect();
71 $from = $this->mFile
->getRedirected();
72 $to = $this->mFile
->getName();
76 return Title
::makeTitle( NS_FILE
, $to );
79 public function isRedirect( $text = false ) {
81 if ( $this->mFile
->isLocal() ) {
82 return parent
::isRedirect( $text );
85 return (bool)$this->mFile
->getRedirected();
88 public function isLocal() {
90 return $this->mFile
->isLocal();
93 public function getFile() {
98 public function getDuplicates() {
100 if ( !is_null( $this->mDupes
) ) {
101 return $this->mDupes
;
103 $hash = $this->mFile
->getSha1();
105 return $this->mDupes
= array();
107 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
108 // Remove duplicates with self and non matching file sizes
109 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
110 $size = $this->mFile
->getSize();
111 foreach ( $dupes as $index => $file ) {
112 $key = $file->getRepoName() . ':' . $file->getName();
113 if ( $key == $self ) {
114 unset( $dupes[$index] );
116 if ( $file->getSize() != $size ) {
117 unset( $dupes[$index] );
120 $this->mDupes
= $dupes;
121 return $this->mDupes
;
125 * Override handling of action=purge
127 public function doPurge() {
129 if ( $this->mFile
->exists() ) {
130 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
131 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
133 $this->mFile
->upgradeRow();
134 $this->mFile
->purgeCache();
136 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
137 // even if the file supposedly doesn't exist, force any cached information
138 // to be updated (in case the cached information is wrong)
139 $this->mFile
->purgeCache();