Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
399e977b82 | |
|
de6644302c | |
|
edd70257ad | |
|
cea39b66c8 | |
|
b852dec610 | |
|
f3c949dcb0 | |
|
3944eabdcd | |
|
f1677cb6f9 |
|
@ -1,35 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
|
@ -1,17 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -0,0 +1 @@
|
|||
*~
|
19
README
19
README
|
@ -1,8 +1,22 @@
|
|||
sqlquery Plugin for DokuWiki
|
||||
|
||||
Processing query to mysql database and display results as a table.
|
||||
Processing queries to databases and display results as a table.
|
||||
|
||||
All documentation for this plugin can be found at
|
||||
This is a improved version which can connect to different hosts
|
||||
and databases. The defaults are set in the plugin configuration.
|
||||
Different types, hosts and databases can be set inside the tag:
|
||||
|
||||
<sql type=mysql host=myhost db=mydb>
|
||||
SELECT foo FROM bar ORDER BY baz
|
||||
<sql>
|
||||
|
||||
For security reasons the credentials for database access are only
|
||||
stored in the main plugin configuration. At the moment there is
|
||||
only one user configurable so for access to multiple servers.
|
||||
So the user and password mast be the same across the servers.
|
||||
|
||||
Based on sqlquery-plugin from George Pirogov, original documentation
|
||||
for that base plugin can be found at
|
||||
https://www.dokuwiki.org/plugin:sqlquery
|
||||
|
||||
If you install this plugin manually, make sure it is installed in
|
||||
|
@ -13,6 +27,7 @@ Please refer to http://www.dokuwiki.org/plugins for additional info
|
|||
on how to install plugins in DokuWiki.
|
||||
|
||||
----
|
||||
Copyright (C) Thomas Hooge <thomas@hoogi.de>
|
||||
Copyright (C) George Pirogov <i1557@yandex.ru>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
# sqlquery
|
||||
A dokuwiki plugin for processing query to MySQL databases and display results as a table.
|
||||
|
||||
More information at https://www.dokuwiki.org/plugin:sqlquery
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
//$conf['fixme'] = 'FIXME';
|
||||
|
||||
$conf['type'] = 'mysql';
|
||||
$conf['Host'] = 'localhost';
|
||||
$conf['DB'] = '';
|
||||
$conf['user'] = '';
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @author George Pirogov <i1557@yandex.ru>
|
||||
*/
|
||||
|
||||
|
||||
$meta['type'] = array('multichoice', '_choices' => array('mysql', 'dblib'));
|
||||
$meta['Host'] = array('string');
|
||||
$meta['DB'] = array('string');
|
||||
$meta['user'] = array('string');
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* German language file for sqlquery plugin
|
||||
*
|
||||
* @author Thomas Hooge <thomas@hoogi.de>
|
||||
*/
|
||||
|
||||
// menu entry for admin plugins
|
||||
// $lang['menu'] = 'Your menu entry';
|
||||
|
||||
// custom language strings for the plugin
|
||||
// $lang['fixme'] = 'FIXME';
|
||||
|
||||
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* German language file for sqlquery plugin
|
||||
*
|
||||
* @author Thomas Hooge <thomas@hoogi.de>
|
||||
*/
|
||||
|
||||
// keys need to match the config setting name
|
||||
|
||||
$lang['type'] = 'DSN-Prefix (Datenbanktyp)';
|
||||
$lang['Host'] = 'Standard-Serveradresse (DNS oder IP)';
|
||||
$lang['DB'] = 'Standard-Datenbankname';
|
||||
$lang['user'] = 'Datenbankbenutzername';
|
||||
$lang['password'] = 'Datenbankkennwort';
|
||||
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* english language file for sqlquery plugin
|
||||
* English language file for sqlquery plugin
|
||||
*
|
||||
* @author George Pirogov <i1557@yandex.ru>
|
||||
*/
|
||||
|
@ -8,6 +8,11 @@
|
|||
// keys need to match the config setting name
|
||||
// $lang['fixme'] = 'FIXME';
|
||||
|
||||
$lang['type'] = 'DSN prefix (database type)';
|
||||
$lang['Host'] = 'Default server address (DNS or IP)';
|
||||
$lang['DB'] = 'Default database name';
|
||||
$lang['user'] = 'Database username';
|
||||
$lang['password'] = 'Database password';
|
||||
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* English language file for sqlquery plugin
|
||||
* Russian language file for sqlquery plugin
|
||||
*
|
||||
* @author George Pirogov <i1557@yandex.ru>
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* english language file for sqlquery plugin
|
||||
* Russian language file for sqlquery plugin
|
||||
*
|
||||
* @author George Pirogov <i1557@yandex.ru>
|
||||
*/
|
||||
|
@ -8,8 +8,9 @@
|
|||
// keys need to match the config setting name
|
||||
// $lang['fixme'] = 'FIXME';
|
||||
|
||||
$lang['Host'] = 'Адрес MySQL сервера (dns или ip)';
|
||||
$lang['DB'] = 'Имя базы данных MySQL';
|
||||
$lang['type'] = 'Префикс DSN (тип базы данных)';
|
||||
$lang['Host'] = 'Адрес сервера по умолчанию (DNS или IP)';
|
||||
$lang['DB'] = 'Имя базы данных по умолчанию';
|
||||
$lang['user'] = 'Логин';
|
||||
$lang['password'] = 'Пароль';
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
base sqlquery
|
||||
author George Pirogov
|
||||
email i1557@yandex.ru
|
||||
date 2016-11-25
|
||||
name SQL query plugin
|
||||
desc Processing query to mysql database and display results as a table.
|
||||
url https://www.dokuwiki.org/plugin:sqlquery
|
||||
author Thomas Hooge
|
||||
email thomas@hoogi.de
|
||||
date 2023-12-01
|
||||
name SQL query plugin (multidb)
|
||||
desc Processing queries to databases and display results as a table.
|
||||
|
|
161
syntax.php
161
syntax.php
|
@ -4,29 +4,26 @@
|
|||
*
|
||||
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author George Pirogov <i1557@yandex.ru>
|
||||
* @author Thomas Hooge <hooge@rowa-group.com>
|
||||
*
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if (!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* All DokuWiki plugins to extend the parser/rendering mechanism
|
||||
* need to inherit from this class
|
||||
*/
|
||||
class syntax_plugin_sqlquery extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
public function getType() {
|
||||
return 'substition';
|
||||
}
|
||||
|
||||
public function getSort() {
|
||||
return 666;
|
||||
}
|
||||
public function getType() { return 'substition'; }
|
||||
public function getSort() { return 666; }
|
||||
public function getPType() { return 'block'; }
|
||||
|
||||
public function connectTo($mode)
|
||||
{
|
||||
$this->Lexer->addEntryPattern('<sql>', $mode, 'plugin_sqlquery');
|
||||
}
|
||||
|
||||
public function postConnect()
|
||||
{
|
||||
$this->Lexer->addExitPattern('</sql>','plugin_sqlquery');
|
||||
$this->Lexer->addSpecialPattern('<sql\b(?:\s+(?:host|db|type)=[\w\-\.$]+?)*\s*>(?:.*?</sql>)', $mode, 'plugin_sqlquery');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,29 +33,36 @@ class syntax_plugin_sqlquery extends DokuWiki_Syntax_Plugin {
|
|||
* @param int $state The state of the handler
|
||||
* @param int $pos The position in the document
|
||||
* @param Doku_Handler $handler The handler
|
||||
*
|
||||
* @return array Data for the renderer
|
||||
*/
|
||||
public function handle($match, $state, $pos, Doku_Handler $handler)
|
||||
{
|
||||
switch ( $state )
|
||||
{
|
||||
case DOKU_LEXER_ENTER:
|
||||
$data = array();
|
||||
return $data;
|
||||
break;
|
||||
|
||||
case DOKU_LEXER_UNMATCHED:
|
||||
return array('sqlquery' => $match);
|
||||
break;
|
||||
|
||||
case DOKU_LEXER_EXIT:
|
||||
$data = array();
|
||||
return $data;
|
||||
break;
|
||||
|
||||
public function handle($match, $state, $pos, Doku_Handler $handler) {
|
||||
$data = array('state' => $state);
|
||||
if ($state == DOKU_LEXER_SPECIAL) {
|
||||
# get type (DSN prefix)
|
||||
if (preg_match('/<sql\b.*type=(mysql|dblib)/', $match, $result)) {
|
||||
$data['type'] = $result[1];
|
||||
} else {
|
||||
$data['type'] = $this->getConf('type');
|
||||
}
|
||||
# get host
|
||||
if (preg_match('/<sql\b.*host=([\w\-\.$]+)/', $match, $result)) {
|
||||
$data['host'] = $result[1];
|
||||
} else {
|
||||
$data['host'] = $this->getConf('Host');
|
||||
}
|
||||
# get database
|
||||
if (preg_match('/<sql\b.*db=([\w\-\.$]+)/', $match, $result)) {
|
||||
$data['db'] = $result[1];
|
||||
} else {
|
||||
$data['db'] = $this->getConf('DB');
|
||||
}
|
||||
# get query
|
||||
$data['match'] = $match;
|
||||
if (preg_match('%<sql.*?>(.*)</sql>%s', $match, $result)) {
|
||||
$data['query'] = trim($result[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -68,72 +72,73 @@ class syntax_plugin_sqlquery extends DokuWiki_Syntax_Plugin {
|
|||
* @param string $mode Renderer mode (supported modes: xhtml)
|
||||
* @param Doku_Renderer $renderer The renderer
|
||||
* @param array $data The data from the handler() function
|
||||
*
|
||||
* @return bool If rendering was successful.
|
||||
*/
|
||||
public function render($mode, Doku_Renderer $renderer, $data)
|
||||
{
|
||||
if ($mode != 'xhtml') return false;
|
||||
if (empty($data['query'])) return true;
|
||||
|
||||
if ( !empty( $data['sqlquery'] ) )
|
||||
{
|
||||
// получаем параметры конфигурации
|
||||
$host = $this->getConf('Host');
|
||||
$DB = $this->getConf('DB');
|
||||
// get configuration
|
||||
$user = $this->getConf('user');
|
||||
$password = $this->getConf('password');
|
||||
|
||||
// получаем запрос
|
||||
$querystring = $data['sqlquery'];
|
||||
// connect to database
|
||||
$dsn = "{$data['type']}:host={$data['host']};dbname={$data[db]};charset=UTF8;";
|
||||
try {
|
||||
$dbh = new PDO($dsn, $user, $password);
|
||||
} catch (PDOException $e) {
|
||||
$renderer->doc .= "<pre>Unable to connect to database:" . $e->getMessage() . "</pre>\n";
|
||||
return true;
|
||||
}
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
|
||||
|
||||
// подключаемся к базе
|
||||
$link = mysqli_connect($host, $user, $password, $DB);
|
||||
mysqli_set_charset($link, "utf8");
|
||||
// run query
|
||||
try {
|
||||
$result = $dbh->query($data['query']);
|
||||
} catch (PDOException $e) {
|
||||
$renderer->doc .= "<pre>Error in query:" . $e->getMessage() . "</pre>\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
// подключились
|
||||
if ( $link )
|
||||
{
|
||||
$result = mysqli_query($link, $querystring);
|
||||
if ( $result )
|
||||
{
|
||||
// получаем кол-во полей в таблице
|
||||
$fieldcount = mysqli_num_fields($result);
|
||||
// get the number of fields in the table
|
||||
$fieldcount = $result->columnCount();
|
||||
|
||||
// строим таблицу
|
||||
$renderer->doc .= "<table id=\"sqlquerytable\" class=\"inline\">";
|
||||
// build a table
|
||||
$renderer->doc .= '<table id="sqlquerytable" class="inline">' . "\n";
|
||||
|
||||
// строим заголовок
|
||||
// build the header section of the table
|
||||
$renderer->doc .= "<thead><tr>";
|
||||
while ($fieldinfo = mysqli_fetch_field($result))
|
||||
{
|
||||
|
||||
for ($i = 0; $i < $fieldcount; $i++) {
|
||||
$meta = $result->getColumnMeta($i);
|
||||
$renderer->doc .= "<th>";
|
||||
$renderer->doc .= $fieldinfo->name;
|
||||
$renderer->doc .= $meta['name'];
|
||||
$renderer->doc .= "</th>";
|
||||
}
|
||||
$renderer->doc .= "</tr></thead>";
|
||||
$renderer->doc .= "</tr></thead>\n";
|
||||
|
||||
// строим содержимое таблицы
|
||||
$renderer->doc .= "<tbody>";
|
||||
while ($row = mysqli_fetch_row($result))
|
||||
{
|
||||
// build the contents of the table
|
||||
$renderer->doc .= "<tbody>\n";
|
||||
foreach ($result as $row) {
|
||||
$renderer->doc .= "<tr>";
|
||||
|
||||
// строим строку
|
||||
for ( $i = 0; $i < $fieldcount; $i++ )
|
||||
{
|
||||
for ( $i = 0; $i < $fieldcount; $i++ ) {
|
||||
$renderer->doc .= "<td>";
|
||||
$renderer->doc .= $row[$i];
|
||||
$renderer->doc .= htmlentities($row[$i]);
|
||||
$renderer->doc .= "</td>";
|
||||
}
|
||||
$renderer->doc .= "</tr>";
|
||||
} // of while fetch_row
|
||||
// закрываем таблицу
|
||||
$renderer->doc .= "</tbody></table>";
|
||||
} // of mysqli_query
|
||||
mysqli_close($link);
|
||||
} // of mysqli link
|
||||
} // of sqlquery not empty
|
||||
return true;
|
||||
} // of render function
|
||||
$renderer->doc .= "</tr>\n";
|
||||
}
|
||||
|
||||
// vim:ts=4:sw=4:et:
|
||||
// finish the table
|
||||
$renderer->doc .= "</tbody>\n</table>\n";
|
||||
|
||||
// Close connection, there is no close() method with PDO :-(
|
||||
$result = null;
|
||||
$dbh = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue