WikiDebug/describe table

From TestWiki
Jump to: navigation, search

The WikiDebug extension adds a new tag that allows you to display a live description of a DB table within a wiki page.

Syntax[edit]

<describe_table table="{TableName}" display="{DisplayType}" showindexes="{bool}" />
  • {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 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[edit]

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" />

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[edit]

<describe_table table="page" display="table" />

Live Table Definition: page

FieldTypeNullKeyDefaultExtra
page_idint(8) unsignedNOPRI auto_increment
page_namespaceint(11)NOMUL0 
page_titlevarchar(255)NO   
page_restrictionstinyblobNO   
page_counterbigint(20) unsignedNO 0 
page_is_redirecttinyint(1) unsignedNOMUL0 
page_is_newtinyint(1) unsignedNO 0 
page_randomdouble unsignedNOMUL0 
page_touchedvarchar(14)NO   
page_latestint(8) unsignedNO 0 
page_lenint(8) unsignedNOMUL0 
page_content_modelvarbinary(32)YES   
page_links_updatedvarbinary(14)YES   
page_langvarbinary(35)YES   

Indexes

Non_uniqueKey_nameSeq_in_indexColumn_nameCollationCardinalitySub_partPackedNullIndex_typeCommentIndex_comment
0PRIMARY1page_idA209   BTREE  
0name_title1page_namespaceA    BTREE  
0name_title2page_titleA209   BTREE  
1page_random1page_randomA209   BTREE  
1page_len1page_lenA209   BTREE  
1page_redirect_namespace_len1page_is_redirectA2   BTREE  
1page_redirect_namespace_len2page_namespaceA14   BTREE  
1page_redirect_namespace_len3page_lenA209   BTREE  


Example 2: Tabular Description without indexes[edit]

<describe_table table="page" display="table" showindexes="false" />

Live Table Definition: page

FieldTypeNullKeyDefaultExtra
page_idint(8) unsignedNOPRI auto_increment
page_namespaceint(11)NOMUL0 
page_titlevarchar(255)NO   
page_restrictionstinyblobNO   
page_counterbigint(20) unsignedNO 0 
page_is_redirecttinyint(1) unsignedNOMUL0 
page_is_newtinyint(1) unsignedNO 0 
page_randomdouble unsignedNOMUL0 
page_touchedvarchar(14)NO   
page_latestint(8) unsignedNO 0 
page_lenint(8) unsignedNOMUL0 
page_content_modelvarbinary(32)YES   
page_links_updatedvarbinary(14)YES   
page_langvarbinary(35)YES   


Example 3: Non-viewable table[edit]

If we try and look at a table that is not listed in the $wgWikiDebug_ViewableTables array we get the following:

Live Table Definition: user

Table cannot be viewed. It either does not exist, or is protected against viewing.