MediaWiki REL1_32
ForeignDBFile.php
Go to the documentation of this file.
1<?php
26
32class 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
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 ) {
169 $ttl = WANObjectCache::TTL_UNCACHEABLE;
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}
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.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:121
$wgLang
Definition Setup.php:910
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.
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.
getDescriptionText(Language $lang=null)
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
Internationalisation code.
Definition Language.php:35
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:46
string $timestamp
Upload timestamp.
User $user
Uploader.
MediaWikiServices is the service locator for the application scope of MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
$res
Definition database.txt:21
const NS_FILE
Definition Defines.php:70
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:2050
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
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))
$source
title
if(!isset( $args[0])) $lang