Index: trunk/extensions/SQL2Wiki/SQL2Wiki.php |
— | — | @@ -37,247 +37,3 @@ |
38 | 38 | |
39 | 39 | // list of database contact data |
40 | 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 "'.$db.'"</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 | | -*/ |