MediaWiki  master
ForeignDBFile.php
Go to the documentation of this file.
1 <?php
26 
27 // @phan-file-suppress PhanTypeMissingReturn false positives
33 class 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
120  return File::getDescriptionUrl();
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 }
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:110
ForeignDBFile
Foreign file with an accessible MediaWiki database.
Definition: ForeignDBFile.php:33
ForeignDBFile\recordUpload
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
Definition: ForeignDBFile.php:66
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
NS_FILE
const NS_FILE
Definition: Defines.php:75
$res
$res
Definition: testCompression.php:57
$dbr
$dbr
Definition: testCompression.php:54
File\$url
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:131
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:184
$wgLang
$wgLang
Definition: Setup.php:776
ForeignDBFile\getRepo
getRepo()
Definition: ForeignDBFile.php:38
ForeignDBFile\publish
publish( $srcPath, $flags=0, array $options=[])
Definition: ForeignDBFile.php:49
ForeignDBFile\deleteFile
deleteFile( $reason, User $user, $suppress=false)
Definition: ForeignDBFile.php:102
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:909
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:59
ForeignDBFile\getDescriptionText
getDescriptionText(Language $lang=null)
Definition: ForeignDBFile.php:127
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:111
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2173
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:119
File\getName
getName()
Return the name of this file.
Definition: File.php:315
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:116
Wikimedia\Rdbms\DBUnexpectedError
@newable Stable to extend
Definition: DBUnexpectedError.php:29
File\readOnlyError
readOnlyError()
Definition: File.php:1880
$cache
$cache
Definition: mcc.php:33
$source
$source
Definition: mwdoc-filter.php:34
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:78
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:56
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:118