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}
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.
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
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
const NS_FILE
Definition Defines.php:70
$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
if(!isset( $args[0])) $lang