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