3 * Special handling for file pages.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Special handling for file pages
28 class WikiFilePage
extends WikiPage
{
32 protected $mFile = false; // !< File object
33 protected $mRepo = null; // !<
34 protected $mFileLoaded = false; // !<
35 protected $mDupes = null; // !<
37 public function __construct( $title ) {
38 parent
::__construct( $title );
43 public function getActionOverrides() {
44 $overrides = parent
::getActionOverrides();
45 $overrides[ 'revert' ] = 'RevertFileAction';
52 public function setFile( $file ) {
54 $this->mFileLoaded
= true;
60 protected function loadFile() {
61 if ( $this->mFileLoaded
) {
64 $this->mFileLoaded
= true;
66 $this->mFile
= wfFindFile( $this->mTitle
);
67 if ( !$this->mFile
) {
68 $this->mFile
= wfLocalFile( $this->mTitle
); // always a File
70 $this->mRepo
= $this->mFile
->getRepo();
75 * @return mixed|null|Title
77 public function getRedirectTarget() {
79 if ( $this->mFile
->isLocal() ) {
80 return parent
::getRedirectTarget();
83 $from = $this->mFile
->getRedirected();
84 $to = $this->mFile
->getName();
88 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
92 * @return bool|mixed|Title
94 public function followRedirect() {
96 if ( $this->mFile
->isLocal() ) {
97 return parent
::followRedirect();
99 $from = $this->mFile
->getRedirected();
100 $to = $this->mFile
->getName();
101 if ( $from == $to ) {
104 return Title
::makeTitle( NS_FILE
, $to );
111 public function isRedirect( $text = false ) {
113 if ( $this->mFile
->isLocal() ) {
114 return parent
::isRedirect( $text );
117 return (bool)$this->mFile
->getRedirected();
123 public function isLocal() {
125 return $this->mFile
->isLocal();
131 public function getFile() {
139 public function getDuplicates() {
141 if ( !is_null( $this->mDupes
) ) {
142 return $this->mDupes
;
144 $hash = $this->mFile
->getSha1();
146 return $this->mDupes
= array();
148 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
149 // Remove duplicates with self and non matching file sizes
150 $self = $this->mFile
->getRepoName() . ':' . $this->mFile
->getName();
151 $size = $this->mFile
->getSize();
156 foreach ( $dupes as $index => $file ) {
157 $key = $file->getRepoName() . ':' . $file->getName();
158 if ( $key == $self ) {
159 unset( $dupes[$index] );
161 if ( $file->getSize() != $size ) {
162 unset( $dupes[$index] );
165 $this->mDupes
= $dupes;
166 return $this->mDupes
;
170 * Override handling of action=purge
173 public function doPurge() {
175 if ( $this->mFile
->exists() ) {
176 wfDebug( 'ImagePage::doPurge purging ' . $this->mFile
->getName() . "\n" );
177 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
179 $this->mFile
->upgradeRow();
180 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
182 wfDebug( 'ImagePage::doPurge no image for ' . $this->mFile
->getName() . "; limiting purge to cache only\n" );
183 // even if the file supposedly doesn't exist, force any cached information
184 // to be updated (in case the cached information is wrong)
185 $this->mFile
->purgeCache( array( 'forThumbRefresh' => true ) );
187 return parent
::doPurge();