r111760 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111759‎ | r111760 | r111761 >
Date:16:12, 17 February 2012
Author:amire80
Status:ok
Tags:i18nreview, niklas 
Comment:
Added the svgOnly setting. If it's enabled, the PNG will be created by MediaWiki's rasterize function, rather than by ploticus, thus allowing Unicode text. It will actually work only after I commit the corresponding changes in EasyTimeline.pl; until then, not using svgOnly shouldn't change any behavior.
Modified paths:
  • /trunk/extensions/timeline/Timeline.php (modified) (history)

Diff [purge]

Index: trunk/extensions/timeline/Timeline.php
@@ -38,6 +38,9 @@
3939
4040 // The name of the FileBackend to use for timeline (see $wgFileBackends)
4141 public $fileBackend = '';
 42+
 43+ // Whether to generate only an SVG file using ploticus
 44+ public $svgOnly = false;
4245 }
4346 $wgTimelineSettings = new TimelineSettings;
4447 $wgTimelineSettings->ploticusCommand = "/usr/bin/ploticus";
@@ -107,6 +110,7 @@
108111 // Get command for ploticus to read the user input and output an error,
109112 // map, and rendering (png or gif) file under the same dir as the temp file.
110113 $cmdline = wfEscapeShellArg( $wgTimelineSettings->perlCommand, $wgTimelineSettings->timelineFile ) .
 114+ ($wgTimelineSettings->svgOnly ? " -s " : "") .
111115 " -i " . wfEscapeShellArg( $tmpPath ) . " -m -P " . wfEscapeShellArg( $wgTimelineSettings->ploticusCommand ) .
112116 " -T " . wfEscapeShellArg( $wgTmpDirectory ) . " -A " . wfEscapeShellArg( $wgArticlePath ) .
113117 " -f " . wfEscapeShellArg( $wgTimelineSettings->fontFile );
@@ -116,6 +120,34 @@
117121 $retVal = null;
118122 $ret = wfShellExec( $cmdline, $retVal );
119123
 124+ // If running in svgOnly mode, create the PNG file from the SVG
 125+ if ( $wgTimelineSettings->svgOnly ) {
 126+ // Read the default timeline image size from the DVG file
 127+ $svgFilename = "{$tmpPath}.svg";
 128+ wfSuppressWarnings();
 129+ $svgHandle = fopen( $svgFilename, "r" );
 130+ wfRestoreWarnings();
 131+ if ( !$svgHandle ) {
 132+ throw new Exception( "Unable to open file $svgFilename for reading the timeline size" );
 133+ }
 134+ while ( !feof( $svgHandle ) ) {
 135+ $line = fgets( $svgHandle );
 136+ if ( preg_match( '/viewBox="0 0 ([0-9.]+) ([0-9.]+)"/', $line, $matches ) ) {
 137+ $svgWidth = $matches[1];
 138+ $svgHeight = $matches[2];
 139+ break;
 140+ }
 141+ }
 142+ fclose( $svgHandle );
 143+
 144+ $svgHandler = new SvgHandler();
 145+ wfDebug( "Rasterizing PNG timeline from SVG $svgFilename, size $svgWidth x $svgHeight\n" );
 146+ $rasterizeResult = $svgHandler->rasterize( $svgFilename, "{$tmpPath}.png", $svgWidth, $svgHeight );
 147+ if ( $rasterizeResult !== true ) {
 148+ return "<div dir=\"ltr\">FAIL: " . $rasterizeResult->toText() . "</div>";
 149+ }
 150+ }
 151+
120152 // Copy the output files into storage...
121153 // @TODO: store error files in another container or not at all?
122154 $opt = array( 'force' => 1, 'nonLocking' => 1, 'allowStale' => 1 ); // performance

Follow-up revisions

RevisionCommit summaryAuthorDate
r111864Replaced the svgOnly setting with a method parameter to the <timeline> tag, s...amire8014:09, 19 February 2012

Status & tagging log