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 
59  public function restore( $versions = [], $unsuppress = false ) {
60  $this->readOnlyError();
61  }
62 
70  public function deleteFile( $reason, User $user, $suppress = false ) {
71  $this->readOnlyError();
72  }
73 
79  public function move( $target ) {
80  $this->readOnlyError();
81  }
82 
86  public function getDescriptionUrl() {
87  // Restore remote behavior
88  return File::getDescriptionUrl();
89  }
90 
95  public function getDescriptionText( Language $lang = null ) {
96  global $wgLang;
97 
98  if ( !$this->repo->fetchDescription ) {
99  return false;
100  }
101 
102  $lang = $lang ?? $wgLang;
103  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
104  if ( !$renderUrl ) {
105  return false;
106  }
107 
108  $touched = $this->repo->getReplicaDB()->selectField(
109  'page',
110  'page_touched',
111  [
112  'page_namespace' => NS_FILE,
113  'page_title' => $this->title->getDBkey()
114  ],
115  __METHOD__
116  );
117  if ( $touched === false ) {
118  return false; // no description page
119  }
120 
121  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
122  $fname = __METHOD__;
123 
124  return $cache->getWithSetCallback(
125  $this->repo->getLocalCacheKey(
126  'file-foreign-description',
127  $lang->getCode(),
128  md5( $this->getName() ),
129  $touched
130  ),
131  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
132  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
133  wfDebug( "Fetching shared description from $renderUrl" );
134  $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
135  get( $renderUrl, [], $fname );
136  if ( !$res ) {
137  $ttl = WANObjectCache::TTL_UNCACHEABLE;
138  }
139 
140  return $res;
141  }
142  );
143  }
144 
152  public function getDescriptionShortUrl() {
153  $dbr = $this->repo->getReplicaDB();
154  $pageId = $dbr->selectField(
155  'page',
156  'page_id',
157  [
158  'page_namespace' => NS_FILE,
159  'page_title' => $this->title->getDBkey()
160  ],
161  __METHOD__
162  );
163 
164  if ( $pageId !== false ) {
165  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
166  if ( $url !== false ) {
167  return $url;
168  }
169  }
170  return null;
171  }
172 
173 }
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
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:163
$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
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:152
$wgLang
$wgLang
Definition: Setup.php:778
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:70
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:910
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:95
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:79
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2126
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:119
File\getName
getName()
Return the name of this file.
Definition: File.php:315
Wikimedia\Rdbms\DBUnexpectedError
@newable Stable to extend
Definition: DBUnexpectedError.php:29
File\readOnlyError
readOnlyError()
Definition: File.php:1880
$cache
$cache
Definition: mcc.php:33
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:59
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:86