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 string $srcPath
38 * @param array $options
42 function publish( $srcPath, $flags = 0, array $options = [] ) {
43 $this->readOnlyError();
47 * @param string $oldver
49 * @param string $license
50 * @param string $copyStatus
51 * @param string $source
53 * @param bool|string $timestamp
54 * @param User|null $user User object or null to use $wgUser
58 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
59 $watch = false, $timestamp = false, User
$user = null ) {
60 $this->readOnlyError();
64 * @param array $versions
65 * @param bool $unsuppress
69 function restore( $versions = [], $unsuppress = false ) {
70 $this->readOnlyError();
74 * @param string $reason
75 * @param bool $suppress
76 * @param User|null $user
80 function delete( $reason, $suppress = false, $user = null ) {
81 $this->readOnlyError();
85 * @param Title $target
89 function move( $target ) {
90 $this->readOnlyError();
96 function getDescriptionUrl() {
97 // Restore remote behavior
98 return File
::getDescriptionUrl();
102 * @param Language|null $lang Optional language to fetch description in.
103 * @return string|false
105 function getDescriptionText( Language
$lang = null ) {
108 if ( !$this->repo
->fetchDescription
) {
112 $lang = $lang ??
$wgLang;
113 $renderUrl = $this->repo
->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
118 $touched = $this->repo
->getReplicaDB()->selectField(
122 'page_namespace' => NS_FILE
,
123 'page_title' => $this->title
->getDBkey()
126 if ( $touched === false ) {
127 return false; // no description page
130 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
133 return $cache->getWithSetCallback(
134 $this->repo
->getLocalCacheKey(
135 'ForeignFileDescription',
137 md5( $this->getName() ),
140 $this->repo
->descriptionCacheExpiry ?
: $cache::TTL_UNCACHEABLE
,
141 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
142 wfDebug( "Fetching shared description from $renderUrl\n" );
143 $res = MediaWikiServices
::getInstance()->getHttpRequestFactory()->
144 get( $renderUrl, [], $fname );
146 $ttl = WANObjectCache
::TTL_UNCACHEABLE
;
155 * Get short description URL for a file based on the page ID.
158 * @throws DBUnexpectedError
161 public function getDescriptionShortUrl() {
162 $dbr = $this->repo
->getReplicaDB();
163 $pageId = $dbr->selectField(
167 'page_namespace' => NS_FILE
,
168 'page_title' => $this->title
->getDBkey()
172 if ( $pageId !== false ) {
173 $url = $this->repo
->makeUrl( [ 'curid' => $pageId ] );
174 if ( $url !== false ) {