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 
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 
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 }
Foreign file with an accessible MediaWiki database.
User $user
Uploader.
Definition: LocalFile.php:116
getDescriptionText(Language $lang=null)
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(!isset( $args[0])) $lang
$source
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2044
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
getName()
Return the name of this file.
Definition: File.php:307
title
move( $target)
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
restore( $versions=[], $unsuppress=false)
readOnlyError()
Definition: File.php:1791
$wgLang
Definition: Setup.php:922
$res
Definition: database.txt:21
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
$cache
Definition: mcc.php:33
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1983
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback function
Definition: injection.txt:30
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
const NS_FILE
Definition: Defines.php:66
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:131
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:127
Class to represent a local file in the wiki&#39;s own database.
Definition: LocalFile.php:56
string $timestamp
Upload timestamp.
Definition: LocalFile.php:113
publish( $srcPath, $flags=0, array $options=[])