MediaWiki REL1_37
ForeignDBFile.php
Go to the documentation of this file.
1<?php
27
33class ForeignDBFile extends LocalFile {
34
38 public function getRepo() {
39 return $this->repo;
40 }
41
49 public function publish( $srcPath, $flags = 0, array $options = [] ) {
50 $this->readOnlyError();
51 }
52
59 public function restore( $versions = [], $unsuppress = false ) {
60 $this->readOnlyError();
61 }
62
70 public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
71 $this->readOnlyError();
72 }
73
79 public function move( $target ) {
80 $this->readOnlyError();
81 }
82
86 public function getDescriptionUrl() {
87 // Restore remote behavior
89 }
90
95 public function getDescriptionText( Language $lang = null ) {
96 global $wgLang;
97
98 if ( !$this->repo->fetchDescription ) {
99 return false;
100 }
101
102 $lang = $lang ?? $wgLang;
103 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
104 if ( !$renderUrl ) {
105 return false;
106 }
107
108 $touched = $this->repo->getReplicaDB()->selectField(
109 'page',
110 'page_touched',
111 [
112 'page_namespace' => NS_FILE,
113 'page_title' => $this->title->getDBkey()
114 ],
115 __METHOD__
116 );
117 if ( $touched === false ) {
118 return false; // no description page
119 }
120
121 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
122 $fname = __METHOD__;
123
124 return $cache->getWithSetCallback(
125 $this->repo->getLocalCacheKey(
126 'file-foreign-description',
127 $lang->getCode(),
128 md5( $this->getName() ),
129 $touched
130 ),
131 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
132 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
133 wfDebug( "Fetching shared description from $renderUrl" );
134 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
135 get( $renderUrl, [], $fname );
136 if ( !$res ) {
137 $ttl = WANObjectCache::TTL_UNCACHEABLE;
138 }
139
140 return $res;
141 }
142 );
143 }
144
152 public function getDescriptionShortUrl() {
153 $dbr = $this->repo->getReplicaDB();
154 $pageId = $dbr->selectField(
155 'page',
156 'page_id',
157 [
158 'page_namespace' => NS_FILE,
159 'page_title' => $this->title->getDBkey()
160 ],
161 __METHOD__
162 );
163
164 if ( $pageId !== false ) {
165 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
166 if ( $url !== false ) {
167 return $url;
168 }
169 }
170 return null;
171 }
172
173}
const NS_FILE
Definition Defines.php:70
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:831
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:134
getName()
Return the name of this file.
Definition File.php:330
readOnlyError()
Definition File.php:1967
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:113
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2215
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.
deleteFile( $reason, UserIdentity $user, $suppress=false)
restore( $versions=[], $unsuppress=false)
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:42
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:63
UserIdentity null $user
Uploader.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Interface for objects representing user identity.
$cache
Definition mcc.php:33
if(!isset( $args[0])) $lang