Index: trunk/extensions/timeline/Timeline.php |
— | — | @@ -38,6 +38,9 @@ |
39 | 39 | |
40 | 40 | // The name of the FileBackend to use for timeline (see $wgFileBackends) |
41 | 41 | public $fileBackend = ''; |
| 42 | + |
| 43 | + // Whether to generate only an SVG file using ploticus |
| 44 | + public $svgOnly = false; |
42 | 45 | } |
43 | 46 | $wgTimelineSettings = new TimelineSettings; |
44 | 47 | $wgTimelineSettings->ploticusCommand = "/usr/bin/ploticus"; |
— | — | @@ -107,6 +110,7 @@ |
108 | 111 | // Get command for ploticus to read the user input and output an error, |
109 | 112 | // map, and rendering (png or gif) file under the same dir as the temp file. |
110 | 113 | $cmdline = wfEscapeShellArg( $wgTimelineSettings->perlCommand, $wgTimelineSettings->timelineFile ) . |
| 114 | + ($wgTimelineSettings->svgOnly ? " -s " : "") . |
111 | 115 | " -i " . wfEscapeShellArg( $tmpPath ) . " -m -P " . wfEscapeShellArg( $wgTimelineSettings->ploticusCommand ) . |
112 | 116 | " -T " . wfEscapeShellArg( $wgTmpDirectory ) . " -A " . wfEscapeShellArg( $wgArticlePath ) . |
113 | 117 | " -f " . wfEscapeShellArg( $wgTimelineSettings->fontFile ); |
— | — | @@ -116,6 +120,34 @@ |
117 | 121 | $retVal = null; |
118 | 122 | $ret = wfShellExec( $cmdline, $retVal ); |
119 | 123 | |
| 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 | + |
120 | 152 | // Copy the output files into storage... |
121 | 153 | // @TODO: store error files in another container or not at all? |
122 | 154 | $opt = array( 'force' => 1, 'nonLocking' => 1, 'allowStale' => 1 ); // performance |