r42041 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42040‎ | r42041 | r42042 >
Date:18:43, 13 October 2008
Author:brion
Status:old
Tags:
Comment:
Cleanup for r42022/r42023 interwiki stuff
* Remove duplicate code in Interwiki::isValidInterwiki(), which should help avoid future drift between the two copies
* Early return on prefix = '', we know it won't be valid :)
* Dump extra isValidInterwikiCached function -- just go through the regular fetch() path, it doesn't do much more processing.
* Simplify Title codepath in full URL generation to ensure we never call an invalid object
Modified paths:
  • /trunk/phase3/includes/Interwiki.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Interwiki.php
@@ -32,25 +32,8 @@
3333 * @param $prefix string Interwiki prefix to use
3434 */
3535 static public function isValidInterwiki( $prefix ){
36 - global $wgContLang;
37 - $prefix = $wgContLang->lc( $prefix );
38 - if( isset( self::$smCache[$prefix] ) ){
39 - return true;
40 - }
41 - global $wgInterwikiCache;
42 - if ($wgInterwikiCache) {
43 - return Interwiki::isValidInterwikiCached( $key );
44 - }
45 - $iw = Interwiki::load( $prefix );
46 - if( !$iw ){
47 - $iw = false;
48 - }
49 - if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
50 - reset( self::$smCache );
51 - unset( self::$smCache[ key( self::$smCache ) ] );
52 - }
53 - self::$smCache[$prefix] = $iw;
54 - return ($iw != false);
 36+ $result = self::fetch( $prefix );
 37+ return (bool)$result;
5538 }
5639
5740 /**
@@ -61,6 +44,9 @@
6245 */
6346 static public function fetch( $prefix ) {
6447 global $wgContLang;
 48+ if( $prefix == '' ) {
 49+ return null;
 50+ }
6551 $prefix = $wgContLang->lc( $prefix );
6652 if( isset( self::$smCache[$prefix] ) ){
6753 return self::$smCache[$prefix];
@@ -110,19 +96,6 @@
11197 }
11298
11399 /**
114 - * Check whether an interwiki is in the cache
115 - *
116 - * @note More logic is explained in DefaultSettings.
117 - *
118 - * @param $key \type{\string} Database key
119 - * @return \type{\bool} Whether it exists
120 - */
121 - protected static function isValidInterwikiCached( $key ) {
122 - $value = getInterwikiCacheEntry( $key );
123 - return $value != '';
124 - }
125 -
126 - /**
127100 * Get entry from interwiki cache
128101 *
129102 * @note More logic is explained in DefaultSettings.
Index: trunk/phase3/includes/Title.php
@@ -675,7 +675,8 @@
676676 $query = wfArrayToCGI( $query );
677677 }
678678
679 - if ( '' == $this->mInterwiki || !Interwiki::isValidInterwiki( $this->mInterwiki ) ) {
 679+ $interwiki = Interwiki::fetch( $this->mInterwiki );
 680+ if ( !$interwiki ) {
680681 $url = $this->getLocalUrl( $query, $variant );
681682
682683 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
@@ -684,7 +685,7 @@
685686 $url = $wgServer . $url;
686687 }
687688 } else {
688 - $baseUrl = Interwiki::fetch( $this->mInterwiki )->getURL( );
 689+ $baseUrl = $interwiki->getURL( );
689690
690691 $namespace = wfUrlencode( $this->getNsText() );
691692 if ( '' != $namespace ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r42022Clean up Interwiki.php to meet Tim's suggestions. Hopefully should make clean...mattj08:35, 13 October 2008
r42023Fix r42022, always returning true for isValidInterwiki as I forgot to add the...mattj09:31, 13 October 2008

Status & tagging log