MediaWiki  1.30.0
ForeignDBFile.php
Go to the documentation of this file.
1 <?php
25 
31 class ForeignDBFile extends LocalFile {
38  static function newFromTitle( $title, $repo, $unused = null ) {
39  return new self( $title, $repo );
40  }
41 
50  static function newFromRow( $row, $repo ) {
51  $title = Title::makeTitle( NS_FILE, $row->img_name );
52  $file = new self( $title, $repo );
53  $file->loadFromRow( $row );
54 
55  return $file;
56  }
57 
65  function publish( $srcPath, $flags = 0, array $options = [] ) {
66  $this->readOnlyError();
67  }
68 
81  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
82  $watch = false, $timestamp = false, User $user = null ) {
83  $this->readOnlyError();
84  }
85 
92  function restore( $versions = [], $unsuppress = false ) {
93  $this->readOnlyError();
94  }
95 
103  function delete( $reason, $suppress = false, $user = null ) {
104  $this->readOnlyError();
105  }
106 
112  function move( $target ) {
113  $this->readOnlyError();
114  }
115 
119  function getDescriptionUrl() {
120  // Restore remote behavior
121  return File::getDescriptionUrl();
122  }
123 
128  function getDescriptionText( $lang = null ) {
129  global $wgLang;
130 
131  if ( !$this->repo->fetchDescription ) {
132  return false;
133  }
134 
135  $lang = $lang ?: $wgLang;
136  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
137  if ( !$renderUrl ) {
138  return false;
139  }
140 
141  $touched = $this->repo->getReplicaDB()->selectField(
142  'page',
143  'page_touched',
144  [
145  'page_namespace' => NS_FILE,
146  'page_title' => $this->title->getDBkey()
147  ]
148  );
149  if ( $touched === false ) {
150  return false; // no description page
151  }
152 
154 
155  return $cache->getWithSetCallback(
156  $this->repo->getLocalCacheKey(
157  'RemoteFileDescription',
158  'url',
159  $lang->getCode(),
160  $this->getName(),
161  $touched
162  ),
163  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
164  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
165  wfDebug( "Fetching shared description from $renderUrl\n" );
166  $res = Http::get( $renderUrl, [], __METHOD__ );
167  if ( !$res ) {
169  }
170 
171  return $res;
172  }
173  );
174  }
175 
183  public function getDescriptionShortUrl() {
184  $dbr = $this->repo->getReplicaDB();
185  $pageId = $dbr->selectField(
186  'page',
187  'page_id',
188  [
189  'page_namespace' => NS_FILE,
190  'page_title' => $this->title->getDBkey()
191  ]
192  );
193 
194  if ( $pageId !== false ) {
195  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
196  if ( $url !== false ) {
197  return $url;
198  }
199  }
200  return null;
201  }
202 
203 }
ForeignDBFile\getDescriptionText
getDescriptionText( $lang=null)
Definition: ForeignDBFile.php:128
function
when a variable name is used in a function
Definition: design.txt:93
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:128
ForeignDBFile
Foreign file with an accessible MediaWiki database.
Definition: ForeignDBFile.php:31
ForeignDBFile\recordUpload
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
Definition: ForeignDBFile.php:81
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
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
LocalFile\$user
int $user
User ID of uploader.
Definition: LocalFile.php:105
NS_FILE
const NS_FILE
Definition: Defines.php:71
$res
$res
Definition: database.txt:21
ForeignDBFile\newFromTitle
static newFromTitle( $title, $repo, $unused=null)
Definition: ForeignDBFile.php:38
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
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
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:50
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:183
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:529
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ForeignDBFile\publish
publish( $srcPath, $flags=0, array $options=[])
Definition: ForeignDBFile.php:65
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:1047
LocalFile
Class to represent a local file in the wiki's own database.
Definition: LocalFile.php:45
Http\get
static get( $url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition: Http.php:98
ForeignDBFile\move
move( $target)
Definition: ForeignDBFile.php:112
File\$title
Title string bool $title
Definition: File.php:99
File\getDescriptionUrl
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2022
File\getName
getName()
Return the name of this file.
Definition: File.php:297
LocalFile\$timestamp
string $timestamp
Upload timestamp.
Definition: LocalFile.php:102
Wikimedia\Rdbms\DBUnexpectedError
Definition: DBUnexpectedError.php:27
File\readOnlyError
readOnlyError()
Definition: File.php:1768
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
$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:1965
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
$source
$source
Definition: mwdoc-filter.php:46
ForeignDBFile\restore
restore( $versions=[], $unsuppress=false)
Definition: ForeignDBFile.php:92
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2801
ForeignDBFile\getDescriptionUrl
getDescriptionUrl()
Definition: ForeignDBFile.php:119
array
the array() calling protocol came about after MediaWiki 1.4rc1.