MediaWiki REL1_31
ForeignDBFile.php
Go to the documentation of this file.
1<?php
25
31class 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
122 }
123
128 function getDescriptionText( $lang = null ) {
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
153 $cache = ObjectCache::getMainWANInstance();
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 ) {
168 $ttl = WANObjectCache::TTL_UNCACHEABLE;
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:117
getName()
Return the name of this file.
Definition File.php:297
readOnlyError()
Definition File.php:1789
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:96
Title string bool $title
Definition File.php:99
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2043
Foreign file with an accessible MediaWiki database.
getDescriptionText( $lang=null)
publish( $srcPath, $flags=0, array $options=[])
static newFromRow( $row, $repo)
Create a ForeignDBFile from a title Do not call this except from inside a repo class.
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
restore( $versions=[], $unsuppress=false)
recordUpload( $oldver, $desc, $license='', $copyStatus='', $source='', $watch=false, $timestamp=false, User $user=null)
static newFromTitle( $title, $repo, $unused=null)
static get( $url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition Http.php:98
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:46
string $timestamp
Upload timestamp.
User $user
Uploader.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
$res
Definition database.txt:21
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
const NS_FILE
Definition Defines.php:80
the array() calling protocol came about after MediaWiki 1.4rc1.
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:2001
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:37
$cache
Definition mcc.php:33
$source
title
if(!isset( $args[0])) $lang