25 use Cdb\Exception as CdbException;
26 use Cdb\Reader as CdbReader;
132 $result = $this->
fetch( $prefix );
134 return (
bool)$result;
144 if ( $prefix ==
'' ) {
148 $prefix = $this->contLang->lc( $prefix );
149 if ( $this->localCache->has( $prefix ) ) {
150 return $this->localCache->get( $prefix );
153 if ( $this->cdbData ) {
156 $iw = $this->
load( $prefix );
161 $this->localCache->set( $prefix, $iw );
172 $this->localCache->clear();
180 $this->localCache->clear( $prefix );
182 $key = $this->objectCache->makeKey(
'interwiki', $prefix );
183 $this->objectCache->delete( $key );
199 list( $local, $url ) = explode(
' ', $value, 2 );
200 return new Interwiki( $prefix, $url,
'',
'', (
int)$local );
215 wfDebug( __METHOD__ .
"( $prefix )\n" );
222 if ( $this->interwikiScopes >= 3 && !$this->thisSite ) {
223 $this->thisSite = $this->
getCacheValue(
'__sites:' . $wikiId );
224 if ( $this->thisSite ==
'' ) {
231 if ( $value ==
'' && $this->interwikiScopes >= 3 ) {
232 $value = $this->
getCacheValue(
"_{$this->thisSite}:{$prefix}" );
235 if ( $value ==
'' && $this->interwikiScopes >= 2 ) {
238 if ( $value ==
'undef' ) {
241 }
catch ( CdbException $e ) {
242 wfDebug( __METHOD__ .
": CdbException caught, error message was "
243 . $e->getMessage() );
250 if ( $this->cdbReader ===
null ) {
251 if ( is_string( $this->cdbData ) ) {
252 $this->cdbReader = \Cdb\Reader::open( $this->cdbData );
253 } elseif ( is_array( $this->cdbData ) ) {
254 $this->cdbReader = new \Cdb\Reader\Hash( $this->cdbData );
256 $this->cdbReader =
false;
260 if ( $this->cdbReader ) {
261 return $this->cdbReader->get( $key );
273 private function load( $prefix ) {
275 if ( !
Hooks::run(
'InterwikiLoadPrefix', [ $prefix, &$iwData ] ) ) {
279 if ( is_array( $iwData ) ) {
287 $iwData = $this->objectCache->getWithSetCallback(
288 $this->objectCache->makeKey(
'interwiki', $prefix ),
290 function ( $oldValue, &$ttl, array &$setOpts ) use ( $prefix, $fname ) {
295 $row =
$dbr->selectRow(
297 self::selectFields(),
298 [
'iw_prefix' => $prefix ],
302 return $row ? (array)$row :
'!NONEXISTENT';
306 if ( is_array( $iwData ) ) {
320 if ( isset( $mc[
'iw_url'] ) ) {
321 $url = $mc[
'iw_url'];
322 $local = $mc[
'iw_local'] ?? 0;
323 $trans = $mc[
'iw_trans'] ?? 0;
324 $api = $mc[
'iw_api'] ??
'';
325 $wikiId = $mc[
'iw_wikiid'] ??
'';
327 return new Interwiki(
null, $url, $api, $wikiId, $local, $trans );
340 wfDebug( __METHOD__ .
"()\n" );
347 if ( $this->interwikiScopes >= 3 && !$this->thisSite ) {
353 $this->thisSite = $site;
360 if ( $this->interwikiScopes >= 2 ) {
361 $sources[] =
'__global';
364 if ( $this->interwikiScopes >= 3 ) {
367 $sources[] = $wikiId;
369 foreach ( $sources as
$source ) {
371 foreach ( explode(
' ', $list ) as $iw_prefix ) {
377 list( $iw_local, $iw_url ) = explode(
' ', $row );
379 if ( $local !==
null && $local != $iw_local ) {
383 $data[$iw_prefix] = [
384 'iw_prefix' => $iw_prefix,
386 'iw_local' => $iw_local,
390 }
catch ( CdbException $e ) {
391 wfDebug( __METHOD__ .
": CdbException caught, error message was "
392 . $e->getMessage() );
395 return array_values( $data );
409 if ( $local !==
null ) {
411 $where[
'iw_local'] = 1;
412 } elseif ( $local == 0 ) {
413 $where[
'iw_local'] = 0;
417 $res = $db->select(
'interwiki',
418 self::selectFields(),
419 $where, __METHOD__, [
'ORDER BY' =>
'iw_prefix' ]
423 foreach (
$res as $row ) {
424 $retval[] = (array)$row;
437 if ( $this->cdbData ) {