r57583 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57582‎ | r57583 | r57584 >
Date:19:18, 9 October 2009
Author:laner
Status:deferred
Tags:
Comment:
* Cleaned up how javascript is conditionally aded
* Added SemanticMediawiki output format support (format=plot)
Modified paths:
  • /trunk/extensions/Plotters/Plotters.php (modified) (history)
  • /trunk/extensions/Plotters/PlottersClass.php (modified) (history)
  • /trunk/extensions/Plotters/PlottersParser.php (modified) (history)
  • /trunk/extensions/Plotters/SRF_Plotters.php (added) (history)

Diff [purge]

Index: trunk/extensions/Plotters/PlottersParser.php
@@ -16,12 +16,13 @@
1717
1818 class PlottersParser {
1919
 20+ var $arguments;
2021 var $argumentArray;
2122 var $dataArray;
2223
23 - function PlottersParser( $input, $argv, &$parser ) {
 24+ function PlottersParser( $input = "", $argv = Array() ) {
2425 $this->parseArguments( $argv );
25 - $this->parseData( $input, $parser );
 26+ $this->parseData( $input );
2627 }
2728
2829 function getArguments() {
@@ -32,6 +33,10 @@
3334 return $this->dataArray;
3435 }
3536
 37+ function setData( $data ) {
 38+ $this->dataArray = $data;
 39+ }
 40+
3641 function parseArguments( $argv ) {
3742 // Parse arguments, set defaults, and do sanity checks
3843 $this->argumentArray = array ( "renderer" => "generic", "preprocessors" => array(), "preprocessorarguments" => array(),
@@ -127,7 +132,7 @@
128133 }
129134 }
130135
131 - function parseData( $input, $parser ) {
 136+ function parseData( $input ) {
132137 $this->dataArray = array();
133138
134139 Plotters::debug( 'plot script input: ', $this->argumentArray["scriptarguments"] );
Index: trunk/extensions/Plotters/Plotters.php
@@ -48,6 +48,8 @@
4949 $wgAutoloadClasses['Plotters'] = $dir . 'PlottersClass.php';
5050 $wgAutoloadClasses['PlottersParser'] = $dir . 'PlottersParser.php';
5151 $wgAutoloadClasses['SpecialPlotters'] = $dir . 'SpecialPlotters.php';
 52+$smwgResultFormats['plot'] = 'SRFPlotters';
 53+$wgAutoloadClasses['SRFPlotters'] = $dir . 'SRF_Plotters.php';
5254 $wgSpecialPages['Plotters'] = 'SpecialPlotters';
5355 $wgSpecialPageGroups['Plotters'] = 'wiki';
5456
@@ -208,7 +210,7 @@
209211 }
210212
211213 function initPlotters( $input, $argv, &$parser ) {
212 - $pParser = new PlottersParser( $input, $argv, $parser );
 214+ $pParser = new PlottersParser( $input, $argv );
213215 $pPlotter = new Plotters( $pParser, $parser );
214216
215217 $pPlotter->checkForErrors();
@@ -226,11 +228,11 @@
227229 function PlottersParserOutput( &$outputPage, &$parserOutput ) {
228230 if ( !empty( $parserOutput->mPlottersTag ) ) {
229231 // 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"] ) {
233235 Plotters::setPlottersHeaders( $outputPage, 'generic' );
234 - } else if ( !empty( $parserOutput->$plotkitname ) ) {
 236+ } else if ( $parserOutput->mplotter["$plotkitname"] ) {
235237 Plotters::setPlottersHeaders( $outputPage, 'plotkit' );
236238 }
237239
@@ -241,8 +243,8 @@
242244 $done = array();
243245
244246 foreach ( $plotters as $pname => $code ) {
245 - $tname = strtolower( "mplotter-$pname" );
246 - if ( !empty( $parserOutput->$tname ) ) {
 247+ $tname = strtolower( "$pname" );
 248+ if ( $parserOutput->mplotter["$tname"] ) {
247249 wfApplyPlotterCode( $code, $outputPage, $done );
248250 }
249251 }
Index: trunk/extensions/Plotters/PlottersClass.php
@@ -99,17 +99,17 @@
100100 $this->parser->mOutput->mPlottersTag = true;
101101
102102 // 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;
105105
106106 // Add preprocessor tags
107107 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;
110110 }
111111
112 - $script = "mplotter-" . $this->argumentArray["script"];
113 - $this->parser->mOutput->$script = true;
 112+ $script = $this->argumentArray["script"];
 113+ $this->parser->mOutput->mplotter["$script"] = true;
114114
115115 // output
116116 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
174 + native

Status & tagging log