}
/**
- * This function takes one or two arrays, objects, or strings as input, and returns a CGI-style string, e.g.
+ * This function takes two arrays as input, and returns a CGI-style string, e.g.
* "days=7&limit=100". Options in the first array override options in the second.
* Options set to "" will not be output.
- * @depreciated
- */
-function wfArrayToCGI( $query1, $query2 = null ) {
- if( is_null($query2) ) wfBuildQuery( $query1 );
- else wfBuildQuery( $query2, $query1 );
-}
-/**
- * wfBuildQuery is a improved wrapper for http_build_query.
- * We support a defaults array which the query may be merged with. As well we also support
- * arrays, objects, and strings as input.
- */
-function wfBuildQuery( $query, $defaults = null ) {
- if( !is_null($defaults) ) {
- ## If either array is a string, then parse it and make sure to fix magic quotes.
- foreach( array( 'query', 'defaults' ) as $var ) {
- if( is_string($$var) ) {
- $arr = array();
- parse_str($$var, &$arr);
- if( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
- global $wgRequest;
- $wgRequest->fix_magic_quotes( $arr );
- }
- $$var = $arr;
+ */
+function wfArrayToCGI( $array1, $array2 = NULL )
+{
+ if ( !is_null( $array2 ) ) {
+ $array1 = $array1 + $array2;
+ }
+
+ $cgi = '';
+ foreach ( $array1 as $key => $value ) {
+ if ( '' !== $value ) {
+ if ( '' != $cgi ) {
+ $cgi .= '&';
}
+ $cgi .= urlencode( $key ) . '=' . urlencode( $value );
}
- # Merge, make sure they are arrays, not objects.
- $query = ((array)$defaults) + ((array)$query);
}
-
- # Note that we must specify & because the default is sometimes &
- $cgi = is_string($query) ? $query : http_build_query( $query, null, '&' );
return $cgi;
}
* Get a cache key
*/
function wfMemcKey( /*... */ ) {
+ global $wgDBprefix, $wgDBname;
$args = func_get_args();
- $key = wfWikiID() . ':' . implode( ':', $args );
+ if ( $wgDBprefix ) {
+ $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args );
+ } else {
+ $key = $wgDBname . ':' . implode( ':', $args );
+ }
return $key;
}
*/
function wfForeignMemcKey( $db, $prefix /*, ... */ ) {
$args = array_slice( func_get_args(), 2 );
- wfForeignWikiID($db,$prefix) . ':' . implode( ':', $args );
+ if ( $prefix ) {
+ $key = "$db-$prefix:" . implode( ':', $args );
+ } else {
+ $key = $db . ':' . implode( ':', $args );
+ }
return $key;
}
* This is used as a prefix in memcached keys
*/
function wfWikiID() {
- global $wgDBname, wgDBprefix;
+ global $wgDBprefix, $wgDBname;
if ( $wgDBprefix ) {
return "$wgDBname-$wgDBprefix";
} else {
}
}
-/**
- * Get an ASCII string identifying a foreign wiki or shared db
- * This is used as a prefix in foreign memcached keys
- */
-function wfForeignWikiID( $db = null, $prefix = null ) {
- global $wgSharedDB, $wgSharedPrefix, $wgDBname, $wgDBprefix;
- if( !isset($db) ) $db = (isset($wgSharedDB) ? $wgSharedDB, $wgDBname);
- if( !isset($prefix) ) $prefix = ($wgSharedPrefix ? $wgSharedPrefix, $wgDBprefix);
-
- if ( $prefix ) {
- return "$db-$prefix";
- } else {
- return $db;
- }
-}
-
/**
* Split a wiki ID into DB name and table prefix
*/
*/
public function getFullURL( $query = '', $variant = false ) {
global $wgContLang, $wgServer, $wgRequest;
-
- $query = wfBuildQuery( $query ); # Support query input other than strings.
-
+
if ( '' == $this->mInterwiki ) {
$url = $this->getLocalUrl( $query, $variant );
-
+
// Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
// Correct fix would be to move the prepending elsewhere.
if ($wgRequest->getVal('action') != 'render') {
}
} else {
$baseUrl = $this->getInterwikiLink( $this->mInterwiki );
-
+
$namespace = wfUrlencode( $this->getNsText() );
if ( '' != $namespace ) {
# Can this actually happen? Interwikis shouldn't be parsed.
public function getLocalURL( $query = '', $variant = false ) {
global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
global $wgVariantArticlePath, $wgContLang, $wgUser;
-
- $query = wfBuildQuery( $query ); # Support query input other than strings.
-
+
// internal links should point to same variant as current page (only anonymous users)
if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
$pref = $wgContLang->getPreferredVariant(false);
if($pref != $wgContLang->getCode())
$variant = $pref;
}
-
+
if ( $this->isExternal() ) {
$url = $this->getFullURL();
if ( $query ) {
$query = $matches[1];
if( isset( $matches[4] ) ) $query .= $matches[4];
$url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
- $url = wfAppendQuery( $url, $query );
+ if( $query != '' ) $url .= '?' . $query;
}
}
if ( $url === false ) {
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
-
+
// FIXME: this causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
if ($wgRequest->getVal('action') == 'render') {
}
}
-function setupRightClickEdit() {
- if (document.getElementsByTagName) {
- var spans = document.getElementsByTagName('span');
- for (var i = 0; i < spans.length; i++) {
- var el = spans[i];
- if(el.className == 'editsection') {
- addRightClickEditHandler(el);
- }
- }
- }
-}
-
-function addRightClickEditHandler(el) {
- for (var i = 0; i < el.childNodes.length; i++) {
- var link = el.childNodes[i];
- if (link.nodeType == 1 && link.nodeName.toLowerCase() == 'a') {
- var editHref = link.getAttribute('href');
- // find the enclosing (parent) header
- var prev = el.parentNode;
- if (prev && prev.nodeType == 1 &&
- prev.nodeName.match(/^[Hh][1-6]$/)) {
- prev.oncontextmenu = function(e) {
- if (!e) { e = window.event; }
- // e is now the event in all browsers
- var targ;
- if (e.target) { targ = e.target; }
- else if (e.srcElement) { targ = e.srcElement; }
- if (targ.nodeType == 3) { // defeat Safari bug
- targ = targ.parentNode;
- }
- // targ is now the target element
-
- // We don't want to deprive the noble reader of a context menu
- // for the section edit link, do we? (Might want to extend this
- // to all <a>'s?)
- if (targ.nodeName.toLowerCase() != 'a'
- || targ.parentNode.className != 'editsection') {
- document.location = editHref;
- return false;
- }
- return true;
- };
- }
- }
- }
-}
-
var checkboxes;
var lastCheckbox;