[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Display template names in CargoTables even if table doesn't ...

2018-01-18 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/405017 )

Change subject: Display template names in CargoTables even if table doesn't 
exist
..


Display template names in CargoTables even if table doesn't exist

Change-Id: I4a80cc637b2d13c408f75820ef4705eabaaa9e7d
---
M specials/CargoTables.php
1 file changed, 46 insertions(+), 38 deletions(-)

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



diff --git a/specials/CargoTables.php b/specials/CargoTables.php
index f23ec3a..9879044 100644
--- a/specials/CargoTables.php
+++ b/specials/CargoTables.php
@@ -260,6 +260,49 @@
return $actionLinks;
}
 
+   function tableTemplatesText( $tableName, $templatesThatDeclareTables, 
$templatesThatAttachToTables ) {
+   if ( method_exists( $this, 'getLinkRenderer' ) ) {
+   $linkRenderer = $this->getLinkRenderer();
+   } else {
+   $linkRenderer = null;
+   }
+
+   // "Declared by" text
+   if ( !array_key_exists( $tableName, $templatesThatDeclareTables 
) ) {
+   $declaringTemplatesText = $this->msg( 
'cargo-cargotables-notdeclared' )->text();
+   } else {
+   $templatesThatDeclareThisTable = 
$templatesThatDeclareTables[$tableName];
+   $templateLinks = array();
+   foreach ( $templatesThatDeclareThisTable as $templateID 
) {
+   $templateTitle = Title::newFromID( $templateID 
);
+   $templateLinks[] = CargoUtils::makeLink( 
$linkRenderer, $templateTitle );
+   }
+   $declaringTemplatesText = $this->msg(
+   'cargo-cargotables-declaredby', implode( 
$templateLinks ) )->text();
+   }
+
+   // "Attached by" text
+   if ( array_key_exists( $tableName, $templatesThatAttachToTables 
) ) {
+   $templatesThatAttachToThisTable = 
$templatesThatAttachToTables[$tableName];
+   } else {
+   $templatesThatAttachToThisTable = array();
+   }
+
+   if ( count( $templatesThatAttachToThisTable ) == 0 ) {
+   return $declaringTemplatesText;
+   }
+
+   $templateLinks = array();
+   foreach ( $templatesThatAttachToThisTable as $templateID ) {
+   $templateTitle = Title::newFromID( $templateID );
+   $templateLinks[] = CargoUtils::makeLink( $linkRenderer, 
$templateTitle );
+   }
+   $attachingTemplatesText = $this->msg(
+   'cargo-cargotables-attachedby', implode( $templateLinks 
) )->text();
+
+   return "$declaringTemplatesText, $attachingTemplatesText";
+   }
+
/**
 * Returns HTML for a bulleted list of Cargo tables, with various
 * links and information for each one.
@@ -296,6 +339,7 @@
if ( !$cdb->tableExists( $tableName ) ) {
$tableText = "$tableName - ";
$tableText .= '' . 
$this->msg( "cargo-cargotables-nonexistenttable" )->parse() . '';
+   $tableText .= ' (' . $this->tableTemplatesText( 
$tableName, $templatesThatDeclareTables, $templatesThatAttachToTables ) . ')';
$text .= Html::rawElement( 'li', null, 
$tableText );
continue;
}
@@ -306,45 +350,9 @@
$firstTemplateID = $canBeRecreated ? 
$templatesThatDeclareTables[$tableName][0] : null;
$actionLinks = $this->displayActionLinksForTable( 
$tableName, false, $canBeRecreated, $firstTemplateID );
$numRowsText = $this->displayNumRowsForTable( $cdb, 
$tableName );
+   $templatesText = $this->tableTemplatesText( $tableName, 
$templatesThatDeclareTables, $templatesThatAttachToTables );
 
-   // "Declared by" text
-   if ( !array_key_exists( $tableName, 
$templatesThatDeclareTables ) ) {
-   $declaringTemplatesText = $this->msg( 
'cargo-cargotables-notdeclared' )->text();
-   } else {
-   $templatesThatDeclareThisTable = 
$templatesThatDeclareTables[$tableName];
-   $templateLinks = array();
-   foreach ( $templatesThatDeclareThisTable as 
$templateID ) {
-   $templateTitle = Title::newFromID( 
$templateID );
-   $templateLinks[] = 
CargoUtils::makeLink( $linkRenderer, $templateTitle );
- 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Display template names in CargoTables even if table doesn't ...

2018-01-18 Thread Yaron Koren (Code Review)
Yaron Koren has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/405017 )

Change subject: Display template names in CargoTables even if table doesn't 
exist
..

Display template names in CargoTables even if table doesn't exist

Change-Id: I4a80cc637b2d13c408f75820ef4705eabaaa9e7d
---
M specials/CargoTables.php
1 file changed, 46 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/17/405017/2

diff --git a/specials/CargoTables.php b/specials/CargoTables.php
index f23ec3a..9879044 100644
--- a/specials/CargoTables.php
+++ b/specials/CargoTables.php
@@ -260,6 +260,49 @@
return $actionLinks;
}
 
+   function tableTemplatesText( $tableName, $templatesThatDeclareTables, 
$templatesThatAttachToTables ) {
+   if ( method_exists( $this, 'getLinkRenderer' ) ) {
+   $linkRenderer = $this->getLinkRenderer();
+   } else {
+   $linkRenderer = null;
+   }
+
+   // "Declared by" text
+   if ( !array_key_exists( $tableName, $templatesThatDeclareTables 
) ) {
+   $declaringTemplatesText = $this->msg( 
'cargo-cargotables-notdeclared' )->text();
+   } else {
+   $templatesThatDeclareThisTable = 
$templatesThatDeclareTables[$tableName];
+   $templateLinks = array();
+   foreach ( $templatesThatDeclareThisTable as $templateID 
) {
+   $templateTitle = Title::newFromID( $templateID 
);
+   $templateLinks[] = CargoUtils::makeLink( 
$linkRenderer, $templateTitle );
+   }
+   $declaringTemplatesText = $this->msg(
+   'cargo-cargotables-declaredby', implode( 
$templateLinks ) )->text();
+   }
+
+   // "Attached by" text
+   if ( array_key_exists( $tableName, $templatesThatAttachToTables 
) ) {
+   $templatesThatAttachToThisTable = 
$templatesThatAttachToTables[$tableName];
+   } else {
+   $templatesThatAttachToThisTable = array();
+   }
+
+   if ( count( $templatesThatAttachToThisTable ) == 0 ) {
+   return $declaringTemplatesText;
+   }
+
+   $templateLinks = array();
+   foreach ( $templatesThatAttachToThisTable as $templateID ) {
+   $templateTitle = Title::newFromID( $templateID );
+   $templateLinks[] = CargoUtils::makeLink( $linkRenderer, 
$templateTitle );
+   }
+   $attachingTemplatesText = $this->msg(
+   'cargo-cargotables-attachedby', implode( $templateLinks 
) )->text();
+
+   return "$declaringTemplatesText, $attachingTemplatesText";
+   }
+
/**
 * Returns HTML for a bulleted list of Cargo tables, with various
 * links and information for each one.
@@ -296,6 +339,7 @@
if ( !$cdb->tableExists( $tableName ) ) {
$tableText = "$tableName - ";
$tableText .= '' . 
$this->msg( "cargo-cargotables-nonexistenttable" )->parse() . '';
+   $tableText .= ' (' . $this->tableTemplatesText( 
$tableName, $templatesThatDeclareTables, $templatesThatAttachToTables ) . ')';
$text .= Html::rawElement( 'li', null, 
$tableText );
continue;
}
@@ -306,45 +350,9 @@
$firstTemplateID = $canBeRecreated ? 
$templatesThatDeclareTables[$tableName][0] : null;
$actionLinks = $this->displayActionLinksForTable( 
$tableName, false, $canBeRecreated, $firstTemplateID );
$numRowsText = $this->displayNumRowsForTable( $cdb, 
$tableName );
+   $templatesText = $this->tableTemplatesText( $tableName, 
$templatesThatDeclareTables, $templatesThatAttachToTables );
 
-   // "Declared by" text
-   if ( !array_key_exists( $tableName, 
$templatesThatDeclareTables ) ) {
-   $declaringTemplatesText = $this->msg( 
'cargo-cargotables-notdeclared' )->text();
-   } else {
-   $templatesThatDeclareThisTable = 
$templatesThatDeclareTables[$tableName];
-   $templateLinks = array();
-   foreach ( $templatesThatDeclareThisTable as 
$templateID ) {
-   $templateTitle = Title::newFromID( 
$templateID );
-   $templateLinks[] = 
CargoUtils::makeLink( $linkRenderer, $templateTitle