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
25 * Foreign file with an accessible MediaWiki database
27 * @ingroup FileAbstraction
29 class ForeignDBFile
extends LocalFile
{
32 * @param FileRepo $repo
34 * @return ForeignDBFile
36 static function newFromTitle( $title, $repo, $unused = null ) {
37 return new self( $title, $repo );
41 * Create a ForeignDBFile from a title
42 * Do not call this except from inside a repo class.
44 * @param stdClass $row
45 * @param FileRepo $repo
46 * @return ForeignDBFile
48 static function newFromRow( $row, $repo ) {
49 $title = Title
::makeTitle( NS_FILE
, $row->img_name
);
50 $file = new self( $title, $repo );
51 $file->loadFromRow( $row );
57 * @param string $srcPath
59 * @param array $options
63 function publish( $srcPath, $flags = 0, array $options = [] ) {
64 $this->readOnlyError();
68 * @param string $oldver
70 * @param string $license
71 * @param string $copyStatus
72 * @param string $source
74 * @param bool|string $timestamp
75 * @param User $user User object or null to use $wgUser
79 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
80 $watch = false, $timestamp = false, User
$user = null ) {
81 $this->readOnlyError();
85 * @param array $versions
86 * @param bool $unsuppress
90 function restore( $versions = [], $unsuppress = false ) {
91 $this->readOnlyError();
95 * @param string $reason
96 * @param bool $suppress
97 * @param User|null $user
101 function delete( $reason, $suppress = false, $user = null ) {
102 $this->readOnlyError();
106 * @param Title $target
108 * @throws MWException
110 function move( $target ) {
111 $this->readOnlyError();
117 function getDescriptionUrl() {
118 // Restore remote behavior
119 return File
::getDescriptionUrl();
123 * @param bool|Language $lang Optional language to fetch description in.
124 * @return string|false
126 function getDescriptionText( $lang = false ) {
129 if ( !$this->repo
->fetchDescription
) {
133 $lang = $lang ?
: $wgLang;
134 $renderUrl = $this->repo
->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
139 $touched = $this->repo
->getReplicaDB()->selectField(
143 'page_namespace' => NS_FILE
,
144 'page_title' => $this->title
->getDBkey()
147 if ( $touched === false ) {
148 return false; // no description page
151 $cache = ObjectCache
::getMainWANInstance();
153 return $cache->getWithSetCallback(
154 $this->repo
->getLocalCacheKey(
155 'RemoteFileDescription',
161 $this->repo
->descriptionCacheExpiry ?
: $cache::TTL_UNCACHEABLE
,
162 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
163 wfDebug( "Fetching shared description from $renderUrl\n" );
164 $res = Http
::get( $renderUrl, [], __METHOD__
);
166 $ttl = WANObjectCache
::TTL_UNCACHEABLE
;
175 * Get short description URL for a file based on the page ID.
178 * @throws DBUnexpectedError
181 public function getDescriptionShortUrl() {
182 $dbr = $this->repo
->getReplicaDB();
183 $pageId = $dbr->selectField(
187 'page_namespace' => NS_FILE
,
188 'page_title' => $this->title
->getDBkey()
192 if ( $pageId !== false ) {
193 $url = $this->repo
->makeUrl( [ 'curid' => $pageId ] );
194 if ( $url !== false ) {