<?php
/**
+ * Interwiki table entry.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
- * Interwiki table entry
*/
/**
* Fetch an Interwiki object
*
* @param $prefix String: interwiki prefix to use
- * @return Interwiki Object, or null if not valid
+ * @return Interwiki|null|bool
*/
static public function fetch( $prefix ) {
global $wgContLang;
$value = '';
}
+
return $value;
}
/**
* Load the interwiki, trying first memcached then the DB
*
- * @param $prefix The interwiki prefix
+ * @param $prefix string The interwiki prefix
* @return Boolean: the prefix is valid
*/
protected static function load( $prefix ) {
if ( !$iwData ) {
$key = wfMemcKey( 'interwiki', $prefix );
$iwData = $wgMemc->get( $key );
+ if ( $iwData === '!NONEXISTENT' ) {
+ return false; // negative cache hit
+ }
}
if( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
$db = wfGetDB( DB_SLAVE );
- $row = $db->fetchRow( $db->select( 'interwiki', '*', array( 'iw_prefix' => $prefix ),
+ $row = $db->fetchRow( $db->select( 'interwiki', self::selectFields(), array( 'iw_prefix' => $prefix ),
__METHOD__ ) );
$iw = Interwiki::loadFromArray( $row );
if ( $iw ) {
);
$wgMemc->add( $key, $mc, $wgInterwikiExpiry );
return $iw;
+ } else {
+ $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry ); // negative cache hit
}
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
+ * @param $mc array Associative array: row from the interwiki table
+ * @return Boolean|Interwiki whether everything was there
*/
protected static function loadFromArray( $mc ) {
if( isset( $mc['iw_url'] ) ) {
/**
* Fetch all interwiki prefixes from interwiki cache
*
- * @param $local If not null, limits output to local/non-local interwikis
+ * @param $local null|string If not null, limits output to local/non-local interwikis
* @return Array List of prefixes
* @since 1.19
*/
/**
* Fetch all interwiki prefixes from DB
*
- * @param $local If not null, limits output to local/non-local interwikis
+ * @param $local string|null If not null, limits output to local/non-local interwikis
* @return Array List of prefixes
* @since 1.19
*/
}
$res = $db->select( 'interwiki',
- array( 'iw_prefix', 'iw_url', 'iw_api', 'iw_wikiid', 'iw_local', 'iw_trans' ),
+ self::selectFields(),
$where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' )
);
$retval = array();
/**
* Returns all interwiki prefixes
*
- * @param $local If set, limits output to local/non-local interwikis
+ * @param $local string|null If set, limits output to local/non-local interwikis
* @return Array List of prefixes
* @since 1.19
*/
*
* @param $title String: what text to put for the article name
* @return String: the URL
+ * @note Prior to 1.19 The getURL with an argument was broken.
+ * If you if you use this arg in an extension that supports MW earlier
+ * than 1.19 please wfUrlencode and substitute $1 on your own.
*/
public function getURL( $title = null ) {
$url = $this->mURL;
- if( $title != null ) {
- $url = str_replace( "$1", $title, $url );
+ if( $title !== null ) {
+ $url = str_replace( "$1", wfUrlencode( $title ), $url );
}
return $url;
}
$msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
return !$msg->exists() ? '' : $msg;
}
+
+ /**
+ * Return the list of interwiki fields that should be selected to create
+ * a new interwiki object.
+ * @return array
+ */
+ public static function selectFields() {
+ return array(
+ 'iw_prefix',
+ 'iw_url',
+ 'iw_api',
+ 'iw_wikiid',
+ 'iw_local',
+ 'iw_trans'
+ );
+ }
}