+ var util;
+
+ /**
+ * Encode the string like PHP's rawurlencode
+ * @ignore
+ *
+ * @param {string} str String to be encoded.
+ * @return {string} Encoded string
+ */
+ function rawurlencode( str ) {
+ str = String( str );
+ return encodeURIComponent( str )
+ .replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
+ .replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' );
+ }
+
+ /**
+ * Private helper function used by util.escapeId*()
+ * @ignore
+ *
+ * @param {string} str String to be encoded
+ * @param {string} mode Encoding mode, see documentation for $wgFragmentMode
+ * in DefaultSettings.php
+ * @return {string} Encoded string
+ */
+ function escapeIdInternal( str, mode ) {
+ str = String( str );
+
+ switch ( mode ) {
+ case 'html5':
+ return str.replace( / /g, '_' );
+ case 'html5-legacy':
+ str = str.replace( /[ \t\n\r\f_'"&#%]+/g, '_' )
+ .replace( /^_+|_+$/, '' );
+ if ( str === '' ) {
+ str = '_';
+ }
+ return str;
+ case 'legacy':
+ return rawurlencode( str.replace( / /g, '_' ) )
+ .replace( /%3A/g, ':' )
+ .replace( /%/g, '.' );
+ default:
+ throw new Error( 'Unrecognized ID escaping mode ' + mode );
+ }
+ }
+