Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I finally worked through all of the issues and now have a fairly decent solution to render the graph nicely, provide a list of links, and register the links with wiki. My solution doesn't fully support all of the capabilities of the current GraphViz extension as it is written as there is functionality we do not need and I do not want to support. Here are the assumptions / limitations of this solution:</p> <ul> <li>Does not support MscGen: We only have a need for Graphviz.</li> <li>Does not support imageAtrributes: We wanted to control the format and presentation and it seemed like there were inconsistencies in the imageAttributes implementation that would then cause further support issues.</li> <li>Does not support wikilinks: While it would be nice to provide consistent link usage through wiki and the Graphviz extension, the reality is that Graphviz is a completely different markup environment. While the current extension 'supports' wikilinks, the implementation is a little weak and leaves areas for confusion. Example: Wikilinks support giving the link an optional description but Graphviz already uses the node label for the description. So then you end up ignoring the wikilink description and telling users that 'Yes, we support wikilinks but don't use the description part' So since we aren't really using wikilinks correctly, just implement a regular link implementation and try to avoid the confusion entirely.</li> </ul> <p>Here is what the output looks like: <img src="https://i.stack.imgur.com/eVY1I.png" alt="Wiki Graphviz enhancements"></p> <p>Here are the changes that were made</p> <p>Comment out this line:</p> <pre><code>// We don't want to support wikilinks so don't replace them //$timelinesrc = rewriteWikiUrls( $timelinesrc ); // if we use wiki-links we transform them to real urls </code></pre> <p>Replace this block of code:</p> <pre><code>// clean up map-name $map = preg_replace( '#&lt;ma(.*)&gt;#', ' ', $map ); $map = str_replace( '&lt;/map&gt;', '', $map ); if ( $renderer == 'mscgen' ) { $mapbefore = $map; $map = preg_replace( '/(\w+)\s([_:%#/\w]+)\s(\d+,\d+)\s(\d+,\d+)/', '&lt;area shape="$1" href="$2" title="$2" alt="$2" coords="$3,$4" /&gt;', $map ); } /* Procduce html */ if ( $wgGraphVizSettings-&gt;imageFormatting ) { $txt = imageAtrributes( $args, $storagename, $map, $outputType, $wgUploadPath ); // if we want borders/position/... } else { $txt = '&lt;map name="' . $storagename . '"&gt;' . $map . '&lt;/map&gt;' . '&lt;img src="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '"' . ' usemap="#' . $storagename . '" /&gt;'; } </code></pre> <p>With this code:</p> <pre><code>$intHtml = ''; $extHtml = ''; $badHtml = ''; // Wrap the map/area info with top level nodes and load into xml object $xmlObj = new SimpleXMLElement( $map ); // What does map look like before we start working with it? wfDebugLog( 'graphviz', 'map before: ' . $map . "\n" ); // loop through each of the &lt;area&gt; nodes foreach($xmlObj-&gt;area as $areaNode) { wfDebugLog( 'graphviz', "areaNode: " . $areaNode-&gt;asXML() . "\n" ); // Get the data from the XML attributes $hrefValue = (string)$areaNode-&gt;attributes()-&gt;href; $textValue = (string)$areaNode-&gt;attributes()-&gt;title; wfDebugLog( 'graphviz', '$hrefValue before: ' . $hrefValue . "\n" ); wfDebugLog( 'graphviz', '$textValue before: ' . $textValue . "\n" ); // For the text fields, multiple spaces (" ") in the Graphviz source (label) // turns into a regular space followed by encoded representations of // non-breaking spaces (" &amp;#xA0;&amp;#xA0;") in the .map file which then turns // into the following in the local variables: ("   "). // The following two options appear to convert/decode the characters // appropriately. Leaving the lines commented out for now, as we have // not seen a graph in the wild with multiple spaces in the label - // just happened to stumble on the scenario. // See http://www.php.net/manual/en/simplexmlelement.asxml.php // and http://stackoverflow.com/questions/2050723/how-can-i-preg-replace-special-character-like-pret-a-porter //$textValue = iconv("UTF-8", "ASCII//TRANSLIT", $textValue); //$textValue = html_entity_decode($textValue, ENT_NOQUOTES, 'UTF-8'); // Now we need to deal with the whitespace characters like tabs and newlines // and also deal with them correctly to replace multiple occurences. // Unfortunately, the \n and \t values in the variable aren't actually // tab or newline characters but literal characters '\' + 't' or '\' + 'n'. // So the normally recommended regex '/\s+/u' to replace the whitespace // characters does not work. // See http://stackoverflow.com/questions/6579636/preg-replace-n-in-string $hrefValue = preg_replace("/( |\\\\n|\\\\t)+/", ' ', $hrefValue); $textValue = preg_replace("/( |\\\\n|\\\\t)+/", ' ', $textValue); // check to see if the url matches any of the // allowed protocols for external links if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $hrefValue ) ) { // external link $parser-&gt;mOutput-&gt;addExternalLink( $hrefValue ); $extHtml .= Linker::makeExternalLink( $hrefValue, $textValue ) . ', '; } else { $first = substr( $hrefValue, 0, 1 ); if ( $first == '\\' || $first == '[' || $first == '/' ) { // potential UNC path, wikilink, absolute or relative path $hrefValue = '#InvalidLink'; $badHtml .= Linker::makeExternalLink( $hrefValue, $textValue ) . ', '; $textValue = 'Invalid link. Check Graphviz source.'; } else { $title = Title::newFromText( $hrefValue ); if ( is_null( $title ) ) { // invalid link $hrefValue = '#InvalidLink'; $badHtml .= Linker::makeExternalLink( $hrefValue, $textValue ) . ', '; $textValue = 'Invalid link. Check Graphviz source.'; } else { // internal link $parser-&gt;mOutput-&gt;addLink( $title ); $intHtml .= Linker::link( $title, $textValue ) . ', '; $hrefValue = $title-&gt;getFullURL(); } } } $areaNode-&gt;attributes()-&gt;href = $hrefValue; $areaNode-&gt;attributes()-&gt;title = $textValue; } $map = $xmlObj-&gt;asXML(); // The contents of $map, which is now XML, gets embedded // in the HTML sent to the browser so we need to strip // the XML version tag and we also strip the &lt;map&gt; because // it will get replaced with a new one with the correct name. $map = str_replace( '&lt;?xml version="1.0"?&gt;', '', $map ); $map = preg_replace( '#&lt;ma(.*)&gt;#', ' ', $map ); $map = str_replace( '&lt;/map&gt;', '', $map ); // Let's see what it looks like now that we are done with it. wfDebugLog( 'graphviz', 'map after: ' . $map . "\n" ); $txt = '' . '&lt;table style="background-color:#f9f9f9;border:1px solid #ddd;"&gt;' . '&lt;tr&gt;' . '&lt;td style="border:1px solid #ddd;text-align:center;"&gt;' . '&lt;map name="' . $storagename . '"&gt;' . $map . '&lt;/map&gt;' . '&lt;img src="' . $wgUploadPath . '/graphviz/' . $storagename . '.' . $outputType . '"' . ' usemap="#' . $storagename . '" /&gt;' . '&lt;/td&gt;' . '&lt;/tr&gt;' . '&lt;tr&gt;' . '&lt;td style="font:10px verdana;"&gt;' . 'This Graphviz diagram links to the following pages:' . '&lt;br /&gt;&lt;strong&gt;Internal&lt;/strong&gt;: ' . ( $intHtml != '' ? rtrim( $intHtml, ' ,' ) : '&lt;em&gt;none&lt;/em&gt;' ) . '&lt;br /&gt;&lt;strong&gt;External&lt;/strong&gt;: ' . ( $extHtml != '' ? rtrim( $extHtml, ' ,' ) : '&lt;em&gt;none&lt;/em&gt;' ) . ( $badHtml != '' ? '&lt;br /&gt;&lt;strong&gt;Invalid&lt;/strong&gt;: ' . rtrim($badHtml, ' ,') . '&lt;br /&gt;&lt;em&gt;Tip: Do not use wikilinks ([]), UNC paths (\\) or relative links (/) when creating links in Graphviz diagrams.&lt;/em&gt;' : '' ) . '&lt;/td&gt;' . '&lt;/tr&gt;' . '&lt;/table&gt;'; </code></pre> <p>Possible enhancements: </p> <ul> <li>It would be nice if the list of links below the graph were sorted and de-duped.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload