- # ISO 639 2-letter language codes
- "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.com/wiki.cgi?$1",
- "hi" => "http://hi.wikipedia.com/wiki.cgi?$1",
- "hr" => "http://hr.wikipedia.org/wiki/$1",
- "hu" => "http://hu.wikipedia.com/wiki.cgi?$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",
- "zu" => "http://zu.wikipedia.com/wiki.cgi?$1"
-);
-?>
+ 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;
+
+ $iwData = false;
+ if ( !wfRunHooks( 'InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) {
+ return Interwiki::loadFromArray( $iwData );
+ }
+
+ if ( !$iwData ) {
+ $key = wfMemcKey( 'interwiki', $prefix );
+ $iwData = $wgMemc->get( $key );
+ }
+
+ if( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
+ $iw = Interwiki::loadFromArray( $iwData );
+ 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() {
+ $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
+ return !$msg->exists() ? '' : $msg;
+ }
+
+ /**
+ * Get a description for this interwiki
+ *
+ * @return String
+ */
+ public function getDescription() {
+ $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
+ return !$msg->exists() ? '' : $msg;
+ }
+}