jenkins-bot has submitted this change and it was merged.

Change subject: [PagePreparation] Categories kept as a part of page template
......................................................................


[PagePreparation] Categories kept as a part of page template

The Categories have been surrounded by </translate>...</translate> tags
so that they become a part of the page template. They are also tagged with
the {{#translation}} magic word.

It depends on I61e3a89a1d013ce88a03b3f42abd7c535dbd797f (for the
namespaces) and I16bb4fe5294c238aa345e9b33350d64d518748f4 (for
{{#translation}}).

Bug: T68880
Change-Id: I3ee551904ee0cbcbdb486fdbc6c0693254a43513
---
M resources/js/ext.translate.special.pagepreparation.js
1 file changed, 32 insertions(+), 4 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/js/ext.translate.special.pagepreparation.js 
b/resources/js/ext.translate.special.pagepreparation.js
index f82a8da..9f77222 100644
--- a/resources/js/ext.translate.special.pagepreparation.js
+++ b/resources/js/ext.translate.special.pagepreparation.js
@@ -49,8 +49,8 @@
        }
 
        /**
-        * Remove all the <translate> tags before preparing the page. The
-        * tool will add them back wherever needed.
+        * Remove all the <translate> tags and {{translation}} templates before
+        * preparing the page. The tool will add them back wherever needed.
         * @param {string} pageContent
         * @return {string}
         */
@@ -71,6 +71,32 @@
                }
                pageContent = pageContent.replace( /\{\{languages.*?\}\}/gi, '' 
);
                return pageContent;
+       }
+
+       /**
+        * Add <translate> tags around Categories to make them a part of the 
page template
+        * and tag them with the {{translation}} template.
+        * @param {string} pageContent
+        * @return {jQuery.Promise}
+        */
+       function doCategories( pageContent ) {
+               return getNamespaceAliases( 14 ).then( function ( aliases ) {
+                       var aliasList, categoryRegex;
+
+                       aliases.push( 'category' );
+                       for ( var i = 0; i < aliases.length; i++ ) {
+                               aliases[i] = $.escapeRE( aliases[i] );
+                       }
+
+                       aliasList = aliases.join( '|' );
+                       // Regex: http://regex101.com/r/sJ3gZ4/2
+                       categoryRegex = new RegExp( '\\[\\[((' + aliasList + 
')' +
+                               ':[^\\|]+)(\\|[^\\|]*?)?\\]\\]', 'gi' );
+                       pageContent = pageContent.replace( categoryRegex, 
'\n</translate>\n' +
+                               '[[$1{{#translation:}}$3]]\n<translate>\n' );
+
+                       return pageContent;
+               } );
        }
 
        /**
@@ -156,7 +182,7 @@
         * @return {jQuery.Promise}
         */
        function doFiles( pageContent ) {
-               getNamespaceAliases( 6 ).then( function ( aliases ) {
+               return getNamespaceAliases( 6 ).then( function ( aliases ) {
                        var aliasList, captionFilesRegex, fileRegex;
 
                        aliases.push( 'file' );
@@ -300,7 +326,9 @@
                                pageContent = addNewLines( pageContent );
                                pageContent = fixInternalLinks( pageContent );
                                pageContent = doTemplates( pageContent );
-                               doFiles( pageContent ).done( function( 
pageContent ) {
+                               doFiles( pageContent )
+                               .then( doCategories )
+                               .done( function( pageContent ) {
                                        pageContent = postPreparationCleanup( 
pageContent );
                                        pageContent = $.trim( pageContent );
                                        getDiff( pageName, pageContent ).done( 
function ( diff ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/140926
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3ee551904ee0cbcbdb486fdbc6c0693254a43513
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: BPositive <[email protected]>
Gerrit-Reviewer: BPositive <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to