Index: trunk/extensions/SQL2Wiki/SQL2Wiki.php~ |
— | — | @@ -1,260 +0,0 @@ |
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 "'.$db.'"</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 | | -?> |