MediaWiki REL1_33
ForeignDBFile.php
Go to the documentation of this file.
1<?php
26
27// @phan-file-suppress PhanTypeMissingReturn false positives
33class 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
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 ) {
170 $ttl = WANObjectCache::TTL_UNCACHEABLE;
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}
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:123
$wgLang
Definition Setup.php:875
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:118
getName()
Return the name of this file.
Definition File.php:298
readOnlyError()
Definition File.php:1781
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:97
Title string bool $title
Definition File.php:100
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2035
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, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition Http.php:98
Internationalisation code.
Definition Language.php:36
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:48
$res
Definition database.txt:21
const NS_FILE
Definition Defines.php:79
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:1999
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:783
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(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition router.php:42
if(!isset( $args[0])) $lang