r50633 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50632‎ | r50633 | r50634 >
Date:16:38, 15 May 2009
Author:laner
Status:deferred
Tags:
Comment:
* Added support for helpers
* Added some more error checking
Modified paths:
  • /trunk/extensions/Plotters/Plotters.i18n.php (modified) (history)
  • /trunk/extensions/Plotters/Plotters.php (modified) (history)
  • /trunk/extensions/Plotters/PlottersClass.php (modified) (history)
  • /trunk/extensions/Plotters/PlottersParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Plotters/PlottersParser.php
@@ -35,7 +35,8 @@
3636 function parseArguments( $argv ) {
3737 // Parse arguments, set defaults, and do sanity checks
3838 $this->argumentArray = array ( "renderer" => "plotkit", "preprocessors" => array(), "preprocessorarguments" => array(),
39 - "script" => "", "scriptarguments" => array(), "datasep" => ",", "width" => "300", "height" => "300", "labels" => array() );
 39+ "script" => "", "scriptarguments" => array(), "datasep" => ",", "width" => "300", "height" => "300", "labels" => array(),
 40+ "helpers" => array() );
4041 if ( isset( $argv["renderer"] ) ) {
4142 //TODO: limit this to supported renderers
4243 $this->argumentArray["renderer"] = preg_replace( '/[^A-Z0-9]/i', '', $argv["renderer"] );
@@ -106,6 +107,13 @@
107108 $this->argumentArray["labels"][] = $label;
108109 }
109110 }
 111+ if ( isset( $argv["helpers"] ) ) {
 112+ // Sanitize scripts - alphanumerics only
 113+ $this->argumentArray["helpers"] = explode( ',', $argv["helpers"] );
 114+ foreach ( $this->argumentArray["helpers"] as &$helper ) {
 115+ $helper = preg_replace( '/[^A-Z0-9]/i', '', $helper );
 116+ }
 117+ }
110118 }
111119
112120 function parseData( $input, $parser ) {
Index: trunk/extensions/Plotters/Plotters.i18n.php
@@ -24,7 +24,10 @@
2525 This overview provides easy access to the system message pages that define each plotter's description and code.",
2626 'plotters-uses' => 'Uses',
2727 'plotters-missing-script' => 'No script was defined.',
 28+ 'plotters-missing-arguments' => 'No arguments specified.',
2829 'plotters-excessively-long-scriptname' => 'The script name is too long. Please define a script that is less than 255 characters.',
 30+ 'plotters-excessively-long-preprocessorname' => 'The preprocessor name is too long. Please define a preprocessor that is less than 255 characters.',
 31+ 'plotters-excessively-long-helpername' => 'The helper name is too long. Please define a helper that is less than 255 characters.',
2932 'plotters-no-data' => 'No data was provided.',
3033 'plotters-invalid-renderer' => 'An invalid renderer was selected.',
3134 'plotters-errors' => '<b>Plotters error(s):</b>',
Index: trunk/extensions/Plotters/Plotters.php
@@ -169,7 +169,8 @@
170170 function initPlottersPF( &$parser ) {
171171 $numargs = func_num_args();
172172 if ( $numargs < 2 ) {
173 - $input = "#Plotters: no arguments specified";
 173+ wfLoadExtensionMessages( 'Plotters' );
 174+ $input = wfMsg( "plotters-errors" ) . " " . wfMsg( "plotters-missing-arguments" );
174175 return str_replace( '§', '<', '§pre>§nowiki>' . $input . '§/nowiki>§/pre>' );
175176 }
176177
Index: trunk/extensions/Plotters/PlottersClass.php
@@ -51,6 +51,17 @@
5252 // Check to ensure scriptname is < 255 characters
5353 $errors .= wfMsg( "plotters-excessively-long-scriptname" ) . "<br />";
5454 }
 55+ // Check preprocessors and helpers
 56+ foreach ( $this->argumentArray["preprocessors"] as $preprocessor ) {
 57+ if ( strlen( $preprocessor ) > 255 ) {
 58+ $errors .= wfMsg( "plotters-excessively-long-preprocessorname" ) . "<br />";
 59+ }
 60+ }
 61+ foreach ( $this->argumentArray["helpers"] as $helper ) {
 62+ if ( strlen( $helper ) > 255 ) {
 63+ $errors .= wfMsg( "plotters-excessively-long-helpername" ) . "<br />";
 64+ }
 65+ }
5566 // Check for data
5667 if ( count( $this->dataArray ) == 0 ) {
5768 $errors .= wfMsg( "plotters-no-data" ) . "<br />";
@@ -78,10 +89,15 @@
7990 $renderer = "mplotter-" . $this->argumentArray["renderer"];
8091 $this->parser->mOutput->$renderer = true;
8192
 93+ // Add preprocessor and helper tags
8294 foreach ( $this->argumentArray["preprocessors"] as $preprocessor ) {
8395 $preprocessor = "mplotter-" . $preprocessor;
8496 $this->parser->mOutput->$preprocessor = true;
8597 }
 98+ foreach ( $this->argumentArray["helpers"] as $helper ) {
 99+ $helper = "mplotter-" . $helper;
 100+ $this->parser->mOutput->$helper = true;
 101+ }
86102
87103 $script = "mplotter-" . $this->argumentArray["script"];
88104 $this->parser->mOutput->$script = true;

Status & tagging log