Gerrit Patch Uploader has uploaded a new change for review.

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

Change subject: Make broken wikilinks in timelines red
......................................................................

Make broken wikilinks in timelines red

Bug: 4
Change-Id: Ia49ceb211331a70618301e2b85bd8a2597786831
---
M EasyTimeline.pl
M Timeline.php
2 files changed, 51 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/timeline 
refs/changes/27/130027/1

diff --git a/EasyTimeline.pl b/EasyTimeline.pl
index a4dcb00..5275d37 100644
--- a/EasyTimeline.pl
+++ b/EasyTimeline.pl
@@ -118,6 +118,7 @@
 my $false = 0;
 
 my $LinkColor              = "brightblue";
+my $BrokenLinkColor        = "red";
 my $MapPNG                 = $false;        # switched when link or hint found
 my $MapSVG                 = $false;        # switched when link found
 my $WarnTextOutsideArea    = 0;
@@ -3174,6 +3175,7 @@
     my $align     = shift;
     my $link      = shift;
     my $hint      = shift;
+    my $exists    = shift;
 
     if (length($text) > 250) {
         &Error(
@@ -3273,7 +3275,11 @@
             }
         }
 
-        $textdetails =~ s/color=[^\s]+/color=$LinkColor/;
+        if ($exists) {
+            $textdetails =~ s/color=[^\s]+/color=$LinkColor/;
+        } else {
+            $textdetails =~ s/color=[^\s]+/color=$BrokenLinkColor/;
+        }            
         push @PlotTextsPng, $textdetails . "\n";
 
         $text = &DecodeInput($text);
@@ -3317,7 +3323,7 @@
     my $link      = shift;
     my $hint      = shift;
     my $tabs      = shift;
-    my ($link2, $hint2, $tab);
+    my ($link2, $hint2, $tab, $exists2);
     my $outside = $false;
 
     if ($Axis{"order"} =~ /reverse/i) {
@@ -3389,7 +3395,8 @@
         if ($text_item !~ /^[\n\s]*$/) {
             $link2 = "";
             $hint2 = "";
-            ($text_item, $link2, $hint2) =
+            $exists2 = $true;
+            ($text_item, $link2, $hint2, $exists2) =
                 &ProcessWikiLink($text_item, $link2, $hint2);
 
             if ($link2 eq "") {
@@ -3402,7 +3409,7 @@
 
             &WriteProcAnnotate(
                 $bar,       $shiftx,   $posx,  $posy,  $text_item,
-                $textcolor, $fontsize, $align, $link2, $hint2
+                $textcolor, $fontsize, $align, $link2, $hint2, $exists2
             );
         }
 
@@ -3716,6 +3723,7 @@
         my $text;
         my $link;
         my $hint;
+        my $exists;
 
         my @Bars2;
 
@@ -3731,13 +3739,14 @@
 
         foreach my $bar2_iter (@Bars2) {
             $hint = "";
+            $exists = $true;
             $text = $BarLegend{ lc($bar2_iter) };
             if ($text =~ /^\s*$/) { $text = "\\"; }
 
             $link = $BarLink{ lc($bar2_iter) };
             if (!defined($link)) {
                 if ($text =~ /\[.*\]/) {
-                    ($text, $link, $hint) =
+                    ($text, $link, $hint, $exists) =
                         &ProcessWikiLink($text, $link, $hint);
                 }
             }
@@ -3781,7 +3790,7 @@
             $link = $BarLink{ lc($bars2_iter) };
             if (!defined($link)) {
                 if ($text =~ /\[.*\]/) {
-                    ($text, $link, $hint) =
+                    ($text, $link, $hint, $exists) =
                         &ProcessWikiLink($text, $link, $hint);
                 }
             }
@@ -5079,6 +5088,7 @@
     my $link     = shift;
     my $hint     = shift;
     my $wikilink = $false;
+    my $exists   = $true;
 
     chomp($text);
     chomp($link);
@@ -5150,6 +5160,11 @@
             $link =~ s/\$1/$urlpart/;
             if (($hint eq "") && ($title ne "")) { $hint = "$title"; }
         }
+        print "exists? $title\n";
+        $exists = <STDIN>;
+        chomp($exists);
+        if ($exists eq "does_not_exist") { $exists = $false; }
+        else { $exists = $true; }
         $hint =~ s/_/ /g;
     }
     else {
@@ -5161,7 +5176,7 @@
     }
 
     $hint = &EncodeHtml($hint);
-    return ($text, $link, $hint);
+    return ($text, $link, $hint, $exists);
 }
 
 sub ExternalLinkToHint {
diff --git a/Timeline.php b/Timeline.php
index 13ba281..f83178e 100644
--- a/Timeline.php
+++ b/Timeline.php
@@ -140,7 +140,35 @@
                        // Actually run the command...
                        wfDebug( "Timeline cmd: $cmdline\n" );
                        $retVal = null;
-                       $ret = wfShellExec( $cmdline, $retVal );
+                       $desc = array(
+                               0 => array("pipe", "r"),
+                               1 => array("pipe", "w"),
+                               2 => array("pipe", "w"),
+                       );
+                       // Communicate with rendering process: does page X 
exist?
+                       $proc = proc_open( $cmdline, $desc, $pipes );
+                       $ret = "";
+                       if ( is_resource( $proc ) ) {
+                               while ( !feof( $pipes[1] ) ) {
+                                       $line = fgets( $pipes[1] );
+                                       if ( strpos( $line, "exists? " ) === 0 
) {
+                                               // if the command is asking us 
if link should be red or blue...
+                                               $title = Title::newFromText( 
trim( substr( $line, 8 ) ) );
+                                               if ( $title == null ) {
+                                                       fwrite( $pipes[0], 
"does_not_exist\n" );
+                                               } elseif ( $title->isKnown() ) {
+                                                       // Checking "existence" 
of page title
+                                                       fwrite( $pipes[0], 
"exists\n" );
+                                               } else {
+                                                       fwrite( $pipes[0], 
"does_not_exist\n" );
+                                               }
+                                       }
+                                       else {
+                                               $ret .= $line;
+                                       }
+                               }
+                               $retVal = proc_close( $proc );
+                       }
 
                        // If running in svg2png mode, create the PNG file from 
the SVG
                        if ( $svg2png ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia49ceb211331a70618301e2b85bd8a2597786831
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/timeline
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to