MediaWiki REL1_34
ForeignDBFile.php
Go to the documentation of this file.
1<?php
26
27// @phan-file-suppress PhanTypeMissingReturn false positives
33class ForeignDBFile extends LocalFile {
34
42 function publish( $srcPath, $flags = 0, array $options = [] ) {
43 $this->readOnlyError();
44 }
45
58 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
59 $watch = false, $timestamp = false, User $user = null ) {
60 $this->readOnlyError();
61 }
62
69 function restore( $versions = [], $unsuppress = false ) {
70 $this->readOnlyError();
71 }
72
80 function delete( $reason, $suppress = false, $user = null ) {
81 $this->readOnlyError();
82 }
83
89 function move( $target ) {
90 $this->readOnlyError();
91 }
92
96 function getDescriptionUrl() {
97 // Restore remote behavior
99 }
100
105 function getDescriptionText( Language $lang = null ) {
106 global $wgLang;
107
108 if ( !$this->repo->fetchDescription ) {
109 return false;
110 }
111
112 $lang = $lang ?? $wgLang;
113 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
114 if ( !$renderUrl ) {
115 return false;
116 }
117
118 $touched = $this->repo->getReplicaDB()->selectField(
119 'page',
120 'page_touched',
121 [
122 'page_namespace' => NS_FILE,
123 'page_title' => $this->title->getDBkey()
124 ]
125 );
126 if ( $touched === false ) {
127 return false; // no description page
128 }
129
130 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
131 $fname = __METHOD__;
132
133 return $cache->getWithSetCallback(
134 $this->repo->getLocalCacheKey(
135 'ForeignFileDescription',
136 $lang->getCode(),
137 md5( $this->getName() ),
138 $touched
139 ),
140 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
141 function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
142 wfDebug( "Fetching shared description from $renderUrl\n" );
143 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
144 get( $renderUrl, [], $fname );
145 if ( !$res ) {
146 $ttl = WANObjectCache::TTL_UNCACHEABLE;
147 }
148
149 return $res;
150 }
151 );
152 }
153
161 public function getDescriptionShortUrl() {
162 $dbr = $this->repo->getReplicaDB();
163 $pageId = $dbr->selectField(
164 'page',
165 'page_id',
166 [
167 'page_namespace' => NS_FILE,
168 'page_title' => $this->title->getDBkey()
169 ]
170 );
171
172 if ( $pageId !== false ) {
173 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
174 if ( $url !== false ) {
175 return $url;
176 }
177 }
178 return null;
179 }
180
181}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
$wgLang
Definition Setup.php:880
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:127
getName()
Return the name of this file.
Definition File.php:307
readOnlyError()
Definition File.php:1794
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2047
Foreign file with an accessible MediaWiki database.
publish( $srcPath, $flags=0, array $options=[])
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)
Internationalisation code.
Definition Language.php:37
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:56
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:51
const NS_FILE
Definition Defines.php:75
$cache
Definition mcc.php:33
$source
if(!isset( $args[0])) $lang