Index: trunk/extensions/Plotters/PlottersParser.php |
— | — | @@ -16,12 +16,13 @@ |
17 | 17 | |
18 | 18 | class PlottersParser { |
19 | 19 | |
| 20 | + var $arguments; |
20 | 21 | var $argumentArray; |
21 | 22 | var $dataArray; |
22 | 23 | |
23 | | - function PlottersParser( $input, $argv, &$parser ) { |
| 24 | + function PlottersParser( $input = "", $argv = Array() ) { |
24 | 25 | $this->parseArguments( $argv ); |
25 | | - $this->parseData( $input, $parser ); |
| 26 | + $this->parseData( $input ); |
26 | 27 | } |
27 | 28 | |
28 | 29 | function getArguments() { |
— | — | @@ -32,6 +33,10 @@ |
33 | 34 | return $this->dataArray; |
34 | 35 | } |
35 | 36 | |
| 37 | + function setData( $data ) { |
| 38 | + $this->dataArray = $data; |
| 39 | + } |
| 40 | + |
36 | 41 | function parseArguments( $argv ) { |
37 | 42 | // Parse arguments, set defaults, and do sanity checks |
38 | 43 | $this->argumentArray = array ( "renderer" => "generic", "preprocessors" => array(), "preprocessorarguments" => array(), |
— | — | @@ -127,7 +132,7 @@ |
128 | 133 | } |
129 | 134 | } |
130 | 135 | |
131 | | - function parseData( $input, $parser ) { |
| 136 | + function parseData( $input ) { |
132 | 137 | $this->dataArray = array(); |
133 | 138 | |
134 | 139 | Plotters::debug( 'plot script input: ', $this->argumentArray["scriptarguments"] ); |
Index: trunk/extensions/Plotters/Plotters.php |
— | — | @@ -48,6 +48,8 @@ |
49 | 49 | $wgAutoloadClasses['Plotters'] = $dir . 'PlottersClass.php'; |
50 | 50 | $wgAutoloadClasses['PlottersParser'] = $dir . 'PlottersParser.php'; |
51 | 51 | $wgAutoloadClasses['SpecialPlotters'] = $dir . 'SpecialPlotters.php'; |
| 52 | +$smwgResultFormats['plot'] = 'SRFPlotters'; |
| 53 | +$wgAutoloadClasses['SRFPlotters'] = $dir . 'SRF_Plotters.php'; |
52 | 54 | $wgSpecialPages['Plotters'] = 'SpecialPlotters'; |
53 | 55 | $wgSpecialPageGroups['Plotters'] = 'wiki'; |
54 | 56 | |
— | — | @@ -208,7 +210,7 @@ |
209 | 211 | } |
210 | 212 | |
211 | 213 | function initPlotters( $input, $argv, &$parser ) { |
212 | | - $pParser = new PlottersParser( $input, $argv, $parser ); |
| 214 | + $pParser = new PlottersParser( $input, $argv ); |
213 | 215 | $pPlotter = new Plotters( $pParser, $parser ); |
214 | 216 | |
215 | 217 | $pPlotter->checkForErrors(); |
— | — | @@ -226,11 +228,11 @@ |
227 | 229 | function PlottersParserOutput( &$outputPage, &$parserOutput ) { |
228 | 230 | if ( !empty( $parserOutput->mPlottersTag ) ) { |
229 | 231 | // Output required javascript |
230 | | - $genericname = "mplotter-generic"; |
231 | | - $plotkitname = "mplotter-plotkit"; |
232 | | - if ( !empty( $parserOutput->$genericname ) ) { |
| 232 | + $genericname = "generic"; |
| 233 | + $plotkitname = "plotkit"; |
| 234 | + if ( $parserOutput->mplotter["$genericname"] ) { |
233 | 235 | Plotters::setPlottersHeaders( $outputPage, 'generic' ); |
234 | | - } else if ( !empty( $parserOutput->$plotkitname ) ) { |
| 236 | + } else if ( $parserOutput->mplotter["$plotkitname"] ) { |
235 | 237 | Plotters::setPlottersHeaders( $outputPage, 'plotkit' ); |
236 | 238 | } |
237 | 239 | |
— | — | @@ -241,8 +243,8 @@ |
242 | 244 | $done = array(); |
243 | 245 | |
244 | 246 | foreach ( $plotters as $pname => $code ) { |
245 | | - $tname = strtolower( "mplotter-$pname" ); |
246 | | - if ( !empty( $parserOutput->$tname ) ) { |
| 247 | + $tname = strtolower( "$pname" ); |
| 248 | + if ( $parserOutput->mplotter["$tname"] ) { |
247 | 249 | wfApplyPlotterCode( $code, $outputPage, $done ); |
248 | 250 | } |
249 | 251 | } |
Index: trunk/extensions/Plotters/PlottersClass.php |
— | — | @@ -99,17 +99,17 @@ |
100 | 100 | $this->parser->mOutput->mPlottersTag = true; |
101 | 101 | |
102 | 102 | // Add renderer specific tag |
103 | | - $renderer = "mplotter-" . $this->argumentArray["renderer"]; |
104 | | - $this->parser->mOutput->$renderer = true; |
| 103 | + $renderer = $this->argumentArray["renderer"]; |
| 104 | + $this->parser->mOutput->mplotter["$renderer"] = true; |
105 | 105 | |
106 | 106 | // Add preprocessor tags |
107 | 107 | foreach ( $this->argumentArray["preprocessors"] as $preprocessor ) { |
108 | | - $preprocessor = "mplotter-" . $preprocessor; |
109 | | - $this->parser->mOutput->$preprocessor = true; |
| 108 | + $preprocessor = $preprocessor; |
| 109 | + $this->parser->mOutput->mplotter["$preprocessor"] = true; |
110 | 110 | } |
111 | 111 | |
112 | | - $script = "mplotter-" . $this->argumentArray["script"]; |
113 | | - $this->parser->mOutput->$script = true; |
| 112 | + $script = $this->argumentArray["script"]; |
| 113 | + $this->parser->mOutput->mplotter["$script"] = true; |
114 | 114 | |
115 | 115 | // output |
116 | 116 | return $output; |
Index: trunk/extensions/Plotters/SRF_Plotters.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A query printer using the Plotters extension |
| 5 | + * |
| 6 | + * @note AUTOLOADED |
| 7 | + * @author Ryan Lane |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Result printer to plot and process query results using admin installed javascript |
| 12 | + * |
| 13 | + * @ingroup SMWQuery |
| 14 | + */ |
| 15 | + |
| 16 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 17 | + die( 'Not an entry point.' ); |
| 18 | +} |
| 19 | + |
| 20 | +class SRFPlotters extends SMWResultPrinter { |
| 21 | + protected $pParser, $pPlotter; |
| 22 | + protected $params; |
| 23 | + |
| 24 | + protected function readParameters($params, $outputmode) { |
| 25 | + $this->params = $params; |
| 26 | + } |
| 27 | + |
| 28 | + public function getResult($results, $params, $outputmode) { |
| 29 | + $this->isHTML = false; |
| 30 | + $this->hasTemplates = false; |
| 31 | + |
| 32 | + // skip checks, results with 0 entries are normal |
| 33 | + $this->readParameters($params, $outputmode); |
| 34 | + return $this->getResultText($results, SMW_OUTPUT_HTML); |
| 35 | + } |
| 36 | + |
| 37 | + protected function getResultText($res, $outputmode) { |
| 38 | + global $wgParser; |
| 39 | + |
| 40 | + $dataArray = array(); |
| 41 | + while ( $row = $res->getNext() ) { |
| 42 | + $values = array(); |
| 43 | + foreach ($row as $i => $field) { |
| 44 | + while ( ($object = $field->getNextObject()) !== false ) { |
| 45 | + if ($object->getTypeID() == '_dat') { |
| 46 | + $values[] = SRFCalendar::formatDateStr($object); |
| 47 | + } elseif ($object->getTypeID() == '_wpg') { // use shorter "LongText" for wikipage |
| 48 | + $values[] = $object->getLongText($outputmode, NULL); |
| 49 | + } else { |
| 50 | + $values[] = $object->getShortText($outputmode, NULL); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + $dataArray[] = $values; |
| 55 | + } |
| 56 | + $pParser = new PlottersParser(); |
| 57 | + $pParser->setData( $dataArray ); |
| 58 | + $pParser->parseArguments( $this->params ); |
| 59 | + |
| 60 | + $pPlotter = new Plotters( $pParser, $wgParser ); |
| 61 | + |
| 62 | + $pPlotter->checkForErrors(); |
| 63 | + if ( $pPlotter->hasErrors() ) { |
| 64 | + $results = $pPlotter->getErrors(); |
| 65 | + } else { |
| 66 | + $results = $pPlotter->toHTML(); |
| 67 | + } |
| 68 | + if (is_null($wgParser->getTitle())) |
| 69 | + return $results; |
| 70 | + else |
| 71 | + return array($results, 'noparse' => 'true', 'isHTML' => 'true'); |
| 72 | + } |
| 73 | +} |
Property changes on: trunk/extensions/Plotters/SRF_Plotters.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 74 | + native |