MediaWiki master
ForeignDBFile.php
Go to the documentation of this file.
1<?php
26
32class ForeignDBFile extends LocalFile {
33
37 public function getRepo() {
38 return $this->repo;
39 }
40
47 public function publish( $srcPath, $flags = 0, array $options = [] ) {
48 $this->readOnlyError();
49 }
50
56 public function restore( $versions = [], $unsuppress = false ) {
57 $this->readOnlyError();
58 }
59
66 public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
67 $this->readOnlyError();
68 }
69
74 public function move( $target ) {
75 $this->readOnlyError();
76 }
77
81 public function getDescriptionUrl() {
82 // Restore remote behavior
84 }
85
90 public function getDescriptionText( Language $lang = null ) {
91 global $wgLang;
92
93 if ( !$this->repo->fetchDescription ) {
94 return false;
95 }
96
97 $lang ??= $wgLang;
98 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
99 if ( !$renderUrl ) {
100 return false;
101 }
102
103 $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
104 ->select( 'page_touched' )
105 ->from( 'page' )
106 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
107 ->caller( __METHOD__ )->fetchField();
108 if ( $touched === false ) {
109 return false; // no description page
110 }
111
112 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
113 $fname = __METHOD__;
114
115 return $cache->getWithSetCallback(
116 $this->repo->getLocalCacheKey(
117 'file-foreign-description',
118 $lang->getCode(),
119 md5( $this->getName() ),
120 $touched
121 ),
122 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
123 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
124 wfDebug( "Fetching shared description from $renderUrl" );
125 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
126 get( $renderUrl, [], $fname );
127 if ( !$res ) {
128 $ttl = WANObjectCache::TTL_UNCACHEABLE;
129 }
130
131 return $res;
132 }
133 );
134 }
135
143 public function getDescriptionShortUrl() {
144 $dbr = $this->repo->getReplicaDB();
145 $pageId = $dbr->newSelectQueryBuilder()
146 ->select( 'page_id' )
147 ->from( 'page' )
148 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
149 ->caller( __METHOD__ )->fetchField();
150
151 if ( $pageId !== false ) {
152 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
153 if ( $url !== false ) {
154 return $url;
155 }
156 }
157 return null;
158 }
159
160}
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') &&MW_ENTRY_POINT !=='cli' $wgLang
Definition Setup.php:536
string $url
The URL corresponding to one of the four basic zones.
Definition File.php:144
getName()
Return the name of this file.
Definition File.php:341
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:120
readOnlyError()
Definition File.php:1987
getDescriptionUrl()
Get the URL of the image description page.
Definition File.php:2211
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:63
Local file in the wiki's own database.
Definition LocalFile.php:68
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
Interface for objects representing user identity.