jenkins-bot has submitted this change and it was merged.
Change subject: Updates for Interwiki.php
......................................................................
Updates for Interwiki.php
* Change default type for $iwData to be the same as possible updated values
* Remove superfluous else{}
* Break long lines
* Update documentation
* Update formatting
Change-Id: Ie1a655def0e9a4f71495ce5936964ef81a146297
---
M includes/interwiki/Interwiki.php
1 file changed, 52 insertions(+), 11 deletions(-)
Approvals:
Calak: Looks good to me, but someone else must approve
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/interwiki/Interwiki.php b/includes/interwiki/Interwiki.php
index 3c237bf..09283f2 100644
--- a/includes/interwiki/Interwiki.php
+++ b/includes/interwiki/Interwiki.php
@@ -31,7 +31,25 @@
protected static $smCache = array();
const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max
number of entries.
- protected $mPrefix, $mURL, $mAPI, $mWikiID, $mLocal, $mTrans;
+ /** @var string The interwiki prefix, (e.g. "Meatball", or the language
prefix "de") */
+ protected $mPrefix;
+
+ /** @var string The URL of the wiki, with "$1" as a placeholder for an
article name. */
+ protected $mURL;
+
+ /** @var string The URL of the file api.php */
+ protected $mAPI;
+
+ /** @var string The name of the database (for a connection to be
established
+ * with wfGetLB( 'wikiid' ))
+ */
+ protected $mWikiID;
+
+ /** @var bool whether the wiki is in this project */
+ protected $mLocal;
+
+ /** @var bool Whether interwiki transclusions are allowed */
+ protected $mTrans;
public function __construct( $prefix = null, $url = '', $api = '',
$wikiId = '', $local = 0,
$trans = 0
@@ -52,6 +70,7 @@
*/
public static function isValidInterwiki( $prefix ) {
$result = self::fetch( $prefix );
+
return (bool)$result;
}
@@ -63,13 +82,16 @@
*/
public static 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 );
@@ -79,11 +101,14 @@
$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;
}
@@ -107,6 +132,7 @@
} else {
$s = false;
}
+
return $s;
}
@@ -160,12 +186,12 @@
* Load the interwiki, trying first memcached then the DB
*
* @param string $prefix The interwiki prefix
- * @return bool If $prefix is valid
+ * @return Interwiki|bool Interwiki if $prefix is valid, otherwise false
*/
protected static function load( $prefix ) {
global $wgMemc, $wgInterwikiExpiry;
- $iwData = false;
+ $iwData = array();
if ( !wfRunHooks( 'InterwikiLoadPrefix', array( $prefix,
&$iwData ) ) ) {
return Interwiki::loadFromArray( $iwData );
}
@@ -174,11 +200,13 @@
$key = wfMemcKey( 'interwiki', $prefix );
$iwData = $wgMemc->get( $key );
if ( $iwData === '!NONEXISTENT' ) {
- return false; // negative cache hit
+ // negative cache hit
+ return false;
}
}
- if ( $iwData && is_array( $iwData ) ) { // is_array is hack for
old keys
+ // is_array is hack for old keys
+ if ( $iwData && is_array( $iwData ) ) {
$iw = Interwiki::loadFromArray( $iwData );
if ( $iw ) {
return $iw;
@@ -187,8 +215,13 @@
$db = wfGetDB( DB_SLAVE );
- $row = $db->fetchRow( $db->select( 'interwiki',
self::selectFields(), array( 'iw_prefix' => $prefix ),
- __METHOD__ ) );
+ $row = $db->fetchRow( $db->select(
+ 'interwiki',
+ self::selectFields(),
+ array( 'iw_prefix' => $prefix ),
+ __METHOD__
+ ) );
+
$iw = Interwiki::loadFromArray( $row );
if ( $iw ) {
$mc = array(
@@ -198,10 +231,12 @@
'iw_trans' => $iw->mTrans
);
$wgMemc->add( $key, $mc, $wgInterwikiExpiry );
+
return $iw;
- } else {
- $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry
); // negative cache hit
}
+
+ // negative cache hit
+ $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry );
return false;
}
@@ -223,6 +258,7 @@
return $iw;
}
+
return false;
}
@@ -318,10 +354,12 @@
self::selectFields(),
$where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' )
);
+
$retval = array();
foreach ( $res as $row ) {
$retval[] = (array)$row;
}
+
return $retval;
}
@@ -337,9 +375,9 @@
if ( $wgInterwikiCache ) {
return self::getAllPrefixesCached( $local );
- } else {
- return self::getAllPrefixesDB( $local );
}
+
+ return self::getAllPrefixesDB( $local );
}
/**
@@ -356,6 +394,7 @@
if ( $title !== null ) {
$url = str_replace( "$1", wfUrlencode( $title ), $url );
}
+
return $url;
}
@@ -404,6 +443,7 @@
*/
public function getName() {
$msg = wfMessage( 'interwiki-name-' . $this->mPrefix
)->inContentLanguage();
+
return !$msg->exists() ? '' : $msg;
}
@@ -414,6 +454,7 @@
*/
public function getDescription() {
$msg = wfMessage( 'interwiki-desc-' . $this->mPrefix
)->inContentLanguage();
+
return !$msg->exists() ? '' : $msg;
}
--
To view, visit https://gerrit.wikimedia.org/r/97508
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1a655def0e9a4f71495ce5936964ef81a146297
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Calak <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: IAlex <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits