25use Cdb\Exception as CdbException;
26use Cdb\Reader as CdbReader;
125 $this->hookRunner =
new HookRunner( $hookContainer );
139 $result = $this->
fetch( $prefix );
141 return (
bool)$result;
151 if ( $prefix ==
'' ) {
155 $prefix = $this->contLang->lc( $prefix );
156 if ( $this->localCache->has( $prefix ) ) {
157 return $this->localCache->get( $prefix );
160 if ( $this->cdbData ) {
163 $iw = $this->
load( $prefix );
168 $this->localCache->set( $prefix, $iw );
179 $this->localCache->clear();
187 $this->localCache->clear( $prefix );
189 $key = $this->objectCache->makeKey(
'interwiki', $prefix );
190 $this->objectCache->delete( $key );
206 list( $local, $url ) = explode(
' ', $value, 2 );
207 return new Interwiki( $prefix, $url,
'',
'', (
int)$local );
222 wfDebug( __METHOD__ .
"( $prefix )" );
224 $wikiId = WikiMap::getCurrentWikiId();
229 if ( $this->interwikiScopes >= 3 && !$this->thisSite ) {
230 $this->thisSite = $this->
getCacheValue(
'__sites:' . $wikiId );
231 if ( $this->thisSite ==
'' ) {
238 if ( $value ==
'' && $this->interwikiScopes >= 3 ) {
239 $value = $this->
getCacheValue(
"_{$this->thisSite}:{$prefix}" );
242 if ( $value ==
'' && $this->interwikiScopes >= 2 ) {
245 if ( $value ==
'undef' ) {
248 }
catch ( CdbException $e ) {
249 wfDebug( __METHOD__ .
": CdbException caught, error message was "
250 . $e->getMessage() );
257 if ( $this->cdbReader ===
null ) {
258 if ( is_string( $this->cdbData ) ) {
259 $this->cdbReader = \Cdb\Reader::open( $this->cdbData );
260 } elseif ( is_array( $this->cdbData ) ) {
261 $this->cdbReader = new \Cdb\Reader\Hash( $this->cdbData );
263 $this->cdbReader =
false;
267 if ( $this->cdbReader ) {
268 return $this->cdbReader->get( $key );
280 private function load( $prefix ) {
282 if ( !$this->hookRunner->onInterwikiLoadPrefix( $prefix, $iwData ) ) {
286 if ( is_array( $iwData ) ) {
294 $iwData = $this->objectCache->getWithSetCallback(
295 $this->objectCache->makeKey(
'interwiki', $prefix ),
296 $this->objectCacheExpiry,
297 function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix, $fname ) {
300 $setOpts += Database::getCacheSetOptions(
$dbr );
302 $row =
$dbr->selectRow(
304 self::selectFields(),
305 [
'iw_prefix' => $prefix ],
309 return $row ? (array)$row :
'!NONEXISTENT';
313 if ( is_array( $iwData ) ) {
327 if ( isset( $mc[
'iw_url'] ) ) {
328 $url = $mc[
'iw_url'];
329 $local = $mc[
'iw_local'] ?? 0;
330 $trans = $mc[
'iw_trans'] ?? 0;
331 $api = $mc[
'iw_api'] ??
'';
332 $wikiId = $mc[
'iw_wikiid'] ??
'';
334 return new Interwiki(
null, $url, $api, $wikiId, $local, $trans );
349 $wikiId = WikiMap::getCurrentWikiId();
354 if ( $this->interwikiScopes >= 3 && !$this->thisSite ) {
360 $this->thisSite = $site;
367 if ( $this->interwikiScopes >= 2 ) {
368 $sources[] =
'__global';
371 if ( $this->interwikiScopes >= 3 ) {
374 $sources[] = $wikiId;
376 foreach ( $sources as
$source ) {
378 foreach ( explode(
' ', $list ) as $iw_prefix ) {
384 list( $iw_local, $iw_url ) = explode(
' ', $row );
386 if ( $local !==
null && $local != $iw_local ) {
390 $data[$iw_prefix] = [
391 'iw_prefix' => $iw_prefix,
393 'iw_local' => $iw_local,
397 }
catch ( CdbException $e ) {
398 wfDebug( __METHOD__ .
": CdbException caught, error message was "
399 . $e->getMessage() );
402 return array_values( $data );
416 if ( $local !==
null ) {
418 $where[
'iw_local'] = 1;
419 } elseif ( $local == 0 ) {
420 $where[
'iw_local'] = 0;
424 $res = $db->select(
'interwiki',
425 self::selectFields(),
426 $where, __METHOD__, [
'ORDER BY' =>
'iw_prefix' ]
430 foreach (
$res as $row ) {
431 $retval[] = (array)$row;
444 if ( $this->cdbData ) {
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Value object for representing interwiki records.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Handles a simple LRU key/value map with a maximum number of entries.
Multi-datacenter aware caching interface.
Helper tools for dealing with other locally-hosted wikis.