| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Language\Language; |
| 22 |
use MediaWiki\MediaWikiServices; |
| 23 |
use MediaWiki\Status\Status; |
| 24 |
use MediaWiki\Title\Title; |
| 25 |
use MediaWiki\User\UserIdentity; |
| 26 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 27 |
use Wikimedia\Rdbms\DBUnexpectedError; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class ForeignDBFile extends LocalFile { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function getRepo() { |
| 40 |
return $this->repo; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function publish( $srcPath, $flags = 0, array $options = [] ) { |
| 50 |
$this->readOnlyError(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function restore( $versions = [], $unsuppress = false ) { |
| 59 |
$this->readOnlyError(); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function deleteFile( $reason, UserIdentity $user, $suppress = false ) { |
| 69 |
$this->readOnlyError(); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function move( $target ) { |
| 77 |
$this->readOnlyError(); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function getDescriptionUrl() { |
| 84 |
|
| 85 |
return File::getDescriptionUrl(); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 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; |
| 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 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 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 |
} |