MediaWiki  1.32.0
ForeignDBFile.php
Go to the documentation of this file.
1 <?php
26 
32 class ForeignDBFile extends LocalFile {
39  static function newFromTitle( $title, $repo, $unused = null ) {
40  return new self( $title, $repo );
41  }
42 
51  static function newFromRow( $row, $repo ) {
52  $title = Title::makeTitle( NS_FILE, $row->img_name );
53  $file = new self( $title, $repo );
54  $file->loadFromRow( $row );
55 
56  return $file;
57  }
58 
66  function publish( $srcPath, $flags = 0, array $options = [] ) {
67  $this->readOnlyError();
68  }
69 
82  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
83  $watch = false, $timestamp = false, User $user = null ) {
84  $this->readOnlyError();
85  }
86 
93  function restore( $versions = [], $unsuppress = false ) {
94  $this->readOnlyError();
95  }
96 
104  function delete( $reason, $suppress = false, $user = null ) {
105  $this->readOnlyError();
106  }
107 
113  function move( $target ) {
114  $this->readOnlyError();
115  }
116 
120  function getDescriptionUrl() {
121  // Restore remote behavior
122  return File::getDescriptionUrl();
123  }
124 
129  function getDescriptionText( Language $lang = null ) {
130  global $wgLang;
131 
132  if ( !$this->repo->fetchDescription ) {
133  return false;
134  }
135 
136  $lang = $lang ?? $wgLang;
137  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
138  if ( !$renderUrl ) {
139  return false;
140  }
141 
142  $touched = $this->repo->getReplicaDB()->selectField(
143  'page',
144  'page_touched',
145  [
146  'page_namespace' => NS_FILE,
147  'page_title' => $this->title->getDBkey()
148  ]
149  );
150  if ( $touched === false ) {
151  return false; // no description page
152  }
153 
154  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
155  $fname = __METHOD__;
156 
157  return $cache->getWithSetCallback(
158  $this->repo->getLocalCacheKey(
159  'ForeignFileDescription',
160  $lang->getCode(),
161  md5( $this->getName() ),
162  $touched
163  ),
164  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
165  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
166  wfDebug( "Fetching shared description from $renderUrl\n" );
167  $res = Http::get( $renderUrl, [], $fname );
168  if ( !$res ) {
170  }
171 
172  return $res;
173  }
174  );
175  }
176 
184  public function getDescriptionShortUrl() {
185  $dbr = $this->repo->getReplicaDB();
186  $pageId = $dbr->selectField(
187  'page',
188  'page_id',
189  [
190  'page_namespace' => NS_FILE,
191  'page_title' => $this->title->getDBkey()
192  ]
193  );
194 
195  if ( $pageId !== false ) {
196  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
197  if ( $url !== false ) {
198  return $url;
199  }
200  }
201  return null;
202  }
203 
204 }
File\$repo
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:96
WANObjectCache\TTL_UNCACHEABLE
const TTL_UNCACHEABLE
Idiom for getWithSetCallback() callbacks to avoid calling set()
Definition: WANObjectCache.php:184
ForeignDBFile
Foreign file with an accessible MediaWiki database.
Definition: ForeignDBFile.php:32
ForeignDBFile\recordUpload
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
Definition: ForeignDBFile.php:82
$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:39
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:51
File\$url
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:117
ForeignDBFile\getDescriptionShortUrl
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
Definition: ForeignDBFile.php:184
$wgLang
$wgLang
Definition: Setup.php:902
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:545
ForeignDBFile\publish
publish( $srcPath, $flags=0, array $options=[])
Definition: ForeignDBFile.php:66
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:988
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:46
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:121
Http\get
static get( $url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition: Http.php:98
ForeignDBFile\getDescriptionText
getDescriptionText(Language $lang=null)
Definition: ForeignDBFile.php:129
title
title
Definition: parserTests.txt:239
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:113
File\$title
Title string bool $title
Definition: File.php:99
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2043
LocalFile\$user
User $user
Uploader.
Definition: LocalFile.php:106
File\getName
getName()
Return the name of this file.
Definition: File.php:297
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:103
Wikimedia\Rdbms\DBUnexpectedError
Definition: DBUnexpectedError.php:27
File\readOnlyError
readOnlyError()
Definition: File.php:1789
$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:2036
$source
$source
Definition: mwdoc-filter.php:46
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:93
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:47
Language
Internationalisation code.
Definition: Language.php:35
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:120