MediaWiki  master
ForeignDBFile.php
Go to the documentation of this file.
1 <?php
26 
32 class ForeignDBFile extends LocalFile {
33 
37  public function getRepo() {
38  return $this->repo;
39  }
40 
48  public function publish( $srcPath, $flags = 0, array $options = [] ) {
49  $this->readOnlyError();
50  }
51 
58  public function restore( $versions = [], $unsuppress = false ) {
59  $this->readOnlyError();
60  }
61 
69  public function deleteFile( $reason, UserIdentity $user, $suppress = false ) {
70  $this->readOnlyError();
71  }
72 
78  public function move( $target ) {
79  $this->readOnlyError();
80  }
81 
85  public function getDescriptionUrl() {
86  // Restore remote behavior
87  return File::getDescriptionUrl();
88  }
89 
94  public function getDescriptionText( Language $lang = null ) {
95  global $wgLang;
96 
97  if ( !$this->repo->fetchDescription ) {
98  return false;
99  }
100 
101  $lang ??= $wgLang;
102  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
103  if ( !$renderUrl ) {
104  return false;
105  }
106 
107  $touched = $this->repo->getReplicaDB()->newSelectQueryBuilder()
108  ->select( 'page_touched' )
109  ->from( 'page' )
110  ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
111  ->caller( __METHOD__ )->fetchField();
112  if ( $touched === false ) {
113  return false; // no description page
114  }
115 
116  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
117  $fname = __METHOD__;
118 
119  return $cache->getWithSetCallback(
120  $this->repo->getLocalCacheKey(
121  'file-foreign-description',
122  $lang->getCode(),
123  md5( $this->getName() ),
124  $touched
125  ),
126  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
127  static function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
128  wfDebug( "Fetching shared description from $renderUrl" );
129  $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
130  get( $renderUrl, [], $fname );
131  if ( !$res ) {
132  $ttl = WANObjectCache::TTL_UNCACHEABLE;
133  }
134 
135  return $res;
136  }
137  );
138  }
139 
147  public function getDescriptionShortUrl() {
148  $dbr = $this->repo->getReplicaDB();
149  $pageId = $dbr->newSelectQueryBuilder()
150  ->select( 'page_id' )
151  ->from( 'page' )
152  ->where( [ 'page_namespace' => NS_FILE, 'page_title' => $this->title->getDBkey() ] )
153  ->caller( __METHOD__ )->fetchField();
154 
155  if ( $pageId !== false ) {
156  $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
157  if ( $url !== false ) {
158  return $url;
159  }
160  }
161  return null;
162  }
163 
164 }
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') &&! $wgCommandLineMode) $wgLang
Definition: Setup.php:535
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:138
getName()
Return the name of this file.
Definition: File.php:336
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:117
readOnlyError()
Definition: File.php:1981
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2205
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)
move( $target)
restore( $versions=[], $unsuppress=false)
Base class for language-specific code.
Definition: Language.php:61
Local file in the wiki's own database.
Definition: LocalFile.php:64
Service locator for MediaWiki core services.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:58
Represents a title within MediaWiki.
Definition: Title.php:76
Interface for objects representing user identity.