-<?
-# Note -- this file is generated by maintenance/fetchInterwiki.pl
-# Edit and rerun that script rather than modifying this directly.
+<?php
+/**
+ * @file
+ * Interwiki table entry
+ */
-/* private */ $wgValidInterwikis = array(
- # General interwiki links from the InterMap
- "AbbeNormal" => "http://www.ourpla.net/cgi-bin/pikie.cgi?$1",
- "AcadWiki" => "http://xarch.tu-graz.ac.at/autocad/wiki/$1",
- "Acronym" => "http://www.acronymfinder.com/af-query.asp?String=exact&Acronym=$1",
- "Advogato" => "http://www.advogato.org/$1",
- "AIWiki" => "http://www.ifi.unizh.ch/ailab/aiwiki/aiw.cgi?$1",
- "ALife" => "http://news.alife.org/wiki/index.php?$1",
- "AndStuff" => "http://andstuff.org/wiki.php?$1",
- "Annotation" => "http://bayle.stanford.edu/crit/nph-med.cgi/$1",
- "AnnotationWiki" => "http://www.seedwiki.com/page.cfm?wikiid=368&doc=$1",
- "AwarenessWiki" => "http://taoriver.net/aware/$1",
- "BenefitsWiki" => "http://www.benefitslink.com/cgi-bin/wiki.cgi?$1",
- "BridgesWiki" => "http://c2.com/w2/bridges/$1",
- "C2find" => "http://c2.com/cgi/wiki?FindPage&value=$1",
- "Cache" => "http://www.google.com/search?q=cache:$1",
- "CLiki" => "http://ww.telent.net/cliki/$1",
- "CmWiki" => "http://www.ourpla.net/cgi-bin/wiki.pl?$1",
- "CreationMatters" => "http://www.ourpla.net/cgi-bin/wiki.pl?$1",
- "DejaNews" => "http://www.deja.com/=dnc/getdoc.xp?AN=$1",
- "Dictionary" => "http://www.dict.org/bin/Dict?Database=*&Form=Dict1&Strategy=*&Query=$1",
- "DiveIntoOsx" => "http://diveintoosx.org/$1",
- "DocBook" => "http://docbook.org/wiki/moin.cgi/$1",
- "DolphinWiki" => "http://www.object-arts.com/wiki/html/Dolphin/$1",
- "EfnetCeeWiki" => "http://purl.net/wiki/c/$1",
- "EfnetCppWiki" => "http://purl.net/wiki/cpp/$1",
- "EfnetPythonWiki" => "http://purl.net/wiki/python/$1",
- "EfnetXmlWiki" => "http://purl.net/wiki/xml/$1",
- "EljWiki" => "http://elj.sourceforge.net/phpwiki/index.php/$1",
- "EmacsWiki" => "http://www.emacswiki.org/cgi-bin/wiki.pl?$1",
- "FinalEmpire" => "http://final-empire.sourceforge.net/cgi-bin/wiki.pl?$1",
- "Foldoc" => "http://www.foldoc.org/foldoc/foldoc.cgi?$1",
- "FoxWiki" => "http://fox.wikis.com/wc.dll?Wiki~$1",
- "FreeBSDman" => "http://www.FreeBSD.org/cgi/man.cgi?apropos=1&query=$1",
- "Google" => "http://www.google.com/search?q=$1",
- "GoogleGroups" => "http://groups.google.com/groups?q=$1",
- "GreenCheese" => "http://www.greencheese.org/$1",
- "HammondWiki" => "http://www.dairiki.org/HammondWiki/index.php3?$1",
- "Haribeau" => "http://wiki.haribeau.de/cgi-bin/wiki.pl?$1",
- "IAWiki" => "http://www.IAwiki.net/$1",
- "IMDB" => "http://us.imdb.com/Title?$1",
- "JargonFile" => "http://sunir.org/apps/meta.pl?wiki=JargonFile&redirect=$1",
- "JiniWiki" => "http://www.cdegroot.com/cgi-bin/jini?$1",
- "JspWiki" => "http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=$1",
- "KmWiki" => "http://www.voght.com/cgi-bin/pywiki?$1",
- "KnowHow" => "http://www2.iro.umontreal.ca/~paquetse/cgi-bin/wiki.cgi?$1",
- "LanifexWiki" => "http://opt.lanifex.com/cgi-bin/wiki.pl?$1",
- "LegoWiki" => "http://www.object-arts.com/wiki/html/Lego-Robotics/$1",
- "LinuxWiki" => "http://www.linuxwiki.de/$1",
- "LugKR" => "http://lug-kr.sourceforge.net/cgi-bin/lugwiki.pl?$1",
- "MathSongsWiki" => "http://SeedWiki.com/page.cfm?wikiid=237&doc=$1",
- "MbTest" => "http://www.usemod.com/cgi-bin/mbtest.pl?$1",
- "MeatBall" => "http://www.usemod.com/cgi-bin/mb.pl?$1",
- "MetaWiki" => "http://sunir.org/apps/meta.pl?$1",
- "MetaWikiPedia" => "http://meta.wikipedia.org/wiki/$1",
- "MoinMoin" => "http://purl.net/wiki/moin/$1",
- "MuWeb" => "http://www.dunstable.com/scripts/MuWebWeb?$1",
- "NetVillage" => "http://www.netbros.com/?$1",
- "OpenWiki" => "http://openwiki.com/?$1",
- "OrgPatterns" => "http://www.bell-labs.com/cgi-user/OrgPatterns/OrgPatterns?$1",
- "PangalacticOrg" => "http://www.pangalactic.org/Wiki/$1",
- "PersonalTelco" => "http://www.personaltelco.net/index.cgi/$1",
- "PhpWiki" => "http://phpwiki.sourceforge.net/phpwiki/index.php?$1",
- "Pikie" => "http://pikie.darktech.org/cgi/pikie?$1",
- "PPR" => "http://c2.com/cgi/wiki?$1",
- "PurlNet" => "http://purl.oclc.org/NET/$1",
- "PythonInfo" => "http://www.python.org/cgi-bin/moinmoin/$1",
- "PythonWiki" => "http://www.pythonwiki.de/$1",
- "PyWiki" => "http://www.voght.com/cgi-bin/pywiki?$1",
- "SeaPig" => "http://www.seapig.org/ $1",
- "SeattleWireless" => "http://seattlewireless.net/?$1",
- "SenseisLibrary" => "http://senseis.xmp.net/?$1",
- "Shakti" => "http://cgi.algonet.se/htbin/cgiwrap/pgd/ShaktiWiki/$1",
- "SourceForge" => "http://sourceforge.net/$1",
- "Squeak" => "http://minnow.cc.gatech.edu/squeak/$1",
- "StrikiWiki" => "http://ch.twi.tudelft.nl/~mostert/striki/teststriki.pl?$1",
- "SVGWiki" => "http://www.protocol7.com/svg-wiki/default.asp?$1",
- "Tavi" => "http://tavi.sourceforge.net/index.php?$1",
- "TmNet" => "http://www.technomanifestos.net/?$1",
- "TMwiki" => "http://www.EasyTopicMaps.com/?page=$1",
- "TWiki" => "http://twiki.org/cgi-bin/view/$1",
- "TwistedWiki" => "http://purl.net/wiki/twisted/$1",
- "Unreal" => "http://wiki.beyondunreal.com/wiki/$1",
- "UseMod" => "http://www.usemod.com/cgi-bin/wiki.pl?$1",
- "VisualWorks" => "http://wiki.cs.uiuc.edu/VisualWorks/$1",
- "WebDevWikiNL" => "http://www.promo-it.nl/WebDevWiki/index.php?page=$1",
- "WebSeitzWiki" => "http://webseitz.fluxent.com/wiki/$1",
- "Why" => "http://clublet.com/c/c/why?$1",
- "Wiki" => "http://c2.com/cgi/wiki?$1",
- "WikiPedia" => "http://www.wikipedia.org/wiki/$1",
- "Wiktionary" => "http://wiktionary.org/wiki/$1",
- "WikiWorld" => "http://WikiWorld.com/wiki/index.php/$1",
- "YpsiEyeball" => "http://sknkwrks.dyndns.org:1957/writewiki/wiki.pl?$1",
- "ZWiki" => "http://www.zwiki.org/$1",
+/**
+ * The interwiki class
+ * All information is loaded on creation when called by Interwiki::fetch( $prefix ).
+ * All work is done on slave, because this should *never* change (except during
+ * schema updates etc, which aren't wiki-related)
+ */
+class Interwiki {
- # Some custom additions:
- "ReVo" => "http://purl.org/NET/voko/revo/art/$1.html",
- # eg [[ReVo:cerami]], [[ReVo:astero]] - note X-sensitive!
- "EcheI" => "http://www.ikso.net/cgi-bin/wiki.pl?$1",
- "E\xc4\x89eI" => "http://www.ikso.net/cgi-bin/wiki.pl?$1",
- "UnuMondo" => "http://unumondo.com/cgi-bin/wiki.pl?$1", # X-sensitive!
- "JEFO" => "http://esperanto.jeunes.free.fr/vikio/index.php?$1",
- "PMEG" => "http://www.bertilow.com/pmeg/$1.php",
- # ekz [[PMEG:gramatiko/kunligaj vortetoj/au]]
- "EnciclopediaLibre" => "http://enciclopedia.us.es/wiki.phtml?title=$1",
+ // Cache - removes oldest entry when it hits limit
+ protected static $smCache = array();
+ const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max number of entries.
- # Wikipedia-specific stuff:
- # Special cases
- "w" => "http://www.wikipedia.org/wiki/$1", # DEPRECATED
- "m" => "http://meta.wikipedia.org/wiki/$1",
- "meta" => "http://meta.wikipedia.org/wiki/$1",
- "sep11" => "http://sep11.wikipedia.org/wiki/$1",
- "simple"=> "http://simple.wikipedia.com/wiki.cgi?$1",
- "wiktionary" => "http://wiktionary.org/wiki/$1",
-
- # These may not be recommended, may change...
- "PageHistory" => "http://www.wikipedia.org/w/wiki.phtml?title=$1&action=history",
- "UserContributions" => "http://www.wikipedia.org/w/wiki.phtml?title=Special:Contributions&target=$1",
- "BackLinks" => "http://www.wikipedia.org/w/wiki.phtml?title=Special:Whatlinkshere&target=$1"
- );
+ protected $mPrefix, $mURL, $mAPI, $mWikiID, $mLocal, $mTrans;
- # ISO 639 2-letter language codes
-$WikiPediaLanguages = array(
- "aa" => "http://aa.wikipedia.com/wiki.cgi?$1",
- "ab" => "http://ab.wikipedia.com/wiki.cgi?$1",
- "af" => "http://af.wikipedia.com/wiki.cgi?$1",
- "am" => "http://am.wikipedia.com/wiki.cgi?$1",
- "ar" => "http://ar.wikipedia.com/wiki.cgi?$1",
- "as" => "http://as.wikipedia.com/wiki.cgi?$1",
- "ay" => "http://ay.wikipedia.com/wiki.cgi?$1",
- "az" => "http://az.wikipedia.com/wiki.cgi?$1",
- "ba" => "http://ba.wikipedia.com/wiki.cgi?$1",
- "be" => "http://be.wikipedia.com/wiki.cgi?$1",
- "bh" => "http://bh.wikipedia.com/wiki.cgi?$1",
- "bi" => "http://bi.wikipedia.com/wiki.cgi?$1",
- "bn" => "http://bn.wikipedia.com/wiki.cgi?$1",
- "bs" => "http://bs.wikipedia.org/wiki/$1",
- "bo" => "http://bo.wikipedia.com/wiki.cgi?$1",
- "ca" => "http://ca.wikipedia.com/wiki.cgi?$1",
- "co" => "http://co.wikipedia.com/wiki.cgi?$1",
- "cs" => "http://cs.wikipedia.org/wiki/$1",
- "cy" => "http://cy.wikipedia.com/wiki.cgi?$1",
- "da" => "http://da.wikipedia.org/wiki/$1",
- "de" => "http://de.wikipedia.org/wiki/$1",
- "dk" => "http://da.wikipedia.org/wiki/$1",
- "dz" => "http://dz.wikipedia.com/wiki.cgi?$1",
- "el" => "http://el.wikipedia.org/wiki/$1",
- "en" => "http://www.wikipedia.org/wiki/$1", # May in future be renamed to en.wikipedia.org; should work as alternate
- "eo" => "http://eo.wikipedia.org/wiki/$1",
- "es" => "http://es.wikipedia.org/wiki/$1",
- "et" => "http://et.wikipedia.com/wiki.cgi?$1",
- "eu" => "http://eu.wikipedia.com/wiki.cgi?$1",
- "fa" => "http://fa.wikipedia.com/wiki.cgi?$1",
- "fi" => "http://fi.wikipedia.com/wiki.cgi?$1",
- "fj" => "http://fj.wikipedia.com/wiki.cgi?$1",
- "fo" => "http://fo.wikipedia.com/wiki.cgi?$1",
- "fr" => "http://fr.wikipedia.org/wiki/$1",
- "fy" => "http://fy.wikipedia.com/wiki.cgi?$1",
- "ga" => "http://ga.wikipedia.com/wiki.cgi?$1",
- "gl" => "http://gl.wikipedia.com/wiki.cgi?$1",
- "gn" => "http://gn.wikipedia.com/wiki.cgi?$1",
- "gu" => "http://gu.wikipedia.com/wiki.cgi?$1",
- "ha" => "http://ha.wikipedia.com/wiki.cgi?$1",
- "he" => "http://he.wikipedia.org/wiki/$1",
- "hi" => "http://hi.wikipedia.com/wiki.cgi?$1",
- "hr" => "http://hr.wikipedia.org/wiki/$1",
- "hu" => "http://hu.wikipedia.org/wiki/$1",
- "hy" => "http://hy.wikipedia.com/wiki.cgi?$1",
- "ia" => "http://ia.wikipedia.com/wiki.cgi?$1",
- "id" => "http://id.wikipedia.com/wiki.cgi?$1",
- "ik" => "http://ik.wikipedia.com/wiki.cgi?$1",
- "is" => "http://is.wikipedia.com/wiki.cgi?$1",
- "it" => "http://it.wikipedia.com/wiki.cgi?$1",
- "iu" => "http://iu.wikipedia.com/wiki.cgi?$1",
- "ja" => "http://ja.wikipedia.org/wiki/$1",
- "jv" => "http://jv.wikipedia.com/wiki.cgi?$1",
- "ka" => "http://ka.wikipedia.com/wiki.cgi?$1",
- "kk" => "http://kk.wikipedia.com/wiki.cgi?$1",
- "kl" => "http://kl.wikipedia.com/wiki.cgi?$1",
- "km" => "http://km.wikipedia.com/wiki.cgi?$1",
- "kn" => "http://kn.wikipedia.com/wiki.cgi?$1",
- "ko" => "http://ko.wikipedia.org/wiki/$1",
- "ks" => "http://ks.wikipedia.com/wiki.cgi?$1",
- "ku" => "http://ku.wikipedia.com/wiki.cgi?$1",
- "ky" => "http://ky.wikipedia.com/wiki.cgi?$1",
- "la" => "http://la.wikipedia.com/wiki.cgi?$1",
- "lo" => "http://lo.wikipedia.com/wiki.cgi?$1",
- "lv" => "http://lv.wikipedia.com/wiki.cgi?$1",
- "mg" => "http://mg.wikipedia.com/wiki.cgi?$1",
- "mi" => "http://mi.wikipedia.com/wiki.cgi?$1",
- "mk" => "http://mk.wikipedia.com/wiki.cgi?$1",
- "ml" => "http://ml.wikipedia.org/wiki/$1",
- "mn" => "http://mn.wikipedia.com/wiki.cgi?$1",
- "mo" => "http://mo.wikipedia.com/wiki.cgi?$1",
- "mr" => "http://mr.wikipedia.com/wiki.cgi?$1",
- "ms" => "http://ms.wikipedia.org/wiki/$1",
- "my" => "http://my.wikipedia.com/wiki.cgi?$1",
- "na" => "http://na.wikipedia.com/wiki.cgi?$1",
- "ne" => "http://ne.wikipedia.com/wiki.cgi?$1",
- "nl" => "http://nl.wikipedia.org/wiki/$1",
- "no" => "http://no.wikipedia.com/wiki.cgi?$1",
- "oc" => "http://oc.wikipedia.com/wiki.cgi?$1",
- "om" => "http://om.wikipedia.com/wiki.cgi?$1",
- "or" => "http://or.wikipedia.com/wiki.cgi?$1",
- "pa" => "http://pa.wikipedia.com/wiki.cgi?$1",
- "pl" => "http://pl.wikipedia.org/wiki/$1",
- "ps" => "http://ps.wikipedia.com/wiki.cgi?$1",
- "pt" => "http://pt.wikipedia.com/wiki.cgi?$1",
- "qu" => "http://qu.wikipedia.com/wiki.cgi?$1",
- "rm" => "http://rm.wikipedia.com/wiki.cgi?$1",
- "rn" => "http://rn.wikipedia.com/wiki.cgi?$1",
- "ro" => "http://ro.wikipedia.com/wiki.cgi?$1",
- "ru" => "http://ru.wikipedia.org/wiki/$1",
- "rw" => "http://rw.wikipedia.com/wiki.cgi?$1",
- "sa" => "http://sa.wikipedia.com/wiki.cgi?$1",
- "sd" => "http://sd.wikipedia.com/wiki.cgi?$1",
- "sg" => "http://sg.wikipedia.com/wiki.cgi?$1",
- "sh" => "http://sh.wikipedia.org/wiki/$1",
- "si" => "http://si.wikipedia.com/wiki.cgi?$1",
- "sk" => "http://sk.wikipedia.com/wiki.cgi?$1",
- "sl" => "http://sl.wikipedia.com/wiki.cgi?$1",
- "sm" => "http://sm.wikipedia.com/wiki.cgi?$1",
- "sn" => "http://sn.wikipedia.com/wiki.cgi?$1",
- "so" => "http://so.wikipedia.com/wiki.cgi?$1",
- "sq" => "http://sq.wikipedia.com/wiki.cgi?$1",
- "sr" => "http://sr.wikipedia.org/wiki/$1",
- "ss" => "http://ss.wikipedia.com/wiki.cgi?$1",
- "st" => "http://st.wikipedia.com/wiki.cgi?$1",
- "su" => "http://su.wikipedia.com/wiki.cgi?$1",
- "sv" => "http://sv.wikipedia.org/wiki/$1",
- "sw" => "http://sw.wikipedia.com/wiki.cgi?$1",
- "ta" => "http://ta.wikipedia.com/wiki.cgi?$1",
- "te" => "http://te.wikipedia.com/wiki.cgi?$1",
- "tg" => "http://tg.wikipedia.com/wiki.cgi?$1",
- "th" => "http://th.wikipedia.com/wiki.cgi?$1",
- "ti" => "http://ti.wikipedia.com/wiki.cgi?$1",
- "tk" => "http://tk.wikipedia.com/wiki.cgi?$1",
- "tl" => "http://tl.wikipedia.com/wiki.cgi?$1",
- "tn" => "http://tn.wikipedia.com/wiki.cgi?$1",
- "to" => "http://to.wikipedia.com/wiki.cgi?$1",
- "tr" => "http://tr.wikipedia.org/wiki/$1",
- "ts" => "http://ts.wikipedia.com/wiki.cgi?$1",
- "tt" => "http://tt.wikipedia.com/wiki.cgi?$1",
- "tw" => "http://tw.wikipedia.com/wiki.cgi?$1",
- "ug" => "http://ug.wikipedia.com/wiki.cgi?$1",
- "uk" => "http://uk.wikipedia.com/wiki.cgi?$1",
- "ur" => "http://ur.wikipedia.com/wiki.cgi?$1",
- "uz" => "http://uz.wikipedia.com/wiki.cgi?$1",
- "vi" => "http://vi.wikipedia.com/wiki.cgi?$1",
- "vo" => "http://vo.wikipedia.com/wiki.cgi?$1",
- "wo" => "http://wo.wikipedia.com/wiki.cgi?$1",
- "xh" => "http://xh.wikipedia.com/wiki.cgi?$1",
- "yi" => "http://yi.wikipedia.com/wiki.cgi?$1",
- "yo" => "http://yo.wikipedia.com/wiki.cgi?$1",
- "za" => "http://za.wikipedia.com/wiki.cgi?$1",
- "zh" => "http://zh.wikipedia.org/wiki/$1",
- "zh-cn" => "http://zh.wikipedia.org/wiki/$1",
- "zh-tw" => "http://zh.wikipedia.org/wiki/$1",
- "zu" => "http://zu.wikipedia.com/wiki.cgi?$1",
- "nds" => "http://nds.wikipedia.org/wiki.cgi?$1"
-);
-foreach($WikiPediaLanguages as $code => $url) {
- $wgValidInterwikis[ucfirst($code) . "WikiPedia"] = $url;
- $wgValidInterwikis[ucfirst($code) . "Wikipedia"] = $url;
- # If you're not Wikipedia, comment out next line!
- $wgValidInterwikis[$code] = $url;
-}
+ public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0, $trans = 0 ) {
+ $this->mPrefix = $prefix;
+ $this->mURL = $url;
+ $this->mAPI = $api;
+ $this->mWikiID = $wikiId;
+ $this->mLocal = $local;
+ $this->mTrans = $trans;
+ }
+
+ /**
+ * Check whether an interwiki prefix exists
+ *
+ * @param $prefix String: interwiki prefix to use
+ * @return Boolean: whether it exists
+ */
+ static public function isValidInterwiki( $prefix ) {
+ $result = self::fetch( $prefix );
+ return (bool)$result;
+ }
+
+ /**
+ * Fetch an Interwiki object
+ *
+ * @param $prefix String: interwiki prefix to use
+ * @return Interwiki Object, or null if not valid
+ */
+ static public function fetch( $prefix ) {
+ global $wgContLang;
+ if( $prefix == '' ) {
+ return null;
+ }
+ $prefix = $wgContLang->lc( $prefix );
+ if( isset( self::$smCache[$prefix] ) ) {
+ return self::$smCache[$prefix];
+ }
+ global $wgInterwikiCache;
+ if( $wgInterwikiCache ) {
+ $iw = Interwiki::getInterwikiCached( $prefix );
+ } else {
+ $iw = Interwiki::load( $prefix );
+ if( !$iw ) {
+ $iw = false;
+ }
+ }
+ if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ) {
+ reset( self::$smCache );
+ unset( self::$smCache[key( self::$smCache )] );
+ }
+ self::$smCache[$prefix] = $iw;
+ return $iw;
+ }
+
+ /**
+ * Fetch interwiki prefix data from local cache in constant database.
+ *
+ * @note More logic is explained in DefaultSettings.
+ *
+ * @param $prefix String: interwiki prefix
+ * @return Interwiki object
+ */
+ protected static function getInterwikiCached( $prefix ) {
+ $value = self::getInterwikiCacheEntry( $prefix );
+
+ $s = new Interwiki( $prefix );
+ if ( $value != '' ) {
+ // Split values
+ list( $local, $url ) = explode( ' ', $value, 2 );
+ $s->mURL = $url;
+ $s->mLocal = (int)$local;
+ } else {
+ $s = false;
+ }
+ return $s;
+ }
+
+ /**
+ * Get entry from interwiki cache
+ *
+ * @note More logic is explained in DefaultSettings.
+ *
+ * @param $prefix String: database key
+ * @return String: the entry
+ */
+ protected static function getInterwikiCacheEntry( $prefix ) {
+ global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
+ static $db, $site;
+
+ wfDebug( __METHOD__ . "( $prefix )\n" );
+ if( !$db ) {
+ $db = CdbReader::open( $wgInterwikiCache );
+ }
+ /* Resolve site name */
+ if( $wgInterwikiScopes >= 3 && !$site ) {
+ $site = $db->get( '__sites:' . wfWikiID() );
+ if ( $site == '' ) {
+ $site = $wgInterwikiFallbackSite;
+ }
+ }
+
+ $value = $db->get( wfMemcKey( $prefix ) );
+ // Site level
+ if ( $value == '' && $wgInterwikiScopes >= 3 ) {
+ $value = $db->get( "_{$site}:{$prefix}" );
+ }
+ // Global Level
+ if ( $value == '' && $wgInterwikiScopes >= 2 ) {
+ $value = $db->get( "__global:{$prefix}" );
+ }
+ if ( $value == 'undef' ) {
+ $value = '';
+ }
+
+ return $value;
+ }
+
+ /**
+ * Load the interwiki, trying first memcached then the DB
+ *
+ * @param $prefix The interwiki prefix
+ * @return Boolean: the prefix is valid
+ */
+ protected static function load( $prefix ) {
+ global $wgMemc, $wgInterwikiExpiry;
+ $key = wfMemcKey( 'interwiki', $prefix );
+ $mc = $wgMemc->get( $key );
+ $iw = false;
+ if( $mc && is_array( $mc ) ) { // is_array is hack for old keys
+ $iw = Interwiki::loadFromArray( $mc );
+ if( $iw ) {
+ return $iw;
+ }
+ }
+
+ $db = wfGetDB( DB_SLAVE );
-?>
+ $row = $db->fetchRow( $db->select( 'interwiki', '*', array( 'iw_prefix' => $prefix ),
+ __METHOD__ ) );
+ $iw = Interwiki::loadFromArray( $row );
+ if ( $iw ) {
+ $mc = array(
+ 'iw_url' => $iw->mURL,
+ 'iw_api' => $iw->mAPI,
+ 'iw_local' => $iw->mLocal,
+ 'iw_trans' => $iw->mTrans
+ );
+ $wgMemc->add( $key, $mc, $wgInterwikiExpiry );
+ return $iw;
+ }
+
+ return false;
+ }
+
+ /**
+ * Fill in member variables from an array (e.g. memcached result, Database::fetchRow, etc)
+ *
+ * @param $mc Associative array: row from the interwiki table
+ * @return Boolean: whether everything was there
+ */
+ protected static function loadFromArray( $mc ) {
+ if( isset( $mc['iw_url'] ) && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) {
+ $iw = new Interwiki();
+ $iw->mURL = $mc['iw_url'];
+ $iw->mLocal = $mc['iw_local'];
+ $iw->mTrans = $mc['iw_trans'];
+ $iw->mAPI = isset( $mc['iw_api'] ) ? $mc['iw_api'] : '';
+ $iw->mWikiID = isset( $mc['iw_wikiid'] ) ? $mc['iw_wikiid'] : '';
+
+ return $iw;
+ }
+ return false;
+ }
+
+ /**
+ * Get the URL for a particular title (or with $1 if no title given)
+ *
+ * @param $title String: what text to put for the article name
+ * @return String: the URL
+ */
+ public function getURL( $title = null ) {
+ $url = $this->mURL;
+ if( $title != null ) {
+ $url = str_replace( "$1", $title, $url );
+ }
+ return $url;
+ }
+
+ /**
+ * Get the API URL for this wiki
+ *
+ * @return String: the URL
+ */
+ public function getAPI() {
+ return $this->mAPI;
+ }
+
+ /**
+ * Get the DB name for this wiki
+ *
+ * @return String: the DB name
+ */
+ public function getWikiID() {
+ return $this->mWikiID;
+ }
+
+ /**
+ * Is this a local link from a sister project, or is
+ * it something outside, like Google
+ *
+ * @return Boolean
+ */
+ public function isLocal() {
+ return $this->mLocal;
+ }
+
+ /**
+ * Can pages from this wiki be transcluded?
+ * Still requires $wgEnableScaryTransclusion
+ *
+ * @return Boolean
+ */
+ public function isTranscludable() {
+ return $this->mTrans;
+ }
+
+ /**
+ * Get the name for the interwiki site
+ *
+ * @return String
+ */
+ public function getName() {
+ $key = 'interwiki-name-' . $this->mPrefix;
+ $msg = wfMsgForContent( $key );
+ return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+ }
+
+ /**
+ * Get a description for this interwiki
+ *
+ * @return String
+ */
+ public function getDescription() {
+ $key = 'interwiki-desc-' . $this->mPrefix;
+ $msg = wfMsgForContent( $key );
+ return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+ }
+}