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 Wikimedia\Rdbms\DBUnexpectedError
;
27 * Foreign file with an accessible MediaWiki database
29 * @ingroup FileAbstraction
31 class ForeignDBFile
extends LocalFile
{
34 * @param FileRepo $repo
36 * @return ForeignDBFile
38 static function newFromTitle( $title, $repo, $unused = null ) {
39 return new self( $title, $repo );
43 * Create a ForeignDBFile from a title
44 * Do not call this except from inside a repo class.
46 * @param stdClass $row
47 * @param FileRepo $repo
48 * @return ForeignDBFile
50 static function newFromRow( $row, $repo ) {
51 $title = Title
::makeTitle( NS_FILE
, $row->img_name
);
52 $file = new self( $title, $repo );
53 $file->loadFromRow( $row );
59 * @param string $srcPath
61 * @param array $options
65 function publish( $srcPath, $flags = 0, array $options = [] ) {
66 $this->readOnlyError();
70 * @param string $oldver
72 * @param string $license
73 * @param string $copyStatus
74 * @param string $source
76 * @param bool|string $timestamp
77 * @param User $user User object or null to use $wgUser
81 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
82 $watch = false, $timestamp = false, User
$user = null ) {
83 $this->readOnlyError();
87 * @param array $versions
88 * @param bool $unsuppress
92 function restore( $versions = [], $unsuppress = false ) {
93 $this->readOnlyError();
97 * @param string $reason
98 * @param bool $suppress
99 * @param User|null $user
101 * @throws MWException
103 function delete( $reason, $suppress = false, $user = null ) {
104 $this->readOnlyError();
108 * @param Title $target
110 * @throws MWException
112 function move( $target ) {
113 $this->readOnlyError();
119 function getDescriptionUrl() {
120 // Restore remote behavior
121 return File
::getDescriptionUrl();
125 * @param Language|null $lang Optional language to fetch description in.
126 * @return string|false
128 function getDescriptionText( $lang = null ) {
131 if ( !$this->repo
->fetchDescription
) {
135 $lang = $lang ?
: $wgLang;
136 $renderUrl = $this->repo
->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
141 $touched = $this->repo
->getReplicaDB()->selectField(
145 'page_namespace' => NS_FILE
,
146 'page_title' => $this->title
->getDBkey()
149 if ( $touched === false ) {
150 return false; // no description page
153 $cache = ObjectCache
::getMainWANInstance();
155 return $cache->getWithSetCallback(
156 $this->repo
->getLocalCacheKey(
157 'RemoteFileDescription',
163 $this->repo
->descriptionCacheExpiry ?
: $cache::TTL_UNCACHEABLE
,
164 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
165 wfDebug( "Fetching shared description from $renderUrl\n" );
166 $res = Http
::get( $renderUrl, [], __METHOD__
);
168 $ttl = WANObjectCache
::TTL_UNCACHEABLE
;
177 * Get short description URL for a file based on the page ID.
180 * @throws DBUnexpectedError
183 public function getDescriptionShortUrl() {
184 $dbr = $this->repo
->getReplicaDB();
185 $pageId = $dbr->selectField(
189 'page_namespace' => NS_FILE
,
190 'page_title' => $this->title
->getDBkey()
194 if ( $pageId !== false ) {
195 $url = $this->repo
->makeUrl( [ 'curid' => $pageId ] );
196 if ( $url !== false ) {