jquery.accessKeyLabel: Optimise by using mw.message().plain()
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 21 Aug 2018 04:45:43 +0000 (05:45 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 21 Aug 2018 17:04:46 +0000 (17:04 +0000)
Avoids invoking mw.message#text, which uses the parser() of jqueryMsg,
twice for each call to jquery.accessKeyLabel.

These two messages do not contain any wikitext features, and are
not expected to need them in the future.

To make this explicit, add `{{format|plain}}` to their documentation,
and change the code to use plain().

Bug: T202357
Change-Id: I642f09afda4a93a1208550d44072f0909dcabdd0

languages/i18n/qqq.json
resources/src/jquery/jquery.accessKeyLabel.js

index 4b1717d..b6558b6 100644 (file)
        "colon-separator": "{{optional}}\nChange it only if your language uses another character for ':' or it needs an extra space before the colon.",
        "autocomment-prefix": "{{notranslate}}",
        "pipe-separator": "{{optional}}",
-       "word-separator": "{{optional}}\nThis is a string which is (usually) put between words of the language. It is used, e.g. when messages are concatenated (appended to each other). Note that you must express a space as html entity &amp;#32; because the editing and updating process strips leading and trailing spaces from messages.\n\nMost languages use a space, but some Asian languages, such as Thai and Chinese, do not.",
+       "word-separator": "{{optional}}\nThis is a string which is (usually) put between words of the language. It is used, e.g. when messages are concatenated (appended to each other). Note that you must express a space as html entity &amp;#32; because the editing and updating process strips leading and trailing spaces from messages.\n\nMost languages use a space, but some Asian languages, such as Thai and Chinese, do not.\n{{Format|plain}}",
        "ellipsis": "{{optional}}",
        "percent": "{{optional}}",
        "parentheses": "{{optional}}",
-       "brackets": "{{Optional}}",
+       "brackets": "{{Optional}}\n{{Format|plain}}",
        "quotation-marks": "Quotation marks, for quoting, sometimes titles etc., depending on the language.\n\nSee: [[w:Non-English usage of quotation marks|Non-English usage of quotation marks on Wikipedia]].\n\nParameters:\n* $1 - text to be wrapped in quotation marks",
        "imgmultipageprev": "{{Identical|Previous page}}",
        "imgmultipagenext": "{{Identical|Next page}}",
index 91b7035..674f62c 100644 (file)
         * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`)
         */
        function updateTooltipOnElement( element, titleElement ) {
-               var oldTitle, parts, regexp, newTitle, accessKeyLabel;
+               var oldTitle, parts, regexp, newTitle, accessKeyLabel,
+                       separatorMsg = mw.message( 'word-separator' ).plain();
 
                oldTitle = titleElement.title;
                if ( !oldTitle ) {
                        return;
                }
 
-               parts = ( mw.msg( 'word-separator' ) + mw.msg( 'brackets' ) ).split( '$1' );
+               parts = ( separatorMsg + mw.message( 'brackets' ).plain() ).split( '$1' );
                regexp = new RegExp( parts.map( mw.RegExp.escape ).join( '.*?' ) + '$' );
                newTitle = oldTitle.replace( regexp, '' );
                accessKeyLabel = getAccessKeyLabel( element );
 
                if ( accessKeyLabel ) {
                        // Should be build the same as in Linker::titleAttrib
-                       newTitle += mw.msg( 'word-separator' ) + mw.msg( 'brackets', accessKeyLabel );
+                       newTitle += separatorMsg + mw.message( 'brackets', accessKeyLabel ).plain();
                }
                if ( oldTitle !== newTitle ) {
                        titleElement.title = newTitle;