MediaWiki master
ForeignDBFile.php
Go to the documentation of this file.
1<?php
8
16
22class ForeignDBFile extends LocalFile {
23
27 public function getRepo() {
28 return $this->repo;
29 }
30
36 public function publish( $srcPath, $flags = 0, array $options = [] ): never {
37 $this->readOnlyError();
38 }
39
44 public function restore( $versions = [], $unsuppress = false ): never {
45 $this->readOnlyError();
46 }
47
53 public function deleteFile( $reason, UserIdentity $user, $suppress = false ): never {
54 $this->readOnlyError();
55 }
56
60 public function move( $target ): never {
61 $this->readOnlyError();
62 }
63
67 public function getDescriptionUrl() {
68 // Restore remote behavior
69 return File::getDescriptionUrl();
70 }
71
77 public function getDescriptionText( ?Language $lang = null ) {
78 if ( !$this->repo->fetchDescription ) {
79 return false;
80 }
81
82 if ( $lang === null ) {
83 wfDeprecatedMsg( 'Calling File::getDescriptionText without a lang parameter ' .
84 'was deprecated in MediaWiki 1.46', '1.46' );
85 global $wgLang;
86 $lang = $wgLang;
87 }
88
89 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
90 if ( !$renderUrl ) {
91 return false;
92 }
93
94 $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
95 ->select( 'page_touched' )
96 ->from( 'page' )
97 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
98 ->caller( __METHOD__ )->fetchField();
99 if ( $touched === false ) {
100 return false; // no description page
101 }
102
103 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
104 $fname = __METHOD__;
105
106 return $cache->getWithSetCallback(
107 $this->repo->getLocalCacheKey(
108 'file-foreign-description',
109 $lang->getCode(),
110 md5( $this->getName() ),
111 $touched
112 ),
113 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
114 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
115 wfDebug( "Fetching shared description from $renderUrl" );
116 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
117 get( $renderUrl, [], $fname );
118 if ( !$res ) {
119 $ttl = WANObjectCache::TTL_UNCACHEABLE;
120 }
121
122 return $res;
123 }
124 );
125 }
126
134 public function getDescriptionShortUrl() {
135 $dbr = $this->repo->getReplicaDB();
136 $pageId = $dbr->newSelectQueryBuilder()
137 ->select( 'page_id' )
138 ->from( 'page' )
139 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
140 ->caller( __METHOD__ )->fetchField();
141
142 if ( $pageId !== false ) {
143 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
144 if ( $url !== false ) {
145 return $url;
146 }
147 }
148 return null;
149 }
150
151}
152
154class_alias( ForeignDBFile::class, 'ForeignDBFile' );
const NS_FILE
Definition Defines.php:57
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
$wgLang
Definition Setup.php:554
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:127
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:81
A foreign repository with an accessible MediaWiki database.
Base class for language-specific code.
Definition Language.php:65
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:69
Multi-datacenter aware caching interface.
Interface for objects representing user identity.