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
76 public function getDescriptionText( ?Language $lang = null ) {
77 global $wgLang;
78
79 if ( !$this->repo->fetchDescription ) {
80 return false;
81 }
82
83 $lang ??= $wgLang;
84 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
85 if ( !$renderUrl ) {
86 return false;
87 }
88
89 $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
90 ->select( 'page_touched' )
91 ->from( 'page' )
92 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
93 ->caller( __METHOD__ )->fetchField();
94 if ( $touched === false ) {
95 return false; // no description page
96 }
97
98 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
99 $fname = __METHOD__;
100
101 return $cache->getWithSetCallback(
102 $this->repo->getLocalCacheKey(
103 'file-foreign-description',
104 $lang->getCode(),
105 md5( $this->getName() ),
106 $touched
107 ),
108 $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
109 static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
110 wfDebug( "Fetching shared description from $renderUrl" );
111 $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
112 get( $renderUrl, [], $fname );
113 if ( !$res ) {
114 $ttl = WANObjectCache::TTL_UNCACHEABLE;
115 }
116
117 return $res;
118 }
119 );
120 }
121
129 public function getDescriptionShortUrl() {
130 $dbr = $this->repo->getReplicaDB();
131 $pageId = $dbr->newSelectQueryBuilder()
132 ->select( 'page_id' )
133 ->from( 'page' )
134 ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
135 ->caller( __METHOD__ )->fetchField();
136
137 if ( $pageId !== false ) {
138 $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
139 if ( $url !== false ) {
140 return $url;
141 }
142 }
143 return null;
144 }
145
146}
147
149class_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.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Definition Setup.php:551
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition File.php:126
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:70
Service locator for MediaWiki core services.
Represents a title within MediaWiki.
Definition Title.php:70
Multi-datacenter aware caching interface.
Interface for objects representing user identity.