From: Timo Tijhof Date: Fri, 6 Sep 2019 00:32:38 +0000 (+0100) Subject: mediawiki.util: Move to its own resources/src/ directory X-Git-Tag: 1.34.0-rc.0~361^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=f3659b8d27b169ee1b0db950c1f2839a54139a35;p=lhc%2Fweb%2Fwiklou.git mediawiki.util: Move to its own resources/src/ directory It only has one real file right now, but per T193826 modules that are bound to an explicit directory should have already gotten its own directory. Anyway, this'll make it easier to add other files in it in a separate commit. Change-Id: Iae7d270bf08d5a623b0a90c37c7cfc0c8e424a76 --- diff --git a/resources/Resources.php b/resources/Resources.php index 8234e8970c..d4ee4c516a 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1254,10 +1254,10 @@ return [ ] ], 'mediawiki.util' => [ - 'localBasePath' => "$IP/resources/src", - 'remoteBasePath' => "$wgResourceBasePath/resources/src", + 'localBasePath' => "$IP/resources/src/mediawiki.util/", + 'remoteBasePath' => "$wgResourceBasePath/resources/srcmediawiki.util/", 'packageFiles' => [ - 'mediawiki.util.js', + 'util.js', [ 'name' => 'config.json', 'config' => [ 'FragmentMode', 'LoadScript', diff --git a/resources/src/mediawiki.util.js b/resources/src/mediawiki.util.js deleted file mode 100644 index 36a0195d84..0000000000 --- a/resources/src/mediawiki.util.js +++ /dev/null @@ -1,565 +0,0 @@ -( function () { - 'use strict'; - - var util, - config = require( './config.json' ); - - /** - * 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 'legacy': - return rawurlencode( str.replace( / /g, '_' ) ) - .replace( /%3A/g, ':' ) - .replace( /%/g, '.' ); - default: - throw new Error( 'Unrecognized ID escaping mode ' + mode ); - } - } - - /** - * Utility library - * @class mw.util - * @singleton - */ - util = { - - /** - * Encode the string like PHP's rawurlencode - * - * @param {string} str String to be encoded. - * @return {string} Encoded string - */ - rawurlencode: rawurlencode, - - /** - * Encode string into HTML id compatible form suitable for use in HTML - * Analog to PHP Sanitizer::escapeIdForAttribute() - * - * @since 1.30 - * - * @param {string} str String to encode - * @return {string} Encoded string - */ - escapeIdForAttribute: function ( str ) { - var mode = config.FragmentMode[ 0 ]; - - return escapeIdInternal( str, mode ); - }, - - /** - * Encode string into HTML id compatible form suitable for use in links - * Analog to PHP Sanitizer::escapeIdForLink() - * - * @since 1.30 - * - * @param {string} str String to encode - * @return {string} Encoded string - */ - escapeIdForLink: function ( str ) { - var mode = config.FragmentMode[ 0 ]; - - return escapeIdInternal( str, mode ); - }, - - /** - * Encode page titles for use in a URL - * - * We want / and : to be included as literal characters in our title URLs - * as they otherwise fatally break the title. - * - * The others are decoded because we can, it's prettier and matches behaviour - * of `wfUrlencode` in PHP. - * - * @param {string} str String to be encoded. - * @return {string} Encoded string - */ - wikiUrlencode: function ( str ) { - return util.rawurlencode( str ) - .replace( /%20/g, '_' ) - // wfUrlencode replacements - .replace( /%3B/g, ';' ) - .replace( /%40/g, '@' ) - .replace( /%24/g, '$' ) - .replace( /%21/g, '!' ) - .replace( /%2A/g, '*' ) - .replace( /%28/g, '(' ) - .replace( /%29/g, ')' ) - .replace( /%2C/g, ',' ) - .replace( /%2F/g, '/' ) - .replace( /%7E/g, '~' ) - .replace( /%3A/g, ':' ); - }, - - /** - * Get the link to a page name (relative to `wgServer`), - * - * @param {string|null} [pageName=wgPageName] Page name - * @param {Object} [params] A mapping of query parameter names to values, - * e.g. `{ action: 'edit' }` - * @return {string} Url of the page with name of `pageName` - */ - getUrl: function ( pageName, params ) { - var titleFragmentStart, url, query, - fragment = '', - title = typeof pageName === 'string' ? pageName : mw.config.get( 'wgPageName' ); - - // Find any fragment - titleFragmentStart = title.indexOf( '#' ); - if ( titleFragmentStart !== -1 ) { - fragment = title.slice( titleFragmentStart + 1 ); - // Exclude the fragment from the page name - title = title.slice( 0, titleFragmentStart ); - } - - // Produce query string - if ( params ) { - query = $.param( params ); - } - if ( query ) { - url = title ? - util.wikiScript() + '?title=' + util.wikiUrlencode( title ) + '&' + query : - util.wikiScript() + '?' + query; - } else { - url = mw.config.get( 'wgArticlePath' ) - .replace( '$1', util.wikiUrlencode( title ).replace( /\$/g, '$$$$' ) ); - } - - // Append the encoded fragment - if ( fragment.length ) { - url += '#' + util.escapeIdForLink( fragment ); - } - - return url; - }, - - /** - * Get address to a script in the wiki root. - * For index.php use `mw.config.get( 'wgScript' )`. - * - * @since 1.18 - * @param {string} str Name of script (e.g. 'api'), defaults to 'index' - * @return {string} Address to script (e.g. '/w/api.php' ) - */ - wikiScript: function ( str ) { - str = str || 'index'; - if ( str === 'index' ) { - return mw.config.get( 'wgScript' ); - } else if ( str === 'load' ) { - return config.LoadScript; - } else { - return mw.config.get( 'wgScriptPath' ) + '/' + str + '.php'; - } - }, - - /** - * Append a new style block to the head and return the CSSStyleSheet object. - * Use .ownerNode to access the `