3 * Foreign file with an accessible MediaWiki database.
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
21 * @ingroup FileAbstraction
24 use MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\DBUnexpectedError
;
28 * Foreign file with an accessible MediaWiki database
30 * @ingroup FileAbstraction
32 class ForeignDBFile
extends LocalFile
{
35 * @param FileRepo $repo
37 * @return ForeignDBFile
39 static function newFromTitle( $title, $repo, $unused = null ) {
40 return new self( $title, $repo );
44 * Create a ForeignDBFile from a title
45 * Do not call this except from inside a repo class.
47 * @param stdClass $row
48 * @param FileRepo $repo
49 * @return ForeignDBFile
51 static function newFromRow( $row, $repo ) {
52 $title = Title
::makeTitle( NS_FILE
, $row->img_name
);
53 $file = new self( $title, $repo );
54 $file->loadFromRow( $row );
60 * @param string $srcPath
62 * @param array $options
66 function publish( $srcPath, $flags = 0, array $options = [] ) {
67 $this->readOnlyError();
71 * @param string $oldver
73 * @param string $license
74 * @param string $copyStatus
75 * @param string $source
77 * @param bool|string $timestamp
78 * @param User|null $user User object or null to use $wgUser
82 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
83 $watch = false, $timestamp = false, User
$user = null ) {
84 $this->readOnlyError();
88 * @param array $versions
89 * @param bool $unsuppress
93 function restore( $versions = [], $unsuppress = false ) {
94 $this->readOnlyError();
98 * @param string $reason
99 * @param bool $suppress
100 * @param User|null $user
102 * @throws MWException
104 function delete( $reason, $suppress = false, $user = null ) {
105 $this->readOnlyError();
109 * @param Title $target
111 * @throws MWException
113 function move( $target ) {
114 $this->readOnlyError();
120 function getDescriptionUrl() {
121 // Restore remote behavior
122 return File
::getDescriptionUrl();
126 * @param Language|null $lang Optional language to fetch description in.
127 * @return string|false
129 function getDescriptionText( $lang = null ) {
132 if ( !$this->repo
->fetchDescription
) {
136 $lang = $lang ?
: $wgLang;
137 $renderUrl = $this->repo
->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
142 $touched = $this->repo
->getReplicaDB()->selectField(
146 'page_namespace' => NS_FILE
,
147 'page_title' => $this->title
->getDBkey()
150 if ( $touched === false ) {
151 return false; // no description page
154 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
156 return $cache->getWithSetCallback(
157 $this->repo
->getLocalCacheKey(
158 'RemoteFileDescription',
164 $this->repo
->descriptionCacheExpiry ?
: $cache::TTL_UNCACHEABLE
,
165 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
166 wfDebug( "Fetching shared description from $renderUrl\n" );
167 $res = Http
::get( $renderUrl, [], __METHOD__
);
169 $ttl = WANObjectCache
::TTL_UNCACHEABLE
;
178 * Get short description URL for a file based on the page ID.
181 * @throws DBUnexpectedError
184 public function getDescriptionShortUrl() {
185 $dbr = $this->repo
->getReplicaDB();
186 $pageId = $dbr->selectField(
190 'page_namespace' => NS_FILE
,
191 'page_title' => $this->title
->getDBkey()
195 if ( $pageId !== false ) {
196 $url = $this->repo
->makeUrl( [ 'curid' => $pageId ] );
197 if ( $url !== false ) {