Jsahleen has submitted this change and it was merged.

Change subject: Category text construction refactoring
......................................................................


Category text construction refactoring

Avoid the duplication of construction of actual categories and
high MT category by using all of them in an array. Also
avoid the problem of some categories going to <nowiki> and high MT
without <nowiki>

Change-Id: Iab2bfaaf093e9457a6b6acadb174b5e90c849846
---
M api/ApiContentTranslationPublish.php
1 file changed, 12 insertions(+), 12 deletions(-)

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



diff --git a/api/ApiContentTranslationPublish.php 
b/api/ApiContentTranslationPublish.php
index 4d2263f..4e131b2 100644
--- a/api/ApiContentTranslationPublish.php
+++ b/api/ApiContentTranslationPublish.php
@@ -45,6 +45,7 @@
 
        protected function saveWikitext( $title, $wikitext, $params ) {
                global $wgContentTranslationHighMTCategory;
+               $categories = array();
 
                $sourceLink = '[[:' . $params['from']
                        . ':Special:Redirect/revision/'
@@ -53,18 +54,7 @@
 
                if ( $params['categories'] ) {
                        $categories = explode( '|', $params['categories'] );
-                       foreach ( $categories as $categoryTitle ) {
-                               $categoryText .= "\n[[" . $categoryTitle . "]]";
-                       }
                }
-
-               // If publishing to User namespace, wrap categories in <nowiki>
-               // to avoid blocks by abuse filter. See T88007.
-               if ( isset( $categoryText ) && $title->inNamespace( NS_USER ) ) 
{
-                       $categoryText = "<nowiki>" . $categoryText . 
"\n</nowiki>";
-               }
-
-               $wikitext .= $categoryText;
 
                $progress = json_decode( $params['progress'], true );
                if (
@@ -72,7 +62,17 @@
                        $wgContentTranslationHighMTCategory &&
                        $this->hasHighMT( $progress )
                ) {
-                       $wikitext .= "\n[[" . 
$wgContentTranslationHighMTCategory . ']]';
+                       $categories[] = $wgContentTranslationHighMTCategory;
+               }
+
+               if ( count( $categories ) ) {
+                       $categoryText = "\n[[" . implode( "]]\n[[", $categories 
) . ']]';
+                       // If publishing to User namespace, wrap categories in 
<nowiki>
+                       // to avoid blocks by abuse filter. See T88007.
+                       if ( $title->inNamespace( NS_USER ) ) {
+                               $categoryText = 
"\n<nowiki>$categoryText</nowiki>";
+                       }
+                       $wikitext .= $categoryText;
                }
 
                $summary = $this->msg(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iab2bfaaf093e9457a6b6acadb174b5e90c849846
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Jsahleen <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to