MediaWiki  1.33.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 {
40  static function newFromTitle( $title, $repo, $unused = null ) {
41  return new self( $title, $repo );
42  }
43 
52  static function newFromRow( $row, $repo ) {
53  $title = Title::makeTitle( NS_FILE, $row->img_name );
54  $file = new self( $title, $repo );
55  $file->loadFromRow( $row );
56 
57  return $file;
58  }
59 
67  function publish( $srcPath, $flags = 0, array $options = [] ) {
68  $this->readOnlyError();
69  }
70 
83  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
84  $watch = false, $timestamp = false, User $user = null ) {
85  $this->readOnlyError();
86  }
87 
94  function restore( $versions = [], $unsuppress = false ) {
95  $this->readOnlyError();
96  }
97 
105  function delete( $reason, $suppress = false, $user = null ) {
106  $this->readOnlyError();
107  }
108 
114  function move( $target ) {
115  $this->readOnlyError();
116  }
117 
121  function getDescriptionUrl() {
122  // Restore remote behavior
123  return File::getDescriptionUrl();
124  }
125 
130  function getDescriptionText( Language $lang = null ) {
131  global $wgLang;
132 
133  if ( !$this->repo->fetchDescription ) {
134  return false;
135  }
136 
137  $lang = $lang ?? $wgLang;
138  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
139  if ( !$renderUrl ) {
140  return false;
141  }
142 
143  $touched = $this->repo->getReplicaDB()->selectField(
144  'page',
145  'page_touched',
146  [
147  'page_namespace' => NS_FILE,
148  'page_title' => $this->title->getDBkey()
149  ]
150  );
151  if ( $touched === false ) {
152  return false; // no description page
153  }
154 
155  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
156  $fname = __METHOD__;
157 
158  return $cache->getWithSetCallback(
159  $this->repo->getLocalCacheKey(
160  'ForeignFileDescription',
161  $lang->getCode(),
162  md5( $this->getName() ),
163  $touched
164  ),
165  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
166  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
167  wfDebug( "Fetching shared description from $renderUrl\n" );
168  $res = Http::get( $renderUrl, [], $fname );
169  if ( !$res ) {
171  }
172 
173  return $res;
174  }
175  );
176  }
177 
185  public function getDescriptionShortUrl() {
186  $dbr = $this->repo->getReplicaDB();
187  $pageId = $dbr->selectField(
188  'page',
189  'page_id',
190  [
191  'page_namespace' => NS_FILE,
192  'page_title' => $this->title->getDBkey()
193  ]
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:97
WANObjectCache\TTL_UNCACHEABLE
const TTL_UNCACHEABLE
Idiom for getWithSetCallback() callbacks to avoid calling set()
Definition: WANObjectCache.php:177
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
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:83
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
NS_FILE
const NS_FILE
Definition: Defines.php:70
function
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
$res
$res
Definition: database.txt:21
ForeignDBFile\newFromTitle
static newFromTitle( $title, $repo, $unused=null)
Definition: ForeignDBFile.php:40
php
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
$dbr
$dbr
Definition: testCompression.php:50
ForeignDBFile\newFromRow
static newFromRow( $row, $repo)
Create a ForeignDBFile from a title Do not call this except from inside a repo class.
Definition: ForeignDBFile.php:52
File\$url
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:118
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:185
Http\get
static get( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition: Http.php:98
$wgLang
$wgLang
Definition: Setup.php:875
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
ForeignDBFile\publish
publish( $srcPath, $flags=0, array $options=[])
Definition: ForeignDBFile.php:67
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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:949
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:46
null
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:780
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:123
ForeignDBFile\getDescriptionText
getDescriptionText(Language $lang=null)
Definition: ForeignDBFile.php:130
title
title
Definition: parserTests.txt:245
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:114
File\$title
Title string bool $title
Definition: File.php:100
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2035
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:106
File\getName
getName()
Return the name of this file.
Definition: File.php:298
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:103
Wikimedia\Rdbms\DBUnexpectedError
Definition: DBUnexpectedError.php:27
File\readOnlyError
readOnlyError()
Definition: File.php:1781
$cache
$cache
Definition: mcc.php:33
$options
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:1985
$source
$source
Definition: mwdoc-filter.php:46
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:94
MediaWikiServices
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
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
Language
Internationalisation code.
Definition: Language.php:36
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:121