MediaWiki  1.34.0
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 
42  function publish( $srcPath, $flags = 0, array $options = [] ) {
43  $this->readOnlyError();
44  }
45 
58  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
59  $watch = false, $timestamp = false, User $user = null ) {
60  $this->readOnlyError();
61  }
62 
69  function restore( $versions = [], $unsuppress = false ) {
70  $this->readOnlyError();
71  }
72 
80  function delete( $reason, $suppress = false, $user = null ) {
81  $this->readOnlyError();
82  }
83 
89  function move( $target ) {
90  $this->readOnlyError();
91  }
92 
96  function getDescriptionUrl() {
97  // Restore remote behavior
98  return File::getDescriptionUrl();
99  }
100 
105  function getDescriptionText( Language $lang = null ) {
106  global $wgLang;
107 
108  if ( !$this->repo->fetchDescription ) {
109  return false;
110  }
111 
112  $lang = $lang ?? $wgLang;
113  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
114  if ( !$renderUrl ) {
115  return false;
116  }
117 
118  $touched = $this->repo->getReplicaDB()->selectField(
119  'page',
120  'page_touched',
121  [
122  'page_namespace' => NS_FILE,
123  'page_title' => $this->title->getDBkey()
124  ]
125  );
126  if ( $touched === false ) {
127  return false; // no description page
128  }
129 
130  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
131  $fname = __METHOD__;
132 
133  return $cache->getWithSetCallback(
134  $this->repo->getLocalCacheKey(
135  'ForeignFileDescription',
136  $lang->getCode(),
137  md5( $this->getName() ),
138  $touched
139  ),
140  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
141  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
142  wfDebug( "Fetching shared description from $renderUrl\n" );
143  $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
144  get( $renderUrl, [], $fname );
145  if ( !$res ) {
146  $ttl = WANObjectCache::TTL_UNCACHEABLE;
147  }
148 
149  return $res;
150  }
151  );
152  }
153 
161  public function getDescriptionShortUrl() {
162  $dbr = $this->repo->getReplicaDB();
163  $pageId = $dbr->selectField(
164  'page',
165  'page_id',
166  [
167  'page_namespace' => NS_FILE,
168  'page_title' => $this->title->getDBkey()
169  ]
170  );
171 
172  if ( $pageId !== false ) {
173  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
174  if ( $url !== false ) {
175  return $url;
176  }
177  }
178  return null;
179  }
180 
181 }
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:58
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
NS_FILE
const NS_FILE
Definition: Defines.php:66
$res
$res
Definition: testCompression.php:52
$dbr
$dbr
Definition: testCompression.php:50
File\$url
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:127
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:161
$wgLang
$wgLang
Definition: Setup.php:881
ForeignDBFile\publish
publish( $srcPath, $flags=0, array $options=[])
Definition: ForeignDBFile.php:42
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:105
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:89
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2047
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:116
File\getName
getName()
Return the name of this file.
Definition: File.php:307
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:113
Wikimedia\Rdbms\DBUnexpectedError
Definition: DBUnexpectedError.php:27
File\readOnlyError
readOnlyError()
Definition: File.php:1794
$cache
$cache
Definition: mcc.php:33
$source
$source
Definition: mwdoc-filter.php:34
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:69
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Language
Internationalisation code.
Definition: Language.php:37
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:96