Tim Landscheidt has submitted this change and it was merged.

Change subject: Add support for toolinfo.json to tool page
......................................................................


Add support for toolinfo.json to tool page

Add logic similar to the logic used on the list page that will attempt
to fetch toolinfo data from the database for a given tool and display
that instead of the .description file if found.

Change-Id: Ib146ca62db0adc791cd2500aa99db260cbe0356c
---
M www/content/tool.php
1 file changed, 78 insertions(+), 25 deletions(-)

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



diff --git a/www/content/tool.php b/www/content/tool.php
index a320754..09aa7a7 100644
--- a/www/content/tool.php
+++ b/www/content/tool.php
@@ -2,34 +2,60 @@
 <p>Welcome to the Tool Labs project, the home of community-maintained external 
tools supporting Wikimedia projects and their users.</p>
 <?php
 $tool='';
-$g = posix_getgrnam( 'tools.' . $_REQUEST['tool'] );
-$u = posix_getpwnam( 'tools.' . $_REQUEST['tool'] );
-if ( $g && $u ) {
-       $tool = $_REQUEST['tool'];
-       $maintainers = $g['members'];
-       $home = $u['dir'];
+if ( $_REQUEST['tool'] ) {
+       $g = posix_getgrnam( 'tools.' . $_REQUEST['tool'] );
+       $u = posix_getpwnam( 'tools.' . $_REQUEST['tool'] );
+       if ( $g && $u ) {
+               $tool = $_REQUEST['tool'];
+               $maintainers = $g['members'];
+               $home = $u['dir'];
+       }
 }
 if ( $tool !== '' ) {
+       $info = null;
+
+       $ini = parse_ini_file( '/data/project/admin/replica.my.cnf' );
+       $db = new mysqli( 'tools.labsdb', $ini['user'], $ini['password'], 
'toollabs_p' );
+       if ( $db->connect_errno === 0 ) {
+               $stmt = $db->prepare( 'SELECT toolinfo FROM tools WHERE name = 
?' );
+               if ( $stmt !== false ) {
+                       $stmt->bind_param( 's', $tool );
+                       if ( $stmt->execute() !== false && $stmt->bind_result( 
$json ) ) {
+                               if ( $stmt->fetch() && $json ) {
+                                       $info = json_decode( $json, true );
+                               }
+                       }
+                       $stmt->close();
+               }
+               $db->close();
+       }
+
+       if ( $info === null ) {
+               // No toolinfo data found, so make some up
+               $info = array(
+                       'name' => $tool,
+                       'title' => $tool,
+               );
+               if ( glob( "{$home}/public_html/index.*" ) ) {
+                       // If the tool has an index file in their public_html 
then we
+                       // assume that the tool has a web UI. Lazier than 
polling the
+                       // proxy server.
+                       $info['url'] = '/' . urlencode( $tool ) . '/';
+               }
+               if ( is_readable( "{$home}/.description" ) ) {
+                       $info['description'] = file_get_contents(
+                               "{$home}/.description", false, null, 0, 2048 );
+               }
+       }
+
+       if ( isset( $info['name'] ) ) {
+               // Info only covers a single tool. Just to make things easier 
later on
+               // let's wrap this in a containing array.
+               $info = array( $info );
+       }
 ?>
-<h2>Tool details</h2>
+<h2>Tool account: <?= htmlspecialchars( $tool ) ?></h2>
 <table class="tool-info" cols="2" width="95%">
-<tr><th class="tool-name">
-<?php
-       echo htmlspecialchars( $tool );
-       if ( array_key_exists( 0, glob( "{$home}/public_html/index.*" ) ) ) {
-               echo '<br><span class="mw-editsection"><a href="/', urlencode( 
$tool ), '/">(Web interface)</a></span>';
-       }
-?>
-</th><td></td></tr>
-<tr><th>Description</th>
-<td>
-<?php
-       if ( is_readable( "{$home}/.description" ) ) {
-               $desc = file_get_contents( "{$home}/.description", false, null, 
0, 2048 );
-               print  $purifier->purify( $desc );
-       }
-?>
-</td></tr>
 <tr><th>Maintainers</th><td>
 <?php
        foreach ( $maintainers as $maint ) {
@@ -37,13 +63,40 @@
                if ( $mu ) {
                        $wtu = $mu['gecos'];
 ?>
-       <a href="https://wikitech.wikimedia.org/wiki/User:<?= urlencode( $wtu ) 
?>"><?= htmlspecialchars( ucfirst( $wtu ) ) ?></a>
+<a href="https://wikitech.wikimedia.org/wiki/User:<?= urlencode( $wtu ) 
?>"><?= htmlspecialchars( ucfirst( $wtu ) ) ?></a>
 <?php
                } else {
                        echo htmlspecialchars( ucfirst( $maint ) ), ' ';
                }
        }
 ?>
+</td></tr>
+<tr><th>Tool<?= count($info) > 1 ? 's' : '' ?></th><td>
+<?php
+       $first = ' first';
+       foreach ( $info as $toolinfo ) {
+               echo '<div class="subtool', $first, '"><span 
class="subtool-name">';
+               if ( isset( $toolinfo['url'] ) ) {
+                       echo "<a href=\"" . htmlspecialchars( $toolinfo['url'] 
) . "\">";
+               }
+               echo htmlspecialchars( $toolinfo['title'] );
+               if ( isset( $toolinfo['url'] ) ) {
+                       echo '</a>';
+               }
+               echo '</span><span class="subtool-desc">';
+               if ( isset( $toolinfo['description'] ) ) {
+                       echo  $purifier->purify( $toolinfo['description'] );
+                       if ( isset( $toolinfo['author'] ) ) {
+                               echo '<br><i>Author(s): ', $purifier->purify( 
$toolinfo['author'] ), '</i>';
+                       }
+                       if ( isset( $toolinfo['repository'] ) ) {
+                               echo '<br><a href="', htmlspecialchars( 
$toolinfo['repository'] ), '">Source</a>';
+                       }
+               }
+               echo '</span></div>';
+               $first = '';
+       }
+?>
 </td></tr></table>
 <?php } else { ?>
 <p>No such tool?  Trying to guess, are you?</p>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib146ca62db0adc791cd2500aa99db260cbe0356c
Gerrit-PatchSet: 2
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Tim Landscheidt <t...@tim-landscheidt.de>
Gerrit-Reviewer: Yuvipanda <yuvipa...@wikimedia.org>
Gerrit-Reviewer: coren <mpellet...@wikimedia.org>
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