Dan-nl has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/124376

Change subject: don’t place sub-template into main template when no value is 
present
......................................................................

don’t place sub-template into main template when no value is present

* added logic that will not place the sub-template for {{Creator}} or
  {{Institution}} into the main template if the corresponding fields
  have no values.

Bug: 63646
Change-Id: Ica75e892edaf3c1069da01ac695fa28607e35435
---
M includes/Models/MediawikiTemplate.php
1 file changed, 14 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset 
refs/changes/76/124376/1

diff --git a/includes/Models/MediawikiTemplate.php 
b/includes/Models/MediawikiTemplate.php
index 1a13a0b..1a0d18b 100644
--- a/includes/Models/MediawikiTemplate.php
+++ b/includes/Models/MediawikiTemplate.php
@@ -214,10 +214,14 @@
                                $content = trim( $content );
 
                                if ( $parameter === 'institution' ) {
-                                       $sections .= sprintf(
+                                       if ( empty( $content ) ) {
+                                               $sections .= PHP_EOL;
+                                       } else {
+                                               $sections .= sprintf(
                                                        
$this->_sub_templates['institution'],
                                                        Utils::sanitizeString( 
$content )
                                                ) . PHP_EOL;
+                                       }
                                } elseif ( $parameter === 'artist' ) {
                                        // assumes that there could be more 
than one creator and uses the
                                        // configured metadata separator to 
determine that
@@ -228,16 +232,20 @@
                                                // no other assumptions are 
made other than this one
                                                $creator = explode( ',', 
$creator, 2 );
 
-                                               if ( count( $creator ) === 2 ) {
-                                                       $creator = trim( 
$creator[1] ) . ' ' . trim( $creator[0] );
+                                               if ( count( $creator ) <= 1 && 
empty( $creator[0] ) ) {
+                                                       $sections .= PHP_EOL;
                                                } else {
-                                                       $creator = trim( 
$creator[0] );
-                                               }
+                                                       if ( count( $creator ) 
=== 2 ) {
+                                                               $creator = 
trim( $creator[1] ) . ' ' . trim( $creator[0] );
+                                                       } else {
+                                                               $creator = 
trim( $creator[0] );
+                                                       }
 
-                                               $sections .= sprintf(
+                                                       $sections .= sprintf(
                                                                
$this->_sub_templates['creator'],
                                                                
Utils::sanitizeString( $creator )
                                                        ) . PHP_EOL;
+                                               }
                                        }
                                } elseif ( $parameter === 'permission' ) {
                                        // 
http://commons.wikimedia.org/wiki/Category:Creative_Commons_licenses

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica75e892edaf3c1069da01ac695fa28607e35435
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GWToolset
Gerrit-Branch: master
Gerrit-Owner: Dan-nl <[email protected]>

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

Reply via email to