MediaWiki REL1_39
ForeignDBFile.php
Go to the documentation of this file.
1<?php
24
30class ForeignDBFile extends LocalFile {
31
35 public function getRepo() {
36 return $this->repo;
37 }
38
46 public function publish( $srcPath, $flags = 0, array $options = [] ) {
47 $this->readOnlyError();
48 }
49
56 public function restore( $versions = [], $unsuppress = false ) {
57 $this->readOnlyError();
58 }
59
67 public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
68 $this->readOnlyError();
69 }
70
76 public function move( $target ) {
77 $this->readOnlyError();
78 }
79
83 public function getDescriptionUrl() {
84 // Restore remote behavior
86 }
87
92 public function getDescriptionText( Language $lang = null ) {
93 global $wgLang;
94
95 if ( !$this->repo->fetchDescription ) {
96 return false;
97 }
98
99 $lang = $lang ?? $wgLang;
100 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
101 if ( !$renderUrl ) {
102 return false;
103 }
104
105 $touched = $this->repo->getReplicaDB()->selectField(
106 'page',
107 'page_touched',
108 [
109 'page_namespace' => NS_FILE,
110 'page_title' => $this->title->getDBkey()
111 ],
112 __METHOD__
113 );
114 if ( $touched === false ) {
115 return false; // no description page
116 }
117
118 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
119 $fname = __METHOD__;
120
121 return $cache->getWithSetCallback(
122 $this->repo->getLocalCacheKey(
123 'file-foreign-description',
124 $lang->getCode(),
125 md5( $this->getName() ),
126 $touched
127 ),
128 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
129 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
130 wfDebug( "Fetching shared description from $renderUrl" );
131 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
132 get( $renderUrl, [], $fname );
133 if ( !$res ) {
134 $ttl = WANObjectCache::TTL_UNCACHEABLE;
135 }
136
137 return $res;
138 }
139 );
140 }
141
149 public function getDescriptionShortUrl() {
150 $dbr = $this->repo->getReplicaDB();
151 $pageId = $dbr->selectField(
152 'page',
153 'page_id',
154 [
155 'page_namespace' => NS_FILE,
156 'page_title' => $this->title->getDBkey()
157 ],
158 __METHOD__
159 );
160
161 if ( $pageId !== false ) {
162 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
163 if ( $url !== false ) {
164 return $url;
165 }
166 }
167 return null;
168 }
169
170}
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.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
Definition Setup.php:497
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:135
getName()
Return the name of this file.
Definition File.php:333
readOnlyError()
Definition File.php:1981
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:114
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2208
Foreign file from a reachable database in the same wiki farm.
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)
Base class for language-specific code.
Definition Language.php:53
Local file in the wiki's own database.
Definition LocalFile.php:60
Service locator for MediaWiki core services.
Interface for objects representing user identity.
$cache
Definition mcc.php:33
if(!isset( $args[0])) $lang