MediaWiki fundraising/REL1_35
ForeignDBFile.php
Go to the documentation of this file.
1<?php
26
27// @phan-file-suppress PhanTypeMissingReturn false positives
33class ForeignDBFile extends LocalFile {
34
38 public function getRepo() {
39 return $this->repo;
40 }
41
49 public function publish( $srcPath, $flags = 0, array $options = [] ) {
50 $this->readOnlyError();
51 }
52
66 public function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
67 $watch = false, $timestamp = false, User $user = null ) {
68 wfDeprecated( __METHOD__, '1.35' );
69 $this->readOnlyError();
70 }
71
78 public function restore( $versions = [], $unsuppress = false ) {
79 $this->readOnlyError();
80 }
81
90 public function delete( $reason, $suppress = false, $user = null ) {
91 wfDeprecated( __METHOD__, '1.35' );
92 $this->readOnlyError();
93 }
94
102 public function deleteFile( $reason, User $user, $suppress = false ) {
103 $this->readOnlyError();
104 }
105
111 public function move( $target ) {
112 $this->readOnlyError();
113 }
114
118 public function getDescriptionUrl() {
119 // Restore remote behavior
121 }
122
127 public function getDescriptionText( Language $lang = null ) {
128 global $wgLang;
129
130 if ( !$this->repo->fetchDescription ) {
131 return false;
132 }
133
134 $lang = $lang ?? $wgLang;
135 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
136 if ( !$renderUrl ) {
137 return false;
138 }
139
140 $touched = $this->repo->getReplicaDB()->selectField(
141 'page',
142 'page_touched',
143 [
144 'page_namespace' => NS_FILE,
145 'page_title' => $this->title->getDBkey()
146 ],
147 __METHOD__
148 );
149 if ( $touched === false ) {
150 return false; // no description page
151 }
152
153 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
154 $fname = __METHOD__;
155
156 return $cache->getWithSetCallback(
157 $this->repo->getLocalCacheKey(
158 'ForeignFileDescription',
159 $lang->getCode(),
160 md5( $this->getName() ),
161 $touched
162 ),
163 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
164 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
165 wfDebug( "Fetching shared description from $renderUrl" );
166 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
167 get( $renderUrl, [], $fname );
168 if ( !$res ) {
169 $ttl = WANObjectCache::TTL_UNCACHEABLE;
170 }
171
172 return $res;
173 }
174 );
175 }
176
184 public function getDescriptionShortUrl() {
185 $dbr = $this->repo->getReplicaDB();
186 $pageId = $dbr->selectField(
187 'page',
188 'page_id',
189 [
190 'page_namespace' => NS_FILE,
191 'page_title' => $this->title->getDBkey()
192 ],
193 __METHOD__
194 );
195
196 if ( $pageId !== false ) {
197 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
198 if ( $url !== false ) {
199 return $url;
200 }
201 }
202 return null;
203 }
204
205}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
$wgLang
Definition Setup.php:781
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:131
getName()
Return the name of this file.
Definition File.php:315
readOnlyError()
Definition File.php:1880
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:110
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2173
Foreign file with an accessible MediaWiki database.
publish( $srcPath, $flags=0, array $options=[])
getDescriptionText(Language $lang=null)
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
deleteFile( $reason, User $user, $suppress=false)
restore( $versions=[], $unsuppress=false)
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:41
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:59
string $timestamp
Upload timestamp.
User $user
Uploader.
MediaWikiServices is the service locator for the application scope of MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
const NS_FILE
Definition Defines.php:76
$cache
Definition mcc.php:33
$source
if(!isset( $args[0])) $lang