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
;
27 // @phan-file-suppress PhanTypeMissingReturn false positives
29 * Foreign file with an accessible MediaWiki database
31 * @ingroup FileAbstraction
33 class ForeignDBFile
extends LocalFile
{
36 * @param FileRepo $repo
38 * @return ForeignDBFile
40 static function newFromTitle( $title, $repo, $unused = null ) {
41 return new self( $title, $repo );
45 * Create a ForeignDBFile from a title
46 * Do not call this except from inside a repo class.
48 * @param stdClass $row
49 * @param FileRepo $repo
50 * @return ForeignDBFile
52 static function newFromRow( $row, $repo ) {
53 $title = Title
::makeTitle( NS_FILE
, $row->img_name
);
54 $file = new self( $title, $repo );
55 $file->loadFromRow( $row );
61 * @param string $srcPath
63 * @param array $options
67 function publish( $srcPath, $flags = 0, array $options = [] ) {
68 $this->readOnlyError();
72 * @param string $oldver
74 * @param string $license
75 * @param string $copyStatus
76 * @param string $source
78 * @param bool|string $timestamp
79 * @param User|null $user User object or null to use $wgUser
83 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
84 $watch = false, $timestamp = false, User
$user = null ) {
85 $this->readOnlyError();
89 * @param array $versions
90 * @param bool $unsuppress
94 function restore( $versions = [], $unsuppress = false ) {
95 $this->readOnlyError();
99 * @param string $reason
100 * @param bool $suppress
101 * @param User|null $user
103 * @throws MWException
105 function delete( $reason, $suppress = false, $user = null ) {
106 $this->readOnlyError();
110 * @param Title $target
112 * @throws MWException
114 function move( $target ) {
115 $this->readOnlyError();
121 function getDescriptionUrl() {
122 // Restore remote behavior
123 return File
::getDescriptionUrl();
127 * @param Language|null $lang Optional language to fetch description in.
128 * @return string|false
130 function getDescriptionText( Language
$lang = null ) {
133 if ( !$this->repo
->fetchDescription
) {
137 $lang = $lang ??
$wgLang;
138 $renderUrl = $this->repo
->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
143 $touched = $this->repo
->getReplicaDB()->selectField(
147 'page_namespace' => NS_FILE
,
148 'page_title' => $this->title
->getDBkey()
151 if ( $touched === false ) {
152 return false; // no description page
155 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
158 return $cache->getWithSetCallback(
159 $this->repo
->getLocalCacheKey(
160 'ForeignFileDescription',
162 md5( $this->getName() ),
165 $this->repo
->descriptionCacheExpiry ?
: $cache::TTL_UNCACHEABLE
,
166 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
167 wfDebug( "Fetching shared description from $renderUrl\n" );
168 $res = Http
::get( $renderUrl, [], $fname );
170 $ttl = WANObjectCache
::TTL_UNCACHEABLE
;
179 * Get short description URL for a file based on the page ID.
182 * @throws DBUnexpectedError
185 public function getDescriptionShortUrl() {
186 $dbr = $this->repo
->getReplicaDB();
187 $pageId = $dbr->selectField(
191 'page_namespace' => NS_FILE
,
192 'page_title' => $this->title
->getDBkey()
196 if ( $pageId !== false ) {
197 $url = $this->repo
->makeUrl( [ 'curid' => $pageId ] );
198 if ( $url !== false ) {