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 );
19 public function getActionOverrides() {
20 return array( 'revert' => 'RevertFileAction' );
27 public function setFile( $file ) {
29 $this->mFileLoaded
= true;
32 protected function loadFile() {
33 if ( $this->mFileLoaded
) {
36 $this->mFileLoaded
= true;
39 if ( !$this->mFile
) {
40 $this->mFile
= wfFindFile( $this->mTitle
);
41 if ( !$this->mFile
) {
42 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
45 $this->mRepo
= $this->mFile
->getRepo();
48 public function getRedirectTarget() {
50 if ( $this->mFile
->isLocal() ) {
51 return parent
::getRedirectTarget();
54 $from = $this->mFile
->getRedirected();
55 $to = $this->mFile
->getName();
59 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
62 public function followRedirect() {
64 if ( $this->mFile
->isLocal() ) {
65 return parent
::followRedirect();
67 $from = $this->mFile
->getRedirected();
68 $to = $this->mFile
->getName();
72 return Title
::makeTitle( NS_FILE
, $to );
75 public function isRedirect( $text = false ) {
77 if ( $this->mFile
->isLocal() ) {
78 return parent
::isRedirect( $text );
81 return (bool)$this->mFile
->getRedirected();
84 public function isLocal() {
86 return $this->mFile
->isLocal();
89 public function getFile() {
94 public function getDuplicates() {
96 if ( !is_null( $this->mDupes
) ) {
99 $hash = $this->mFile
->getSha1();
101 return $this->mDupes
= array();
103 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
104 // Remove duplicates with self and non matching file sizes
105 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
106 $size = $this->mFile
->getSize();
107 foreach ( $dupes as $index => $file ) {
108 $key = $file->getRepoName() . ':' . $file->getName();
109 if ( $key == $self ) {
110 unset( $dupes[$index] );
112 if ( $file->getSize() != $size ) {
113 unset( $dupes[$index] );
116 $this->mDupes
= $dupes;
117 return $this->mDupes
;
121 * Override handling of action=purge
123 public function doPurge() {
125 if ( $this->mFile
->exists() ) {
126 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
127 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
129 $this->mFile
->upgradeRow();
130 $this->mFile
->purgeCache();
132 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
133 // even if the file supposedly doesn't exist, force any cached information
134 // to be updated (in case the cached information is wrong)
135 $this->mFile
->purgeCache();