r92851 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92850‎ | r92851 | r92852 >
Date:07:13, 22 July 2011
Author:freakolowsky
Status:ok
Tags:
Comment:
* fixed errorhandling
* added table class with wikitable as default
Modified paths:
  • /trunk/extensions/SQL2Wiki/SQL2Wiki.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SQL2Wiki/SQL2Wiki.body.php
@@ -16,7 +16,7 @@
1717 private $mError = null;
1818
1919 private $ignoreAttributes = array( 'database', 'inline', 'fieldseparator', 'lineseparator', 'cache', 'expand', 'preexpand', 'quiet' );
20 - private $ignoteTabAttributes = array( 'tablestyle', 'hrowstyle', 'hcellstyle', 'rowstyle', 'cellstyle', 'style', 'noheader' );
 20+ private $ignoreTabAttributes = array( 'tableclass', 'tablestyle', 'hrowstyle', 'hcellstyle', 'rowstyle', 'cellstyle', 'style', 'noheader' );
2121
2222 public static function initTags( &$parser ) {
2323 $parser->setHook( "sql2wiki", "SQL2Wiki::renderSQL" );
@@ -30,7 +30,9 @@
3131
3232 $sql = ( $s2w->shouldPreexpand() ) ? $parser->recursiveTagParse( $input ) : $input;
3333
34 - $s2w->execute( $sql );
 34+ if ( !$s2w->execute( $sql ) ) {
 35+ return $s2w->mError;
 36+ }
3537
3638 if ( ( $inline = $s2w->getInlineTag() ) !== false )
3739 $ret = $s2w->parseInline();
@@ -56,7 +58,9 @@
5759
5860 $sql = ( $s2w->shouldPreexpand() ) ? $parser->recursiveTagParse( $input ) : $input;
5961
60 - $s2w->execute( $sql );
 62+ if ( !$s2w->execute( $sql ) ) {
 63+ return $s2w->mError;
 64+ }
6165
6266 $ret = $s2w->parseInline();
6367
@@ -71,7 +75,7 @@
7276
7377 public function __construct( $args, $PLSQLMode = false ) {
7478 global $wgExSql2WikiDatabases;
75 -
 79+
7680 $this->mArgs = $args;
7781 $this->mPLSQLMode = $PLSQLMode;
7882
@@ -129,22 +133,18 @@
130134
131135 public function execute( $sql ) {
132136
133 - $ignore = $this->mDB->ignoreErrors( true );
134137 $this->initDBMSOutput();
135 -
136 - $this->mResult = $this->mDB->query( $sql );
137138
138 - $this->getDBMSOutput();
139 - $this->mDB->ignoreErrors( $ignore );
140 -
141 - if ( $this->mDB->lastError() != null ) {
142 - if ( ( isset( $this->mArgs["quiet"] ) && $this->mArgs["quiet"] == 'true' ) ) {
143 - $this->mError = wfMsgForContent( 'sql2wiki-err-failed_to_execute', $sql, $this->mDB->lastError() );
 139+ try {
 140+ $this->mResult = $this->mDB->query( $sql, 'SQL2Wiki::execute', true );
 141+ $this->getDBMSOutput();
 142+ } catch (DBQueryError $ex) {
 143+ if ( !( isset( $this->mArgs["quiet"] ) && $this->mArgs["quiet"] == 'true' ) ) {
 144+ $this->mError = wfMsgForContent( 'sql2wiki-err-failed_to_execute', $sql, $ex->error );
144145 }
 146+ return false;
 147+ }
145148
146 - return false;
147 - }
148 -
149149 return true;
150150 }
151151
@@ -233,11 +233,12 @@
234234 return '';
235235 }
236236
 237+ $tableClass = isset( $this->mArgs["tableclass"] ) ? $this->mArgs["tableclass"] : 'wikitable';
237238 $tableStyle = isset( $this->mArgs["tablestyle"] ) ? $this->mArgs["tablestyle"] : 'border: black solid 1px;';
238239
239 - $attributes = array_diff_key( $this->mArgs, array_flip( $this->ignoreAttributes ), array_flip( $this->ignoteTabAttributes ) );
 240+ $attributes = array_diff_key( $this->mArgs, array_flip( $this->ignoreAttributes ), array_flip( $this->ignoreTabAttributes ) );
240241
241 - $output = Xml::openElement( 'table', array_merge( $attributes, array( 'style' => $tableStyle ) ) );
 242+ $output = Xml::openElement( 'table', array_merge( $attributes, array( 'style' => $tableStyle, 'class' => $tableClass ) ) );
242243
243244 if ( !isset( $this->mArgs["noheader"] ) || $this->mArgs["noheader"] != 'true' ) {
244245 $headerRowStyle = isset( $this->mArgs["hrowstyle"] ) ? $this->mArgs["hrow_style"] : '';

Status & tagging log