Tweak for r39314: don't add a line break before the "Go" button on the watchlist...
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index c0d7fe9..dabe06d 100644 (file)
@@ -12,6 +12,9 @@ require_once dirname(__FILE__) . '/LogPage.php';
 require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
 require_once dirname(__FILE__) . '/XmlFunctions.php';
 
+// Hide compatibility functions from Doxygen
+/// @cond
+
 /**
  * Compatibility functions
  *
@@ -87,6 +90,9 @@ if ( !function_exists( 'array_diff_key' ) ) {
        }
 }
 
+/// @endcond
+
+
 /**
  * Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
  */
@@ -145,16 +151,31 @@ function wfRandom() {
 }
 
 /**
- * We want / and : to be included as literal characters in our title URLs.
+ * We want some things to be included as literal characters in our title URLs
+ * for prettiness, which urlencode encodes by default.  According to RFC 1738,
+ * all of the following should be safe:
+ *
+ * ;:@&=$-_.+!*'(),
+ *
+ * But + is not safe because it's used to indicate a space; &= are only safe in
+ * paths and not in queries (and we don't distinguish here); ' seems kind of
+ * scary; and urlencode() doesn't touch -_. to begin with.  Plus, although /
+ * is reserved, we don't care.  So the list we unescape is:
+ *
+ * ;:@$!*(),/
+ *
  * %2F in the page titles seems to fatally break for some reason.
  *
  * @param $s String:
  * @return string
 */
-function wfUrlencode ( $s ) {
+function wfUrlencode( $s ) {
        $s = urlencode( $s );
-       $s = preg_replace( '/%3[Aa]/', ':', $s );
-       $s = preg_replace( '/%2[Ff]/', '/', $s );
+       $s = str_ireplace(
+               array( '%3B','%3A','%40','%24','%21','%2A','%28','%29','%2C','%2F' ),
+               array(   ';',  ':',  '@',  '$',  '!',  '*',  '(',  ')',  ',',  '/' ),
+               $s
+       );
 
        return $s;
 }
@@ -655,9 +676,7 @@ function wfMsgExt( $key, $options ) {
        if ( in_array('escape', $options) ) {
                $string = htmlspecialchars ( $string );
        } elseif ( in_array( 'escapenoentities', $options ) ) {
-               $string = htmlspecialchars( $string );
-               $string = str_replace( '&', '&', $string );
-               $string = Sanitizer::normalizeCharReferences( $string );
+               $string = Sanitizer::escapeHtmlAllowEntities( $string );
        }
 
        if( in_array('replaceafter', $options) ) {
@@ -1055,6 +1074,34 @@ function wfArrayToCGI( $array1, $array2 = NULL )
        return $cgi;
 }
 
+/**
+ * This is the logical opposite of wfArrayToCGI(): it accepts a query string as
+ * its argument and returns the same string in array form.  This allows compa-
+ * tibility with legacy functions that accept raw query strings instead of nice
+ * arrays.  Of course, keys and values are urldecode()d.  Don't try passing in-
+ * valid query strings, or it will explode.
+ *
+ * @param $query string Query string
+ * @return array Array version of input
+ */
+function wfCgiToArray( $query ) {
+       if( isset( $query[0] ) and $query[0] == '?' ) {
+               $query = substr( $query, 1 );
+       }
+       $bits = explode( '&', $query );
+       $ret = array();
+       foreach( $bits as $bit ) {
+               if( $bit === '' ) {
+                       continue;
+               }
+               list( $key, $value ) = explode( '=', $bit );
+               $key = urldecode( $key );
+               $value = urldecode( $value );
+               $ret[$key] = $value;
+       }
+       return $ret;
+}
+
 /**
  * Append a query string to an existing URL, which may or may not already
  * have query string parameters already. If so, they will be combined.