Difference between revisions of "Pma2wiki"
Jump to navigation
Jump to search
(New page: See Also: highlighting <source lang=php> #!/usr/bin/php <?php /** * This script is meant to be used as a command-line tool, or else as the target of a custom action within * Quanta ...) |
(fix nesting of <source>) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | See Also: [[highlighting]] | + | See Also: [[Syntax highlighting]] |
− | < | + | <syntaxhighlight lang=php> |
#!/usr/bin/php | #!/usr/bin/php | ||
<?php | <?php | ||
/** | /** | ||
− | + | * This script is meant to be used as a command-line tool, or else as the target of a custom action within | |
− | + | * Quanta | |
− | + | * The script will get the contents of a file which is the generated output of a PHPMyAdmin SQL Schema export, and change the | |
− | + | * format of the table defintion 'headings' into the H2 heading format suitable for posting into MediaWiki | |
− | + | * This process creates easy to navigate and reference SQL schema files in the wiki | |
− | + | * The exact tag output by this script (<sql> or <source lang=sql>) must correlate with the MediaWiki extension you use to get syntax highlighting | |
− | + | * In any case, you need to have a GeSHi syntax highlighting extension active in your MediaWiki installation. | |
− | + | * | |
− | + | * @Usage | |
− | + | * php /path/to/pma2wiki.php /some/pma-schema.sql | |
− | + | */ | |
$content = file_get_contents($argv[1]); | $content = file_get_contents($argv[1]); | ||
Line 21: | Line 21: | ||
/** replace the | /** replace the | ||
− | + | * -- -------------------------------------------------------- | |
− | + | * with nothing | |
− | + | */ | |
$content = preg_replace ("/^[\s-]+$\n/m", '', $content); | $content = preg_replace ("/^[\s-]+$\n/m", '', $content); | ||
/** Handle the 'header' output | /** Handle the 'header' output | ||
− | + | * e.g. | |
-- phpMyAdmin SQL Dump | -- phpMyAdmin SQL Dump | ||
-- version 2.9.1.1-Debian-3 | -- version 2.9.1.1-Debian-3 | ||
-- http://www.phpmyadmin.net | -- http://www.phpmyadmin.net | ||
− | + | */ | |
$pattern = '/ | $pattern = '/ | ||
Line 47: | Line 47: | ||
/** | /** | ||
− | + | * Make the DB name a H2 | |
− | + | */ | |
$pattern = '/^--[\s]([^:]+): `(.*)`$/mU'; | $pattern = '/^--[\s]([^:]+): `(.*)`$/mU'; | ||
$replacement = "== $1: $2 == \n"; | $replacement = "== $1: $2 == \n"; | ||
Line 54: | Line 54: | ||
/** handle the heading metadata | /** handle the heading metadata | ||
− | + | * e.g. | |
− | -- Host: | + | -- Host: foo.example.com |
-- Generation Time: May 03, 2007 at 12:33 PM | -- Generation Time: May 03, 2007 at 12:33 PM | ||
-- Server version: 3.23.55 | -- Server version: 3.23.55 | ||
-- PHP Version: 5.2.0-8+etch1 | -- PHP Version: 5.2.0-8+etch1 | ||
-- | -- | ||
− | -- Database: ` | + | -- Database: `myDatabase` |
− | + | */ | |
$pattern = '/^--[\s]([^:]+): (.*)$/mU'; | $pattern = '/^--[\s]([^:]+): (.*)$/mU'; | ||
$replacement = "; $1: $2"; | $replacement = "; $1: $2"; | ||
Line 67: | Line 67: | ||
/** replace the | /** replace the | ||
− | + | * -- Table -- | |
− | + | * comment with a | |
− | + | * === Table === | |
− | + | * wiki syntax heading | |
− | + | */ | |
//$content = preg_replace("/^--\s+\n^-- Table structure for table `([^`]+)`\n^--\s+\n/imUs", "\n=== $1 ===\n", $content); | //$content = preg_replace("/^--\s+\n^-- Table structure for table `([^`]+)`\n^--\s+\n/imUs", "\n=== $1 ===\n", $content); | ||
$content = preg_replace("/\n^-- Table structure for table `([^`]+)`$/imUs", "\n=== $1 ===\n", $content); | $content = preg_replace("/\n^-- Table structure for table `([^`]+)`$/imUs", "\n=== $1 ===\n", $content); | ||
/** replace the | /** replace the | ||
− | + | * -- -------------------------------------------------------- | |
− | + | * with nothing | |
− | + | */ | |
$content = preg_replace ("/^[\s-]+$\n/m", '', $content); | $content = preg_replace ("/^[\s-]+$\n/m", '', $content); | ||
/** wrap the CREATE statement in <sql> tags (relies on geshi) | /** wrap the CREATE statement in <sql> tags (relies on geshi) | ||
− | + | */ | |
$pattern = '/(CREATE TABLE [^;]+;)/U'; | $pattern = '/(CREATE TABLE [^;]+;)/U'; | ||
− | $replacement = '<source lang=sql> | + | // depends on GeSHi and which extension you have |
+ | $replacement = '<source lang=sql> | ||
$1 | $1 | ||
</source> | </source> | ||
Line 93: | Line 94: | ||
echo $content; | echo $content; | ||
?> | ?> | ||
− | </ | + | </syntaxhighlight> |
+ | |||
+ | [[Category:Wiki]] |
Latest revision as of 09:36, 31 January 2020
See Also: MediaWiki/Syntax highlighting
#!/usr/bin/php
<?php
/**
* This script is meant to be used as a command-line tool, or else as the target of a custom action within
* Quanta
* The script will get the contents of a file which is the generated output of a PHPMyAdmin SQL Schema export, and change the
* format of the table defintion 'headings' into the H2 heading format suitable for posting into MediaWiki
* This process creates easy to navigate and reference SQL schema files in the wiki
* The exact tag output by this script (<sql> or <source lang=sql>) must correlate with the MediaWiki extension you use to get syntax highlighting
* In any case, you need to have a GeSHi syntax highlighting extension active in your MediaWiki installation.
*
* @Usage
* php /path/to/pma2wiki.php /some/pma-schema.sql
*/
$content = file_get_contents($argv[1]);
/** replace the
* -- --------------------------------------------------------
* with nothing
*/
$content = preg_replace ("/^[\s-]+$\n/m", '', $content);
/** Handle the 'header' output
* e.g.
-- phpMyAdmin SQL Dump
-- version 2.9.1.1-Debian-3
-- http://www.phpmyadmin.net
*/
$pattern = '/
-- phpMyAdmin SQL Dump
-- version (.*)$
-- http(.*)$
/mU';
$replacement = '
phpMyAdmin SQL Dump<br />
version $1<br />
http$2
';
$content = preg_replace ($pattern, $replacement, $content);
/**
* Make the DB name a H2
*/
$pattern = '/^--[\s]([^:]+): `(.*)`$/mU';
$replacement = "== $1: $2 == \n";
$content = preg_replace ($pattern, $replacement, $content);
/** handle the heading metadata
* e.g.
-- Host: foo.example.com
-- Generation Time: May 03, 2007 at 12:33 PM
-- Server version: 3.23.55
-- PHP Version: 5.2.0-8+etch1
--
-- Database: `myDatabase`
*/
$pattern = '/^--[\s]([^:]+): (.*)$/mU';
$replacement = "; $1: $2";
$content = preg_replace ($pattern, $replacement, $content);
/** replace the
* -- Table --
* comment with a
* === Table ===
* wiki syntax heading
*/
//$content = preg_replace("/^--\s+\n^-- Table structure for table `([^`]+)`\n^--\s+\n/imUs", "\n=== $1 ===\n", $content);
$content = preg_replace("/\n^-- Table structure for table `([^`]+)`$/imUs", "\n=== $1 ===\n", $content);
/** replace the
* -- --------------------------------------------------------
* with nothing
*/
$content = preg_replace ("/^[\s-]+$\n/m", '', $content);
/** wrap the CREATE statement in <sql> tags (relies on geshi)
*/
$pattern = '/(CREATE TABLE [^;]+;)/U';
// depends on GeSHi and which extension you have
$replacement = '<source lang=sql>
$1
</source>
';
$content = preg_replace ($pattern, $replacement, $content);
// output the content so that the Quanta action can see it.
echo $content;
?>