* Add Linker::link flag for using article path
authorMatt Johnston <mattj@users.mediawiki.org>
Tue, 30 Sep 2008 01:56:54 +0000 (01:56 +0000)
committerMatt Johnston <mattj@users.mediawiki.org>
Tue, 30 Sep 2008 01:56:54 +0000 (01:56 +0000)
* Fix mistake in Interwiki-detecting code in Title
* Clean up Interwiki.php per Tim's recommendations

includes/Interwiki.php
includes/Linker.php
includes/Title.php

index 4c081ca..754fb3b 100644 (file)
@@ -40,7 +40,9 @@ class Interwiki {
                        return Interwiki::getInterwikiCached( $key );
                }
                $iw = new Interwiki;
-               $iw->load( $prefix );
+               if(! $iw->load( $prefix ) ){
+                       return false;
+               }
                if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
                        array_shift( self::$smCache );
                }
@@ -84,6 +86,8 @@ class Interwiki {
                        list( $local, $url ) = explode( ' ', $value, 2 );
                        $s->mURL = $url;
                        $s->mLocal = (int)$local;
+               }else{
+                       return false;
                }
                if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
                        array_shift( self::$smCache );
@@ -92,16 +96,6 @@ class Interwiki {
                return $s;
        }
 
-       /**
-        * Clear all member variables in the current object. Does not clear
-        * the block from the DB.
-        */
-       function clear() {
-               $this->mURL = '';
-               $this->mLocal = $this->mTrans = 0;
-               $this->mPrefix = null;
-       }
-
        /**
         * Get the DB object
         *
@@ -123,25 +117,19 @@ class Interwiki {
                global $wgMemc;
                $key = wfMemcKey( 'interwiki', $prefix );
                $mc = $wgMemc->get( $key );
-               if( $mc && is_array( $mc ) ){ // is_array is hack for old keys
-                       if( $this->loadFromArray( $mc ) ){
-                               wfDebug("Succeeded\n");
-                               return true;
-                       }
-               }else{
-                       $db =& $this->getDB();
-                       
-                       $res = $db->resultObject( $db->select( 'interwiki', '*', array( 'iw_prefix' => $prefix ),
-                               __METHOD__ ) );
-                       if ( $this->loadFromResult( $res ) ) {
-                               $mc = array( 'url' => $this->mURL, 'local' => $this->mLocal, 'trans' => $this->mTrans );
-                               $wgMemc->add( $key, $mc );
-                               return true;
-                       }
+               if( $mc && is_array( $mc ) && $this->loadFromArray( $mc ) ){ // is_array is hack for old keys
+                       wfDebug("Succeeded\n");
+                       return true;
                }
                
-               # Give up
-               $this->clear();
+               $db =& $this->getDB();
+               $res = $db->resultObject( $db->select( 'interwiki', '*', array( 'iw_prefix' => $prefix ),
+                       __METHOD__ ) );
+               if ( $this->loadFromResult( $res ) ) {
+                       $mc = array( 'url' => $this->mURL, 'local' => $this->mLocal, 'trans' => $this->mTrans );
+                       $wgMemc->add( $key, $mc );
+                       return true;
+               }
                return false;
        }
 
index dd899fe..8bcdf7d 100644 (file)
@@ -203,9 +203,18 @@ class Linker {
                        }
                }
                wfProfileOut( __METHOD__ . '-checkPageExistence' );
+               
+               $oldquery = array();
+               if( in_array( "forcearticlepath", $options ) && $query ){
+                       $oldquery = $query;
+                       $query = array();
+               }
 
                # Note: we want the href attribute first, for prettiness.
                $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
+               if( in_array( 'forcearticlepath', $options ) && $oldquery ){
+                       $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
+               }
                $attribs = array_merge(
                        $attribs,
                        $this->linkAttribs( $target, $customAttribs, $options )
index 10a6168..c8de709 100644 (file)
@@ -2054,7 +2054,7 @@ class Title {
                                        # Ordinary namespace
                                        $dbkey = $m[2];
                                        $this->mNamespace = $ns;
-                               } elseif( new Interwiki( $p ) ) {
+                               } elseif( Interwiki::fetch( $p ) ) {
                                        if( !$firstPass ) {
                                                # Can't make a local interwiki link to an interwiki link.
                                                # That's just crazy!