r89153 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89152‎ | r89153 | r89154 >
Date:07:37, 30 May 2011
Author:freakolowsky
Status:deferred (Comments)
Tags:
Comment:
* Initial commit
Modified paths:
  • /trunk/extensions/SQL2Wiki (added) (history)
  • /trunk/extensions/SQL2Wiki/SQL2Wiki.body.php (added) (history)
  • /trunk/extensions/SQL2Wiki/SQL2Wiki.i18n.php (added) (history)
  • /trunk/extensions/SQL2Wiki/SQL2Wiki.php (added) (history)
  • /trunk/extensions/SQL2Wiki/SQL2Wiki.php~ (added) (history)
  • /trunk/extensions/SQL2Wiki/SpecialSQL2Wiki.php (added) (history)

Diff [purge]

Index: trunk/extensions/SQL2Wiki/SQL2Wiki.body.php
@@ -0,0 +1,270 @@
 2+<?php
 3+
 4+class SQL2Wiki {
 5+
 6+ private $mDB;
 7+ private $mDBType;
 8+
 9+ private $mDBMSOutput;
 10+
 11+ private $mArgs;
 12+ private $mPLSQLMode;
 13+ private $mInlineTag = null;
 14+
 15+ private $mResult = null;
 16+ private $mOutput = null;
 17+ private $mError = null;
 18+
 19+ private $ignoreAttributes = array( 'database', 'inline', 'fieldseparator', 'lineseparator', 'cache', 'expand', 'preexpand', 'quiet' );
 20+ private $ignoteTabAttributes = array( 'tablestyle', 'hrowstyle', 'hcellstyle', 'rowstyle', 'cellstyle', 'style', 'noheader' );
 21+
 22+ public static function initTags( &$parser ) {
 23+ $parser->setHook( "sql2wiki", "SQL2Wiki::renderSQL" );
 24+ $parser->setHook( "plsql2wiki", "SQL2Wiki::renderPLSQL" );
 25+ return false;
 26+ }
 27+
 28+ public static function renderSQL( $input, $args, $parser, $frame ) {
 29+ try {
 30+ $s2w = new SQL2Wiki( $args );
 31+
 32+ $sql = ( $s2w->shouldPreexpand() ) ? $parser->recursiveTagParse( $input ) : $input;
 33+
 34+ $s2w->execute( $sql );
 35+
 36+ if ( ( $inline = $s2w->getInlineTag() ) !== false )
 37+ $ret = $s2w->parseInline();
 38+ else
 39+ $ret = $s2w->parseTable();
 40+
 41+ $ret = ( $s2w->shouldExpand() ) ? $parser->recursiveTagParse( $ret ) : $ret;
 42+ $ret .= $s2w->handleCache( $parser );
 43+
 44+ return $ret;
 45+ } catch ( Exception $ex ) {
 46+ return $ex->getMessage();
 47+ }
 48+ }
 49+
 50+ public static function renderPLSQL( $input, $args, $parser, $frame ) {
 51+ try {
 52+ $s2w = new SQL2Wiki( $args, true );
 53+
 54+ if ( !$s2w->isPLSQLSupported() ) {
 55+ return wfMsgForContent( 'sql2wiki-err-feature_not_supported', $s2w->getDBType() );
 56+ }
 57+
 58+ $sql = ( $s2w->shouldPreexpand() ) ? $parser->recursiveTagParse( $input ) : $input;
 59+
 60+ $s2w->execute( $sql );
 61+
 62+ $ret = $s2w->parseInline();
 63+
 64+ $ret = ( $s2w->shouldExpand() ) ? $parser->recursiveTagParse( $ret ) : $ret;
 65+ $ret .= $s2w->handleCache( $parser );
 66+
 67+ return $ret;
 68+ } catch ( Exception $ex ) {
 69+ return $ex->getMessage();
 70+ }
 71+ }
 72+
 73+ public function __construct( $args, $PLSQLMode = false ) {
 74+ global $wgExSql2WikiDatabases;
 75+
 76+ $this->mArgs = $args;
 77+ $this->mPLSQLMode = $PLSQLMode;
 78+
 79+ if ( !isset( $this->mArgs["database"] ) || !isset( $wgExSql2WikiDatabases[$this->mArgs["database"]] ) )
 80+ throw new Exception( wfMsgForContent( 'sql2wiki-err-invalid_db_id' ) );
 81+
 82+ $db = $wgExSql2WikiDatabases[$this->mArgs["database"]];
 83+ $this->mDBType = $db['type'];
 84+ $this->mDB = Database::newFromType( $this->mDBType, $db );
 85+
 86+ if ( !$this->mDB->isOpen() ) {
 87+ throw new Exception( wfMsgForContent( 'sql2wiki-err-failed_to_connect', $this->mArgs["database"] ) );
 88+
 89+ }
 90+ }
 91+
 92+ public function isPLSQLSupported() {
 93+ return ($this->mDBType == 'oracle');
 94+ }
 95+
 96+ public function isDBMSOutputSupported() {
 97+ return ($this->mDBType == 'oracle');
 98+ }
 99+
 100+ public function shouldPreexpand() {
 101+ return ( isset( $this->mArgs["preexpand"] ) && $this->mArgs["preexpand"] == 'true' );
 102+ }
 103+
 104+ public function shouldExpand() {
 105+ return ( isset( $this->mArgs["expand"] ) && $this->mArgs["expand"] == 'true' );
 106+ }
 107+
 108+ public function getInlineTag() {
 109+ if ( $this->mInlineTag == null ) {
 110+ $this->mInlineTag = ( isset( $this->mArgs["inline"] ) )
 111+ ? $this->mArgs["inline"]
 112+ : ( $this->mPLSQLMode ? 'span' : false ) ;
 113+ }
 114+ return $this->mInlineTag;
 115+ }
 116+
 117+ public function getDBType() {
 118+ return $this->mDBType;
 119+ }
 120+
 121+ public function execute( $sql ) {
 122+
 123+ $ignore = $this->mDB->ignoreErrors( true );
 124+ $this->initDBMSOutput();
 125+
 126+ $this->mResult = $this->mDB->doQuery( $sql );
 127+
 128+ $this->getDBMSOutput();
 129+ $this->mDB->ignoreErrors( $ignore );
 130+
 131+ if ( $this->mDB->lastError() != null ) {
 132+ if ( ( isset( $this->mArgs["quiet"] ) && $this->mArgs["quiet"] == 'true' ) ) {
 133+ $this->mError = wfMsgForContent( 'sql2wiki-err-failed_to_execute', $sql, $this->mDB->lastError() );
 134+ }
 135+
 136+ return false;
 137+ }
 138+
 139+ return true;
 140+ }
 141+
 142+ public function handleCache ( $parser ) {
 143+ $cache = isset( $this->mArgs["cache"] ) ? $this->mArgs["cache"] : 'on';
 144+
 145+ if ( $cache == 'off') {
 146+ $parser->disableCache();
 147+ } elseif ( $cache == 'manual' && ($this->mPLSQLMode || $this->getInlineTag() === false) ) {
 148+ return '<br />'.
 149+ Xml::openElement( 'a',
 150+ array( 'href' => $parser->getTitle()->getLocalURL( array( 'action' => 'purge' ) ) ) ).
 151+ Xml::element( 'small', null, wfMsgForContent( 'sql2wiki-cache_refresh' ) ).
 152+ Xml::closeElement( 'a' );
 153+ }
 154+
 155+ return '';
 156+ }
 157+
 158+ private function initDBMSOutput() {
 159+ if ( !$this->isDBMSOutputSupported() ) {
 160+ $this->mDBMSOutput = false;
 161+ return;
 162+ }
 163+
 164+ $this->mDbmsOutput = ( isset( $this->mArgs["dbmsoutput"] ) && $this->mArgs["dbmsoutput"] == 'true' );
 165+ if ($this->mDBMSOutput) {
 166+ $this->enableDBMSOutput();
 167+ }
 168+ }
 169+
 170+ private function enableDBMSOutput() {
 171+ if ( !$this->isDBMSOutputSupported() ) {
 172+ return;
 173+ }
 174+
 175+ $this->mDB->doQuery ('BEGIN dbms_output.enable(null); END;');
 176+ }
 177+
 178+ private function disableDBMSOutput() {
 179+ if ( !$this->isDBMSOutputSupported() ) {
 180+ return;
 181+ }
 182+
 183+ $this->mDB->doQuery ('BEGIN dbms_output.disable; END;');
 184+ }
 185+
 186+ private function getDBMSOutput() {
 187+ if ( !$this->mDBMSOutput ) {
 188+ return false;
 189+ }
 190+
 191+ $this->mOutput = array();
 192+
 193+ $ret = $dbObj->doQuery('SELECT column_value FROM TABLE(get_output_lines())');
 194+ while(($line = $ret->fetchObject()) !== FALSE) {
 195+ $this->mOutput[] = $line->column_value;
 196+ }
 197+ }
 198+
 199+ private function parseInline() {
 200+ $fieldSeparator = isset( $this->mArgs["fieldseparator"] ) ? $this->mArgs["fieldseparator"] : '';
 201+ $lineSeparator = isset( $this->mArgs["lineseparator"] ) ? $this->mArgs["lineseparator"] : '';
 202+
 203+ $output = '';
 204+ while ( ($line = $this->mResult->fetchObject() ) !== FALSE) {
 205+ if ( $output != '' ) {
 206+ $output .= $lineSeparator."\n";
 207+ }
 208+
 209+ foreach ( $line as $value ){
 210+ $output .= $value.$fieldSeparator;
 211+ }
 212+ $output = substr( $output, 0, strlen( $output )-strlen( $fieldSeparator ) );
 213+ }
 214+
 215+ $attributes = array_diff_key( $this->mArgs, array_flip( $this->ignoreAttributes ) );
 216+ return Xml::openElement( $this->getInlineTag(), $attributes).
 217+ $output.
 218+ Xml::closeElement( $this->getInlineTag() );
 219+ }
 220+
 221+ private function parseTable() {
 222+ $line = $this->mResult->fetchObject();
 223+ if ( $line === false ) {
 224+ return '';
 225+ }
 226+
 227+ $tableStyle = isset( $this->mArgs["tablestyle"] ) ? $this->mArgs["tablestyle"] : 'border: black solid 1px;';
 228+
 229+ $attributes = array_diff_key( $this->mArgs, array_flip( $this->ignoreAttributes ), array_flip( $this->ignoteTabAttributes ) );
 230+
 231+ $output = Xml::openElement( 'table', array_merge( $attributes, array( 'style' => $tableStyle ) ) );
 232+
 233+ if ( !isset( $this->mArgs["noheader"] ) || $this->mArgs["noheader"] != 'true' ) {
 234+ $headerRowStyle = isset( $this->mArgs["hrowstyle"] ) ? $this->mArgs["hrow_style"] : '';
 235+ $headerCellStyle = isset( $this->mArgs["hcellstyle"] ) ? $this->mArgs["hcellstyle"] : 'font-weight: bold;';
 236+ $headerCellStyle = array_merge( $attributes, array( 'style' => $headerCellStyle ) );
 237+
 238+ $output .= Xml::openElement( 'tr', array_merge( $attributes, array( 'style' => $headerRowStyle ) ) );
 239+
 240+ foreach ( $line as $key=>$value ) {
 241+ $output .= Xml::openElement( 'th', $headerCellStyle ).
 242+ $key.
 243+ Xml::closeElement( 'th' );
 244+ }
 245+
 246+ $output .= Xml::closeElement( 'tr' );
 247+ }
 248+
 249+ $rowStyle = isset( $this->mArgs["rowstyle"] ) ? $this->mArgs["rowstyle"] : '';
 250+ $cellStyle = isset( $this->mArgs["cellstyle"] ) ? $this->mArgs["cellstyle"] : '';
 251+ $cellStyle = array_merge( $attributes, array( 'style' => $cellStyle ) );
 252+
 253+ do {
 254+ $output .= Xml::openElement( 'tr', array_merge( $attributes, array( 'style' => $rowStyle ) ) );
 255+
 256+ foreach ( $line as $key=>$value ) {
 257+ $output .= Xml::openElement( 'td', $cellStyle ).
 258+ $value.
 259+ Xml::closeElement( 'td' );
 260+ }
 261+
 262+ $output .= Xml::closeElement( 'tr' );
 263+ } while ( ( $line = $this->mResult->fetchObject() ) !== false );
 264+
 265+
 266+ $output .= Xml::closeElement( 'table' );
 267+
 268+ return $output;
 269+ }
 270+
 271+}
Property changes on: trunk/extensions/SQL2Wiki/SQL2Wiki.body.php
___________________________________________________________________
Added: svn:eol-style
1272 + native
Index: trunk/extensions/SQL2Wiki/SQL2Wiki.i18n.php
@@ -0,0 +1,17 @@
 2+<?php
 3+$messages = array();
 4+
 5+$messages['en'] = array(
 6+ 'sql2wiki' => 'SQL2Wiki',
 7+ 'sql2wiki-desc' => 'Show SQL data directly in the page contents.',
 8+
 9+ 'sql2wiki-cache_refresh' => 'Refresh',
 10+
 11+ 'sql2wiki-err-invalid_db_id' => 'SQL2Wiki: Missing or invalid database ID',
 12+ 'sql2wiki-err-invalid_type' => 'SQL2Wiki: Missing or invalid type',
 13+ 'sql2wiki-err-failed_to_connect' => 'SQL2Wiki: Failed to connect to $1!',
 14+ 'sql2wiki-err-failed_to_execute' => 'SQL2Wiki: Failed to execute the statement:<br /> "$1" <br />with error message: "$2"!',
 15+ 'sql2wiki-err-feature_not_supported' => 'SQL2Wiki: Feature is not supported by databases of type $1!',
 16+);
 17+
 18+?>
Property changes on: trunk/extensions/SQL2Wiki/SQL2Wiki.i18n.php
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/extensions/SQL2Wiki/SQL2Wiki.php~
@@ -0,0 +1,260 @@
 2+<?php
 3+
 4+if (!defined('MEDIAWIKI')) die();
 5+
 6+$wgExtensionCredits['parserhook'][] = array(
 7+ 'name' => 'SQL2Wiki',
 8+ 'author' => 'Patrick M�ller (Jure Kajzer - Oracle port)',
 9+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SQL2Wiki',
 10+ 'description' => 'This is modified Oracle version of this extension',
 11+ 'descriptionmsg' => 'sql2wiki-oracle_mod',
 12+ 'version' => '0.0.1',
 13+);
 14+
 15+$wgExtensionCredits['specialpage'][] = array(
 16+ 'name' => 'SQL2Wiki',
 17+ 'author' => 'Jure Kajzer',
 18+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SQL2Wiki',
 19+ 'description' => 'Run SQL2Wiki code on-click',
 20+ 'descriptionmsg' => 'sql2wiki-special',
 21+ 'version' => '0.0.1',
 22+);
 23+
 24+$wgExtensionFunctions[] = "wfSQL2Wiki";
 25+
 26+$dir = dirname(__FILE__) . '/';
 27+$wgAutoloadClasses['sql2wiki'] = $dir . 'SQL2Wiki_body.php';
 28+$wgExtensionMessagesFiles['sql2wiki'] = $dir . 'SQL2Wiki.i18n.php';
 29+$wgSpecialPages['sql2wiki'] = 'SQL2Wiki';
 30+
 31+$sql2wiki_DB_handles = array(
 32+ "orac" => "orac.abakus.si;abakus_wiki;abakus_wiki",
 33+ "abakus" => "abakus.abakus.si;abakus_wiki;abakus_wiki",
 34+ "ipa" => "abakus.abakus.si;ipa_wiki;ipa_wiki");
 35+
 36+require_once($dir . 'SQL2Wiki_body.php');
 37+
 38+$wgOracleDBMSEnabled = false;
 39+
 40+function SQL2Wiki_enableDBMSOutput($dbObj, $state = true) {
 41+ global $wgOracleDBMSEnabled;
 42+ $wgOracleDBMSEnabled = $state;
 43+ if ($state)
 44+ $dbObj->doQuery ('begin dbms_output.enable(null); end;');
 45+ else
 46+ $dbObj->doQuery ('begin dbms_output.disable; end;');
 47+}
 48+
 49+function SQL2Wiki_getDBMSOutput($dbObj) {
 50+ global $wgOracleDBMSEnabled;
 51+
 52+ if ($wgOracleDBMSEnabled === false)
 53+ return false;
 54+
 55+ $out = array();
 56+ $qReturn = null;
 57+ $wdc = 0;
 58+ $qReturn = $dbObj->doQuery('select column_value from table(get_output_lines())');
 59+ while(($qLine = $qReturn->fetchObject()) !== FALSE) {
 60+ $out[] = $qLine->column_value;
 61+ }
 62+
 63+ return $out;
 64+}
 65+
 66+function wfSQL2Wiki() {
 67+ global $wgParser;
 68+ $wgParser->setHook( "sql2wiki", "renderSQL" );
 69+ $wgParser->setHook( "plsql2wiki", "renderPLSQL" );
 70+}
 71+
 72+function SQL2Wiki_execute($db,$input,$enable_output,&$dbObj,&$result,&$output,&$error){
 73+ global $wgDBtype;
 74+ global $sql2wiki_DB_handles;
 75+
 76+ reset ($sql2wiki_DB_handles);
 77+ $bFound = false;
 78+ while(list($index,$val)=each($sql2wiki_DB_handles)) {
 79+ if ( $db == $index ) {
 80+ $aParams = explode(";", $val);
 81+
 82+ foreach($aParams as $parameter) {
 83+ if( count( $aParams ) < 3 ){
 84+ $error="Error in DB_handler definition !";
 85+ return false;
 86+ }
 87+ $host = trim($aParams[0]);
 88+ $user = trim($aParams[1]);
 89+ $pass = trim($aParams[2]);
 90+ $charset = trim($aParams[3]);
 91+ $bFound = true;
 92+ }
 93+ }
 94+ }
 95+ if ( !$bFound ){
 96+ $error="Error in DB_handler definition !";
 97+ return false;
 98+ }
 99+
 100+ $dbObj = new DatabaseOracle($db, $user, $pass, $host, false, 128);
 101+ if (!$dbObj->isOpen()){
 102+ $error='<b>SQL2Wiki failed to connect to DB &quot;'.$db.'&quot;</b>';
 103+ return false;
 104+ }
 105+
 106+ $ignore = $dbObj->ignoreErrors(true);
 107+
 108+ SQL2Wiki_enableDBMSOutput($dbObj, $enable_output);
 109+
 110+ $result = $dbObj->doQuery ($input);
 111+
 112+ $output='';
 113+ if ($enable_output){
 114+ $output = implode(SQL2Wiki_getDBMSOutput($dbObj), "\n");
 115+ if ($output === false){
 116+ $error='<b>SQL2Wiki completed successfully</b>';
 117+ return false;
 118+ }
 119+ }
 120+
 121+ $dbObj->ignoreErrors($ignore);
 122+
 123+ if ($dbObj->lastError() != null){
 124+ $error='<b>SQL2Wiki exited with error: '.$dbObj->lastError().' '.$input.'</b>';
 125+ return false;
 126+ }
 127+ elseif (isset($argv["quiet"])){
 128+ $error='';
 129+ return false;
 130+ }
 131+
 132+ return true;
 133+}
 134+
 135+
 136+function renderSQL( $input, $argv, &$parser ) {
 137+ global $wgOut;
 138+
 139+ $db = $argv["database"];
 140+
 141+ if (isset($argv["preexpand"]) && $argv["preexpand"] == 'true') {
 142+ $input = $parser->recursiveTagParse($input);
 143+ }
 144+
 145+ if (!SQL2Wiki_execute($db,$input,false,$dbObj,$result,$output,$error))
 146+ return $error;
 147+
 148+ if (isset($argv["inline"])) {
 149+ $field_separator = isset($argv["fieldseparator"]) ? $argv["fieldseparator"] : '';
 150+ $line_separator = isset($argv["lineseparator"]) ? $argv["lineseparator"] : '';
 151+
 152+ while (($line = $result->fetchObject()) !== FALSE) {
 153+ if ($output != '')
 154+ $output .= $line_separator."\n";
 155+
 156+ foreach ($line as $value){
 157+ $output .= $value.$field_separator;
 158+ }
 159+ $output = substr($output, 0, strlen($output)-strlen($field_separator));
 160+ }
 161+
 162+ if ($argv["inline"] != '') {
 163+ $other_params = '';
 164+ foreach($argv as $key=>$value)
 165+ if (!in_array($key, array('database', 'inline', 'fieldseparator', 'lineseparator', 'cache', 'expand', 'preexpand')))
 166+ $other_params .= ' '.$key.'="'.trim($value, '"').'"';
 167+ $output = '<'.$argv["inline"].$other_params.'>'.$output.'</'.$argv["inline"].'>';
 168+ }
 169+ } else {
 170+ $table_style = isset($argv["tablestyle"]) ? ' style="'.$argv["tablestyle"].'" ' : ' style="border: black solid 1px;" ';
 171+ $h_row_style = isset($argv["hrowstyle"]) ? ' style="'.$argv["hrow_style"].'" ' : '';
 172+ $h_cell_style = isset($argv["hcellstyle"]) ? ' style="'.$argv["hcellstyle"].'" ' : ' style="font-weight: bold;" ';
 173+ $row_style = isset($argv["rowstyle"]) ? ' style="'.$argv["rowstyle"].'" ' : '';
 174+ $cell_style = isset($argv["cellstyle"]) ? ' style="'.$argv["cellstyle"].'" ' : '';
 175+
 176+ # Create Table Header
 177+ $output .= '<table border=1 cellspacing=0 cellpadding=3'.$table_style.'>';
 178+ $output .= '<tr'.$h_row_style.'>';
 179+ $line = $result->fetchObject();
 180+ foreach ($line as $key=>$value) {
 181+ $output .= '<th'.$h_cell_style.'>'.$key.'</th>';
 182+ }
 183+ $output .= '</tr>';
 184+
 185+ # Create Table Data Rows
 186+ do {
 187+ $output .= '<tr'.$row_style.'>';
 188+ foreach ($line as $value){
 189+ $output .= '<td'.$cell_style.'>'.$value.'</td>';
 190+
 191+ }
 192+ $output .= '</tr>';
 193+ } while (($line = $result->fetchObject()) !== FALSE);
 194+ # End of Table Tag
 195+ $output .= '</table>';
 196+ }
 197+
 198+
 199+ if (isset($argv["cache"]) && $argv["cache"] == 'off') {
 200+ $parser->disableCache();
 201+ } elseif (isset($argv["cache"]) && $argv["cache"] == 'manual') {
 202+ if (!isset($argv["inline"])) {
 203+ $refresh_url = preg_replace('/(.*?)&action=[^&]*(.*)/i', '$1$2', $_SERVER['REQUEST_URI']).
 204+ '&action=purge';
 205+ $output .= '<a href="'.$refresh_url.'"><small>Refresh</small></a>';
 206+ }
 207+ } elseif (isset($argv["inline"])) {
 208+ $parser->disableCache();
 209+ }
 210+
 211+ if ($wgOut->getPageTitle() != 'SQL2Wiki' && isset($argv["expand"]) && $argv["expand"] == 'true') {
 212+wfDebug(strlen($output)." ---------------------\n$output\n\n\n");
 213+ $output = $parser->recursiveTagParse($output);
 214+wfDebug(strlen($output)." ---------------------\n");
 215+ }
 216+
 217+ @$dbObj->close();
 218+ return $output;
 219+}
 220+
 221+function renderPLSQL( $input, $argv, &$parser ) {
 222+ global $wgDBtype;
 223+ global $wgOut;
 224+
 225+ $db = $argv["database"];
 226+
 227+ if (strtolower($wgDBtype) != 'oracle' && strtolower($wgDBtype) != 'oracless')
 228+ return '<b>This function is available only for Oracle and OracleSS DB class.</b>';
 229+
 230+ $dbms_output = isset($argv["dbmsoutput"]) ? $argv["dbmsoutput"] : false;
 231+
 232+ if (isset($argv["preexpand"]) && $argv["preexpand"] == 'true') {
 233+ $input = $parser->recursiveTagParse($input);
 234+ }
 235+
 236+ if (!SQL2Wiki_execute($db,$input,$dbms_output,$dbObj,$result,$output,$error))
 237+ return $error;
 238+
 239+ $wrapper = isset($argv["wrapper"]) ? $argv["wrapper"] : '';
 240+ if ($wrapper != '') {
 241+ $other_params = '';
 242+ foreach($argv as $key=>$value)
 243+ if (!in_array($key, array('database', 'wrapper', 'quiet', 'cache', 'expand', 'preexpand', 'dbmsoutput')))
 244+ $other_params .= ' '.$key.'="'.trim($value, '"').'"';
 245+
 246+ $output = '<'.$wrapper.$other_params.'>'.$output.'</'.$wrapper.'>';
 247+ }
 248+
 249+ if (!isset($argv["cache"]) || $argv["cache"] != 'on') {
 250+ $parser->disableCache();
 251+ }
 252+
 253+ if ($wgOut->getPageTitle() != 'SQL2Wiki' && isset($argv["expand"]) && $argv["expand"] == 'true' ) {
 254+ $output = $parser->recursiveTagParse($output);
 255+ }
 256+
 257+ @$dbObj->close();
 258+ return $output;
 259+}
 260+
 261+?>
Index: trunk/extensions/SQL2Wiki/SQL2Wiki.php
@@ -0,0 +1,283 @@
 2+<?php
 3+# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
 4+if (!defined('MEDIAWIKI')) {
 5+ echo <<<EOT
 6+To install this extension put the following line in LocalSettings.php:
 7+require_once( "\$IP/extensions/SQL2Wiki/SQL2Wiki.php" );
 8+EOT;
 9+ exit( 1 );
 10+}
 11+$wgExtensionCredits['parserhook'][] = array(
 12+ 'name' => 'SQL2Wiki',
 13+ 'author' => 'freakolowsky [Jure Kajzer] original version by Patrick M�ller',
 14+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SQL2Wiki',
 15+ 'description' => 'Show SQL data directly in the page contents..',
 16+ 'descriptionmsg' => 'sql2wiki-desc',
 17+ 'version' => '1.0.0',
 18+);
 19+
 20+$wgExtensionCredits['specialpage'][] = array(
 21+ 'name' => 'SQL2Wiki',
 22+ 'author' => 'Jure Kajzer',
 23+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SQL2Wiki',
 24+ 'description' => 'Run SQL2Wiki code on-click',
 25+ 'descriptionmsg' => 'sql2wiki-special',
 26+ 'version' => '1.0.0',
 27+);
 28+
 29+$dir = dirname(__FILE__) . '/';
 30+$wgExtensionMessagesFiles['SQL2Wiki'] = $dir . 'SQL2Wiki.i18n.php';
 31+
 32+$wgAutoloadClasses['SQL2Wiki'] = $dir . 'SQL2Wiki.body.php';
 33+$wgHooks['ParserFirstCallInit'][] = 'SQL2Wiki::initTags';
 34+
 35+$wgAutoloadClasses['SpecialSQL2Wiki'] = $dir . 'SpecialSQL2Wiki.php';
 36+$wgSpecialPages['SQL2Wiki'] = 'SpecialSQL2Wiki';
 37+
 38+
 39+// list of database contact data
 40+$wgExSql2WikiDatabases = array();
 41+
 42+
 43+
 44+/*
 45+
 46+
 47+
 48+
 49+
 50+
 51+
 52+
 53+$wgExtensionFunctions[] = "wfSQL2Wiki";
 54+
 55+$wgAutoloadClasses['sql2wiki'] = $dir . 'SQL2Wiki_body.php';
 56+$wgExtensionMessagesFiles['sql2wiki'] = $dir . 'SQL2Wiki.i18n.php';
 57+$wgSpecialPages['sql2wiki'] = 'SQL2Wiki';
 58+
 59+$sql2wiki_DB_handles = array();
 60+
 61+require_once($dir . 'SQL2Wiki_body.php');
 62+
 63+$wgOracleDBMSEnabled = false;
 64+
 65+function SQL2Wiki_enableDBMSOutput($dbObj, $state = true) {
 66+ global $wgOracleDBMSEnabled;
 67+ $wgOracleDBMSEnabled = $state;
 68+ if ($state)
 69+ $dbObj->doQuery ('begin dbms_output.enable(null); end;');
 70+ else
 71+ $dbObj->doQuery ('begin dbms_output.disable; end;');
 72+}
 73+
 74+function SQL2Wiki_getDBMSOutput($dbObj) {
 75+ global $wgOracleDBMSEnabled;
 76+
 77+ if ($wgOracleDBMSEnabled === false)
 78+ return false;
 79+
 80+ $out = array();
 81+ $qReturn = null;
 82+ $wdc = 0;
 83+ $qReturn = $dbObj->doQuery('select column_value from table(get_output_lines())');
 84+ while(($qLine = $qReturn->fetchObject()) !== FALSE) {
 85+ $out[] = $qLine->column_value;
 86+ }
 87+
 88+ return $out;
 89+}
 90+
 91+function wfSQL2Wiki() {
 92+ global $wgParser;
 93+ $wgParser->setHook( "sql2wiki", "renderSQL" );
 94+ $wgParser->setHook( "plsql2wiki", "renderPLSQL" );
 95+}
 96+
 97+function SQL2Wiki_execute($db,$input,$enable_output,&$dbObj,&$result,&$output,&$error){
 98+ global $wgDBtype;
 99+ global $sql2wiki_DB_handles;
 100+
 101+ reset ($sql2wiki_DB_handles);
 102+ $bFound = false;
 103+ while(list($index,$val)=each($sql2wiki_DB_handles)) {
 104+ if ( $db == $index ) {
 105+ $aParams = explode(";", $val);
 106+
 107+ foreach($aParams as $parameter) {
 108+ if( count( $aParams ) < 3 ){
 109+ $error="Error in DB_handler definition !";
 110+ return false;
 111+ }
 112+ $host = trim($aParams[0]);
 113+ $user = trim($aParams[1]);
 114+ $pass = trim($aParams[2]);
 115+ $charset = trim($aParams[3]);
 116+ $bFound = true;
 117+ }
 118+ }
 119+ }
 120+ if ( !$bFound ){
 121+ $error="Error in DB_handler definition !";
 122+ return false;
 123+ }
 124+
 125+ $dbObj = new DatabaseOracle($db, $user, $pass, $host, false, 128);
 126+ if (!$dbObj->isOpen()){
 127+ $error='<b>SQL2Wiki failed to connect to DB &quot;'.$db.'&quot;</b>';
 128+ return false;
 129+ }
 130+
 131+ $ignore = $dbObj->ignoreErrors(true);
 132+
 133+ SQL2Wiki_enableDBMSOutput($dbObj, $enable_output);
 134+
 135+ $result = $dbObj->doQuery ($input);
 136+
 137+ $output='';
 138+ if ($enable_output){
 139+ $output = implode(SQL2Wiki_getDBMSOutput($dbObj), "\n");
 140+ if ($output === false){
 141+ $error='<b>SQL2Wiki completed successfully</b>';
 142+ return false;
 143+ }
 144+ }
 145+
 146+ $dbObj->ignoreErrors($ignore);
 147+
 148+ if ($dbObj->lastError() != null){
 149+ $error='<b>SQL2Wiki exited with error: '.$dbObj->lastError().' '.$input.'</b>';
 150+ return false;
 151+ }
 152+ elseif (isset($argv["quiet"])){
 153+ $error='';
 154+ return false;
 155+ }
 156+
 157+ return true;
 158+}
 159+
 160+
 161+function renderSQL( $input, $argv, &$parser ) {
 162+ global $wgOut;
 163+
 164+ $db = $argv["database"];
 165+
 166+ if (isset($argv["preexpand"]) && $argv["preexpand"] == 'true') {
 167+ $input = $parser->recursiveTagParse($input);
 168+ }
 169+
 170+ if (!SQL2Wiki_execute($db,$input,false,$dbObj,$result,$output,$error))
 171+ return $error;
 172+
 173+ if (isset($argv["inline"])) {
 174+ $field_separator = isset($argv["fieldseparator"]) ? $argv["fieldseparator"] : '';
 175+ $line_separator = isset($argv["lineseparator"]) ? $argv["lineseparator"] : '';
 176+
 177+ while (($line = $result->fetchObject()) !== FALSE) {
 178+ if ($output != '')
 179+ $output .= $line_separator."\n";
 180+
 181+ foreach ($line as $value){
 182+ $output .= $value.$field_separator;
 183+ }
 184+ $output = substr($output, 0, strlen($output)-strlen($field_separator));
 185+ }
 186+
 187+ if ($argv["inline"] != '') {
 188+ $other_params = '';
 189+ foreach($argv as $key=>$value)
 190+ if (!in_array($key, array('database', 'inline', 'fieldseparator', 'lineseparator', 'cache', 'expand', 'preexpand')))
 191+ $other_params .= ' '.$key.'="'.trim($value, '"').'"';
 192+ $output = '<'.$argv["inline"].$other_params.'>'.$output.'</'.$argv["inline"].'>';
 193+ }
 194+ } else {
 195+ $table_style = isset($argv["tablestyle"]) ? ' style="'.$argv["tablestyle"].'" ' : ' style="border: black solid 1px;" ';
 196+ $h_row_style = isset($argv["hrowstyle"]) ? ' style="'.$argv["hrow_style"].'" ' : '';
 197+ $h_cell_style = isset($argv["hcellstyle"]) ? ' style="'.$argv["hcellstyle"].'" ' : ' style="font-weight: bold;" ';
 198+ $row_style = isset($argv["rowstyle"]) ? ' style="'.$argv["rowstyle"].'" ' : '';
 199+ $cell_style = isset($argv["cellstyle"]) ? ' style="'.$argv["cellstyle"].'" ' : '';
 200+
 201+ # Create Table Header
 202+ $output .= '<table border=1 cellspacing=0 cellpadding=3'.$table_style.'>';
 203+ $output .= '<tr'.$h_row_style.'>';
 204+ $line = $result->fetchObject();
 205+ foreach ($line as $key=>$value) {
 206+ $output .= '<th'.$h_cell_style.'>'.$key.'</th>';
 207+ }
 208+ $output .= '</tr>';
 209+
 210+ # Create Table Data Rows
 211+ do {
 212+ $output .= '<tr'.$row_style.'>';
 213+ foreach ($line as $value){
 214+ $output .= '<td'.$cell_style.'>'.$value.'</td>';
 215+
 216+ }
 217+ $output .= '</tr>';
 218+ } while (($line = $result->fetchObject()) !== FALSE);
 219+ # End of Table Tag
 220+ $output .= '</table>';
 221+ }
 222+
 223+
 224+ if (isset($argv["cache"]) && $argv["cache"] == 'off') {
 225+ $parser->disableCache();
 226+ } elseif (isset($argv["cache"]) && $argv["cache"] == 'manual') {
 227+ if (!isset($argv["inline"])) {
 228+ $refresh_url = preg_replace('/(.*?)&action=[^&]*(.*)/i', '$1$2', $_SERVER['REQUEST_URI']).
 229+ '&action=purge';
 230+ $output .= '<a href="'.$refresh_url.'"><small>Refresh</small></a>';
 231+ }
 232+ } elseif (isset($argv["inline"])) {
 233+ $parser->disableCache();
 234+ }
 235+
 236+ if ($wgOut->getPageTitle() != 'SQL2Wiki' && isset($argv["expand"]) && $argv["expand"] == 'true') {
 237+ $output = $parser->recursiveTagParse($output);
 238+ }
 239+
 240+ @$dbObj->close();
 241+ return $output;
 242+}
 243+
 244+function renderPLSQL( $input, $argv, &$parser ) {
 245+ global $wgDBtype;
 246+ global $wgOut;
 247+
 248+ $db = $argv["database"];
 249+
 250+ if (strtolower($wgDBtype) != 'oracle' && strtolower($wgDBtype) != 'oracless')
 251+ return '<b>This function is available only for Oracle and OracleSS DB class.</b>';
 252+
 253+ $dbms_output = isset($argv["dbmsoutput"]) ? $argv["dbmsoutput"] : false;
 254+
 255+ if (isset($argv["preexpand"]) && $argv["preexpand"] == 'true') {
 256+ $input = $parser->recursiveTagParse($input);
 257+ }
 258+
 259+ if (!SQL2Wiki_execute($db,$input,$dbms_output,$dbObj,$result,$output,$error))
 260+ return $error;
 261+
 262+ $wrapper = isset($argv["wrapper"]) ? $argv["wrapper"] : '';
 263+ if ($wrapper != '') {
 264+ $other_params = '';
 265+ foreach($argv as $key=>$value)
 266+ if (!in_array($key, array('database', 'wrapper', 'quiet', 'cache', 'expand', 'preexpand', 'dbmsoutput')))
 267+ $other_params .= ' '.$key.'="'.trim($value, '"').'"';
 268+
 269+ $output = '<'.$wrapper.$other_params.'>'.$output.'</'.$wrapper.'>';
 270+ }
 271+
 272+ if (!isset($argv["cache"]) || $argv["cache"] != 'on') {
 273+ $parser->disableCache();
 274+ }
 275+
 276+ if ($wgOut->getPageTitle() != 'SQL2Wiki' && isset($argv["expand"]) && $argv["expand"] == 'true' ) {
 277+ $output = $parser->recursiveTagParse($output);
 278+ }
 279+
 280+ @$dbObj->close();
 281+ return $output;
 282+}
 283+
 284+*/
Property changes on: trunk/extensions/SQL2Wiki/SQL2Wiki.php
___________________________________________________________________
Added: svn:eol-style
1285 + native
Index: trunk/extensions/SQL2Wiki/SpecialSQL2Wiki.php
@@ -0,0 +1,37 @@
 2+<?php
 3+
 4+class SpecialSQL2Wiki extends SpecialPage {
 5+
 6+ public function __construct() {
 7+ parent::__construct( 'SQL2Wiki' );
 8+ }
 9+
 10+ function execute($par) {
 11+ global $wgOut, $wgParser;
 12+
 13+ $this->setHeaders();
 14+
 15+ $pars = explode('/', str_replace('\\', ' ', $par));
 16+
 17+ $type = array_shift($pars);
 18+ $value = array_shift($pars);
 19+
 20+ $argv = array();
 21+ foreach ($pars as $arg) {
 22+ $subarg = explode('=', $arg);
 23+ $argv[$subarg[0]] = $subarg[1];
 24+ }
 25+ $argv['cache'] = 'on';
 26+ $argv['preexpand'] = 'false';
 27+ $argv['expand'] = 'false';
 28+
 29+ if (strtolower($type) == 'sql')
 30+ $wgOut->addHTML(SQL2Wiki::renderSQL($value, $argv, $wgParser, null));
 31+ elseif (strtolower($type) == 'plsql')
 32+ $wgOut->addHTML(SQL2Wiki::renderPLSQL($value, $argv, $wgParser, null));
 33+ else
 34+ $wgOut->addWikiText('<b>'.wfMsg('sql2wiki-err-invalid_type').'</b>');
 35+
 36+ }
 37+
 38+}
Property changes on: trunk/extensions/SQL2Wiki/SpecialSQL2Wiki.php
___________________________________________________________________
Added: svn:eol-style
139 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r89161Followup r89153, remove ?> from i18n filereedy11:58, 30 May 2011
r89289* fixed encoding problemfreakolowsky21:09, 1 June 2011

Comments

#Comment by Raymond (talk | contribs)   20:32, 1 June 2011

Please fix the encoding: "M�ller" at least 2 times.

Status & tagging log