MediaWiki master
ForeignDBFile.php
Go to the documentation of this file.
1<?php
22
31
37class ForeignDBFile extends LocalFile {
38
42 public function getRepo() {
43 return $this->repo;
44 }
45
52 public function publish( $srcPath, $flags = 0, array $options = [] ) {
53 $this->readOnlyError();
54 }
55
61 public function restore( $versions = [], $unsuppress = false ) {
62 $this->readOnlyError();
63 }
64
71 public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
72 $this->readOnlyError();
73 }
74
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 ??= $wgLang;
103 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
104 if ( !$renderUrl ) {
105 return false;
106 }
107
108 $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
109 ->select( 'page_touched' )
110 ->from( 'page' )
111 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
112 ->caller( __METHOD__ )->fetchField();
113 if ( $touched === false ) {
114 return false; // no description page
115 }
116
117 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
118 $fname = __METHOD__;
119
120 return $cache->getWithSetCallback(
121 $this->repo->getLocalCacheKey(
122 'file-foreign-description',
123 $lang->getCode(),
124 md5( $this->getName() ),
125 $touched
126 ),
127 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
128 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
129 wfDebug( "Fetching shared description from $renderUrl" );
130 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
131 get( $renderUrl, [], $fname );
132 if ( !$res ) {
133 $ttl = WANObjectCache::TTL_UNCACHEABLE;
134 }
135
136 return $res;
137 }
138 );
139 }
140
148 public function getDescriptionShortUrl() {
149 $dbr = $this->repo->getReplicaDB();
150 $pageId = $dbr->newSelectQueryBuilder()
151 ->select( 'page_id' )
152 ->from( 'page' )
153 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
154 ->caller( __METHOD__ )->fetchField();
155
156 if ( $pageId !== false ) {
157 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
158 if ( $url !== false ) {
159 return $url;
160 }
161 }
162 return null;
163 }
164
165}
166
168class_alias( ForeignDBFile::class, 'ForeignDBFile' );
const NS_FILE
Definition Defines.php:71
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') &&MW_ENTRY_POINT !=='cli' $wgLang
Definition Setup.php:563
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:140
string null $url
The URL corresponding to one of the four basic zones.
Definition File.php:164
getName()
Return the name of this file.
Definition File.php:361
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2299
Foreign file from a reachable database in the same wiki farm.
getDescriptionShortUrl()
Get short description URL for a file based on the page ID.
publish( $srcPath, $flags=0, array $options=[])
deleteFile( $reason, UserIdentity $user, $suppress=false)
restore( $versions=[], $unsuppress=false)
getDescriptionText(?Language $lang=null)
Local file in the wiki's own database.
Definition LocalFile.php:93
A foreign repository with an accessible MediaWiki database.
Base class for language-specific code.
Definition Language.php:81
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Represents a title within MediaWiki.
Definition Title.php:78
Multi-datacenter aware caching interface.
Interface for objects representing user identity.