WikiDebug/describe table
From TestWiki
< WikiDebug
Revision as of 21:38, 19 October 2011 by HappyDog (Talk | contribs) (moved Debugging tools/describe table to WikiDebug/describe table: Let's name it for the extension.)
The WikiDebug extension adds a new tag that allows you to display a live description of a DB table within a wiki page.
Contents
Syntax
<describe_table table="{TableName}" display="{DisplayType}" showindexes="{bool}"></describe_table>
- {TableName} is the name of a table in the wiki's database. Do not include the prefix specified by $wgPrefix.
- {DisplayType} is the output format for the table data and currently has two possible values. "table" outputs the table definition in tabular form and "sql" outputs it as an SQL "CREATE TABLE" statement. The display attribute is optional, and if omitted (or present but the value is invalid) then "sql" will be used.
- showindexes is an optional argument, which defaults to true if omitted. Set to false to disable index display when outputting in tabular form (ignored for SQL output).
As a security measure this extension will only allow display of tables added to the $wgWikiDebug_ViewableTables array. Any other tables are blocked.
For example, to view the table 'page', you would need to add the following to LocalSettings.php:
$wgWikiDebug_ViewableTables[] = "page";
Example 1: SQL output
Providing the table 'page' is in the viewable tables array, then you can show its description by using the following syntax:
<describe_table table="page"></describe_table>
Live Table Definition: page
CREATE TABLE IF NOT EXISTS `page` ( `page_id` int(8) unsigned NOT NULL AUTO_INCREMENT, `page_namespace` int(11) NOT NULL DEFAULT '0', `page_title` varchar(255) NOT NULL DEFAULT '', `page_restrictions` tinyblob NOT NULL, `page_counter` bigint(20) unsigned NOT NULL DEFAULT '0', `page_is_redirect` tinyint(1) unsigned NOT NULL DEFAULT '0', `page_is_new` tinyint(1) unsigned NOT NULL DEFAULT '0', `page_random` double unsigned NOT NULL DEFAULT '0', `page_touched` varchar(14) NOT NULL DEFAULT '', `page_latest` int(8) unsigned NOT NULL DEFAULT '0', `page_len` int(8) unsigned NOT NULL DEFAULT '0', `page_content_model` varbinary(32) DEFAULT NULL, `page_links_updated` varbinary(14) DEFAULT NULL, `page_lang` varbinary(35) DEFAULT NULL, PRIMARY KEY (`page_id`), UNIQUE KEY `name_title` (`page_namespace`,`page_title`), KEY `page_random` (`page_random`), KEY `page_len` (`page_len`), KEY `page_redirect_namespace_len` (`page_is_redirect`,`page_namespace`,`page_len`) ) ENGINE=MyISAM;
Example 2: Tabular description with indexes
<describe_table table="page" display="table"></describe_table>
Live Table Definition: page
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
page_id | int(8) unsigned | NO | PRI | auto_increment | |
page_namespace | int(11) | NO | MUL | 0 | |
page_title | varchar(255) | NO | |||
page_restrictions | tinyblob | NO | |||
page_counter | bigint(20) unsigned | NO | 0 | ||
page_is_redirect | tinyint(1) unsigned | NO | MUL | 0 | |
page_is_new | tinyint(1) unsigned | NO | 0 | ||
page_random | double unsigned | NO | MUL | 0 | |
page_touched | varchar(14) | NO | |||
page_latest | int(8) unsigned | NO | 0 | ||
page_len | int(8) unsigned | NO | MUL | 0 | |
page_content_model | varbinary(32) | YES | |||
page_links_updated | varbinary(14) | YES | |||
page_lang | varbinary(35) | YES |
Indexes
Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | PRIMARY | 1 | page_id | A | 209 | BTREE | |||||
0 | name_title | 1 | page_namespace | A | 11 | BTREE | |||||
0 | name_title | 2 | page_title | A | 209 | BTREE | |||||
1 | page_random | 1 | page_random | A | 209 | BTREE | |||||
1 | page_len | 1 | page_len | A | 209 | BTREE | |||||
1 | page_redirect_namespace_len | 1 | page_is_redirect | A | 2 | BTREE | |||||
1 | page_redirect_namespace_len | 2 | page_namespace | A | 14 | BTREE | |||||
1 | page_redirect_namespace_len | 3 | page_len | A | 209 | BTREE |
Example 2: Tabular Description without indexes
<describe_table table="page" display="table" showindexes="false"></describe_table>
Live Table Definition: page
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
page_id | int(8) unsigned | NO | PRI | auto_increment | |
page_namespace | int(11) | NO | MUL | 0 | |
page_title | varchar(255) | NO | |||
page_restrictions | tinyblob | NO | |||
page_counter | bigint(20) unsigned | NO | 0 | ||
page_is_redirect | tinyint(1) unsigned | NO | MUL | 0 | |
page_is_new | tinyint(1) unsigned | NO | 0 | ||
page_random | double unsigned | NO | MUL | 0 | |
page_touched | varchar(14) | NO | |||
page_latest | int(8) unsigned | NO | 0 | ||
page_len | int(8) unsigned | NO | MUL | 0 | |
page_content_model | varbinary(32) | YES | |||
page_links_updated | varbinary(14) | YES | |||
page_lang | varbinary(35) | YES |
Example 3: Non-viewable table
If we try and look at a table that is not listed in the $wgWikiDebug_ViewableTables array we get the following: