MediaWiki master
ForeignDBFile.php
Go to the documentation of this file.
1<?php
28
34class ForeignDBFile extends LocalFile {
35
39 public function getRepo() {
40 return $this->repo;
41 }
42
49 public function publish( $srcPath, $flags = 0, array $options = [] ) {
50 $this->readOnlyError();
51 }
52
58 public function restore( $versions = [], $unsuppress = false ) {
59 $this->readOnlyError();
60 }
61
68 public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
69 $this->readOnlyError();
70 }
71
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 ??= $wgLang;
100 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
101 if ( !$renderUrl ) {
102 return false;
103 }
104
105 $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
106 ->select( 'page_touched' )
107 ->from( 'page' )
108 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
109 ->caller( __METHOD__ )->fetchField();
110 if ( $touched === false ) {
111 return false; // no description page
112 }
113
114 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
115 $fname = __METHOD__;
116
117 return $cache->getWithSetCallback(
118 $this->repo->getLocalCacheKey(
119 'file-foreign-description',
120 $lang->getCode(),
121 md5( $this->getName() ),
122 $touched
123 ),
124 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
125 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
126 wfDebug( "Fetching shared description from $renderUrl" );
127 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
128 get( $renderUrl, [], $fname );
129 if ( !$res ) {
130 $ttl = WANObjectCache::TTL_UNCACHEABLE;
131 }
132
133 return $res;
134 }
135 );
136 }
137
145 public function getDescriptionShortUrl() {
146 $dbr = $this->repo->getReplicaDB();
147 $pageId = $dbr->newSelectQueryBuilder()
148 ->select( 'page_id' )
149 ->from( 'page' )
150 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
151 ->caller( __METHOD__ )->fetchField();
152
153 if ( $pageId !== false ) {
154 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
155 if ( $url !== false ) {
156 return $url;
157 }
158 }
159 return null;
160 }
161
162}
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:540
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:147
getName()
Return the name of this file.
Definition File.php:344
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:123
readOnlyError()
Definition File.php:1992
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2216
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)
Local file in the wiki's own database.
Definition LocalFile.php:74
Base class for language-specific code.
Definition Language.php:78
Service locator for MediaWiki core services.
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.