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 
65  public function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
66  $watch = false, $timestamp = false, User $user = null ) {
67  $this->readOnlyError();
68  }
69 
76  public function restore( $versions = [], $unsuppress = false ) {
77  $this->readOnlyError();
78  }
79 
88  public function delete( $reason, $suppress = false, $user = null ) {
89  wfDeprecated( __METHOD__, '1.35' );
90  $this->readOnlyError();
91  }
92 
100  public function deleteFile( $reason, User $user, $suppress = false ) {
101  $this->readOnlyError();
102  }
103 
109  public function move( $target ) {
110  $this->readOnlyError();
111  }
112 
116  public function getDescriptionUrl() {
117  // Restore remote behavior
118  return File::getDescriptionUrl();
119  }
120 
125  public function getDescriptionText( Language $lang = null ) {
126  global $wgLang;
127 
128  if ( !$this->repo->fetchDescription ) {
129  return false;
130  }
131 
132  $lang = $lang ?? $wgLang;
133  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
134  if ( !$renderUrl ) {
135  return false;
136  }
137 
138  $touched = $this->repo->getReplicaDB()->selectField(
139  'page',
140  'page_touched',
141  [
142  'page_namespace' => NS_FILE,
143  'page_title' => $this->title->getDBkey()
144  ]
145  );
146  if ( $touched === false ) {
147  return false; // no description page
148  }
149 
150  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
151  $fname = __METHOD__;
152 
153  return $cache->getWithSetCallback(
154  $this->repo->getLocalCacheKey(
155  'ForeignFileDescription',
156  $lang->getCode(),
157  md5( $this->getName() ),
158  $touched
159  ),
160  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
161  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
162  wfDebug( "Fetching shared description from $renderUrl" );
163  $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
164  get( $renderUrl, [], $fname );
165  if ( !$res ) {
166  $ttl = WANObjectCache::TTL_UNCACHEABLE;
167  }
168 
169  return $res;
170  }
171  );
172  }
173 
181  public function getDescriptionShortUrl() {
182  $dbr = $this->repo->getReplicaDB();
183  $pageId = $dbr->selectField(
184  'page',
185  'page_id',
186  [
187  'page_namespace' => NS_FILE,
188  'page_title' => $this->title->getDBkey()
189  ]
190  );
191 
192  if ( $pageId !== false ) {
193  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
194  if ( $url !== false ) {
195  return $url;
196  }
197  }
198  return null;
199  }
200 
201 }
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:109
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:65
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
$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:130
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1030
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:181
$wgLang
$wgLang
Definition: Setup.php:781
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:100
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:913
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:56
ForeignDBFile\getDescriptionText
getDescriptionText(Language $lang=null)
Definition: ForeignDBFile.php:125
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:109
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2113
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:116
File\getName
getName()
Return the name of this file.
Definition: File.php:310
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:113
Wikimedia\Rdbms\DBUnexpectedError
Definition: DBUnexpectedError.php:27
File\readOnlyError
readOnlyError()
Definition: File.php:1836
$cache
$cache
Definition: mcc.php:33
$source
$source
Definition: mwdoc-filter.php:34
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:76
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:41
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:116