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 .= '<span class="error">' . 
$this->msg( "cargo-cargotables-nonexistenttable" )->parse() . '</span>';
+                               $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 );
-                               }
-                               $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 ) {
-                               $attachingTemplatesText = '';
-                       } else {
-                               $templateLinks = array();
-                               foreach ( $templatesThatAttachToThisTable as 
$templateID ) {
-                                       $templateTitle = Title::newFromID( 
$templateID );
-                                       $templateLinks[] = 
CargoUtils::makeLink( $linkRenderer, $templateTitle );
-                               }
-                               $attachingTemplatesText = $this->msg(
-                                               'cargo-cargotables-attachedby', 
implode( ', ', $templateLinks ) )->text();
-                       }
-
-                       $tableText = "$tableName ($actionLinks) - $numRowsText 
($declaringTemplatesText";
-                       if ( $attachingTemplatesText != '' ) {
-                               $tableText .= ", $attachingTemplatesText";
-                       }
-                       $tableText .= ')';
+                       $tableText = "$tableName ($actionLinks) - $numRowsText 
($templatesText)";
 
                        if ( $hasReplacementTable ) {
                                if ( !$cdb->tableExists( $tableName . '__NEXT' 
) ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a80cc637b2d13c408f75820ef4705eabaaa9e7d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to