Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -983,25 +983,40 @@ |
984 | 984 | } |
985 | 985 | |
986 | 986 | /** |
987 | | - * This function takes two arrays as input, and returns a CGI-style string, e.g. |
| 987 | + * This function takes one or two arrays, objects, or strings as input, and returns a CGI-style string, e.g. |
988 | 988 | * "days=7&limit=100". Options in the first array override options in the second. |
989 | 989 | * Options set to "" will not be output. |
| 990 | + * @depreciated |
990 | 991 | */ |
991 | | -function wfArrayToCGI( $array1, $array2 = NULL ) |
992 | | -{ |
993 | | - if ( !is_null( $array2 ) ) { |
994 | | - $array1 = $array1 + $array2; |
995 | | - } |
996 | | - |
997 | | - $cgi = ''; |
998 | | - foreach ( $array1 as $key => $value ) { |
999 | | - if ( '' !== $value ) { |
1000 | | - if ( '' != $cgi ) { |
1001 | | - $cgi .= '&'; |
| 992 | +function wfArrayToCGI( $query1, $query2 = null ) { |
| 993 | + if( is_null($query2) ) wfBuildQuery( $query1 ); |
| 994 | + else wfBuildQuery( $query2, $query1 ); |
| 995 | +} |
| 996 | +/** |
| 997 | + * wfBuildQuery is a improved wrapper for http_build_query. |
| 998 | + * We support a defaults array which the query may be merged with. As well we also support |
| 999 | + * arrays, objects, and strings as input. |
| 1000 | + */ |
| 1001 | +function wfBuildQuery( $query, $defaults = null ) { |
| 1002 | + if( !is_null($defaults) ) { |
| 1003 | + ## If either array is a string, then parse it and make sure to fix magic quotes. |
| 1004 | + foreach( array( 'query', 'defaults' ) as $var ) { |
| 1005 | + if( is_string($$var) ) { |
| 1006 | + $arr = array(); |
| 1007 | + parse_str($$var, &$arr); |
| 1008 | + if( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) { |
| 1009 | + global $wgRequest; |
| 1010 | + $wgRequest->fix_magic_quotes( $arr ); |
| 1011 | + } |
| 1012 | + $$var = $arr; |
1002 | 1013 | } |
1003 | | - $cgi .= urlencode( $key ) . '=' . urlencode( $value ); |
1004 | 1014 | } |
| 1015 | + # Merge, make sure they are arrays, not objects. |
| 1016 | + $query = ((array)$defaults) + ((array)$query); |
1005 | 1017 | } |
| 1018 | + |
| 1019 | + # Note that we must specify & because the default is sometimes & |
| 1020 | + $cgi = is_string($query) ? $query : http_build_query( $query, null, '&' ); |
1006 | 1021 | return $cgi; |
1007 | 1022 | } |
1008 | 1023 | |
— | — | @@ -2337,13 +2352,8 @@ |
2338 | 2353 | * Get a cache key |
2339 | 2354 | */ |
2340 | 2355 | function wfMemcKey( /*... */ ) { |
2341 | | - global $wgDBprefix, $wgDBname; |
2342 | 2356 | $args = func_get_args(); |
2343 | | - if ( $wgDBprefix ) { |
2344 | | - $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args ); |
2345 | | - } else { |
2346 | | - $key = $wgDBname . ':' . implode( ':', $args ); |
2347 | | - } |
| 2357 | + $key = wfWikiID() . ':' . implode( ':', $args ); |
2348 | 2358 | return $key; |
2349 | 2359 | } |
2350 | 2360 | |
— | — | @@ -2352,11 +2362,7 @@ |
2353 | 2363 | */ |
2354 | 2364 | function wfForeignMemcKey( $db, $prefix /*, ... */ ) { |
2355 | 2365 | $args = array_slice( func_get_args(), 2 ); |
2356 | | - if ( $prefix ) { |
2357 | | - $key = "$db-$prefix:" . implode( ':', $args ); |
2358 | | - } else { |
2359 | | - $key = $db . ':' . implode( ':', $args ); |
2360 | | - } |
| 2366 | + wfForeignWikiID($db,$prefix) . ':' . implode( ':', $args ); |
2361 | 2367 | return $key; |
2362 | 2368 | } |
2363 | 2369 | |
— | — | @@ -2365,7 +2371,7 @@ |
2366 | 2372 | * This is used as a prefix in memcached keys |
2367 | 2373 | */ |
2368 | 2374 | function wfWikiID() { |
2369 | | - global $wgDBprefix, $wgDBname; |
| 2375 | + global $wgDBname, wgDBprefix; |
2370 | 2376 | if ( $wgDBprefix ) { |
2371 | 2377 | return "$wgDBname-$wgDBprefix"; |
2372 | 2378 | } else { |
— | — | @@ -2374,6 +2380,22 @@ |
2375 | 2381 | } |
2376 | 2382 | |
2377 | 2383 | /** |
| 2384 | + * Get an ASCII string identifying a foreign wiki or shared db |
| 2385 | + * This is used as a prefix in foreign memcached keys |
| 2386 | + */ |
| 2387 | +function wfForeignWikiID( $db = null, $prefix = null ) { |
| 2388 | + global $wgSharedDB, $wgSharedPrefix, $wgDBname, $wgDBprefix; |
| 2389 | + if( !isset($db) ) $db = (isset($wgSharedDB) ? $wgSharedDB, $wgDBname); |
| 2390 | + if( !isset($prefix) ) $prefix = ($wgSharedPrefix ? $wgSharedPrefix, $wgDBprefix); |
| 2391 | + |
| 2392 | + if ( $prefix ) { |
| 2393 | + return "$db-$prefix"; |
| 2394 | + } else { |
| 2395 | + return $db; |
| 2396 | + } |
| 2397 | +} |
| 2398 | + |
| 2399 | +/** |
2378 | 2400 | * Split a wiki ID into DB name and table prefix |
2379 | 2401 | */ |
2380 | 2402 | function wfSplitWikiID( $wiki ) { |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -761,10 +761,12 @@ |
762 | 762 | */ |
763 | 763 | public function getFullURL( $query = '', $variant = false ) { |
764 | 764 | global $wgContLang, $wgServer, $wgRequest; |
765 | | - |
| 765 | + |
| 766 | + $query = wfBuildQuery( $query ); # Support query input other than strings. |
| 767 | + |
766 | 768 | if ( '' == $this->mInterwiki ) { |
767 | 769 | $url = $this->getLocalUrl( $query, $variant ); |
768 | | - |
| 770 | + |
769 | 771 | // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc) |
770 | 772 | // Correct fix would be to move the prepending elsewhere. |
771 | 773 | if ($wgRequest->getVal('action') != 'render') { |
— | — | @@ -772,7 +774,7 @@ |
773 | 775 | } |
774 | 776 | } else { |
775 | 777 | $baseUrl = $this->getInterwikiLink( $this->mInterwiki ); |
776 | | - |
| 778 | + |
777 | 779 | $namespace = wfUrlencode( $this->getNsText() ); |
778 | 780 | if ( '' != $namespace ) { |
779 | 781 | # Can this actually happen? Interwikis shouldn't be parsed. |
— | — | @@ -801,14 +803,16 @@ |
802 | 804 | public function getLocalURL( $query = '', $variant = false ) { |
803 | 805 | global $wgArticlePath, $wgScript, $wgServer, $wgRequest; |
804 | 806 | global $wgVariantArticlePath, $wgContLang, $wgUser; |
805 | | - |
| 807 | + |
| 808 | + $query = wfBuildQuery( $query ); # Support query input other than strings. |
| 809 | + |
806 | 810 | // internal links should point to same variant as current page (only anonymous users) |
807 | 811 | if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){ |
808 | 812 | $pref = $wgContLang->getPreferredVariant(false); |
809 | 813 | if($pref != $wgContLang->getCode()) |
810 | 814 | $variant = $pref; |
811 | 815 | } |
812 | | - |
| 816 | + |
813 | 817 | if ( $this->isExternal() ) { |
814 | 818 | $url = $this->getFullURL(); |
815 | 819 | if ( $query ) { |
— | — | @@ -844,7 +848,7 @@ |
845 | 849 | $query = $matches[1]; |
846 | 850 | if( isset( $matches[4] ) ) $query .= $matches[4]; |
847 | 851 | $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] ); |
848 | | - if( $query != '' ) $url .= '?' . $query; |
| 852 | + $url = wfAppendQuery( $url, $query ); |
849 | 853 | } |
850 | 854 | } |
851 | 855 | if ( $url === false ) { |
— | — | @@ -854,7 +858,7 @@ |
855 | 859 | $url = "{$wgScript}?title={$dbkey}&{$query}"; |
856 | 860 | } |
857 | 861 | } |
858 | | - |
| 862 | + |
859 | 863 | // FIXME: this causes breakage in various places when we |
860 | 864 | // actually expected a local URL and end up with dupe prefixes. |
861 | 865 | if ($wgRequest->getVal('action') == 'render') { |