r113059 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113058‎ | r113059 | r113060 >
Date:18:18, 5 March 2012
Author:kipcool
Status:deferred
Tags:
Comment:
Created an install script
Modified paths:
  • /trunk/extensions/Wikidata/Console/installWikidata.php (added) (history)
  • /trunk/extensions/Wikidata/Console/wikidataTemplate.sql (added) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/Console/wikidataTemplate.sql
@@ -0,0 +1,304 @@
 2+--
 3+-- Add the wikidata specific namespaces
 4+--
 5+
 6+CREATE TABLE IF NOT EXISTS language (
 7+ language_id int(10) NOT NULL auto_increment,
 8+ dialect_of_lid int(10) NOT NULL default '0',
 9+ iso639_2 varchar(10) collate utf8_bin NOT NULL default '',
 10+ iso639_3 varchar(10) collate utf8_bin NOT NULL default '',
 11+ wikimedia_key varchar(10) collate utf8_bin NOT NULL default '',
 12+ PRIMARY KEY (language_id)
 13+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 14+
 15+
 16+CREATE TABLE IF NOT EXISTS language_names (
 17+ language_id int(10) NOT NULL default '0',
 18+ name_language_id int(10) NOT NULL default '0',
 19+ language_name varchar(255) NOT NULL default '',
 20+ PRIMARY KEY (language_id,name_language_id),
 21+ KEY language_id (language_id)
 22+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 23+
 24+
 25+CREATE TABLE IF NOT EXISTS wikidata_sets (
 26+ set_prefix varchar(20) default NULL,
 27+ set_fallback_name varchar(255) default NULL,
 28+ set_dmid int(10) default NULL
 29+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 30+
 31+
 32+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/alt_meaningtexts (
 33+ `meaning_mid` int(10) default NULL,
 34+ `meaning_text_tcid` int(10) default NULL,
 35+ `source_id` int(11) NOT NULL default '0',
 36+ `add_transaction_id` int(11) NOT NULL,
 37+ `remove_transaction_id` int(11) default NULL,
 38+ KEY /*$wgWDprefix*/versioned_end_meaning (`remove_transaction_id`,`meaning_mid`,`meaning_text_tcid`,`source_id`),
 39+ KEY /*$wgWDprefix*/versioned_end_text (`remove_transaction_id`,`meaning_text_tcid`,`meaning_mid`,`source_id`),
 40+ KEY /*$wgWDprefix*/versioned_end_source (`remove_transaction_id`,`source_id`,`meaning_mid`,`meaning_text_tcid`),
 41+ KEY /*$wgWDprefix*/versioned_start_meaning (`add_transaction_id`,`meaning_mid`,`meaning_text_tcid`,`source_id`),
 42+ KEY /*$wgWDprefix*/versioned_start_text (`add_transaction_id`,`meaning_text_tcid`,`meaning_mid`,`source_id`),
 43+ KEY /*$wgWDprefix*/versioned_start_source (`add_transaction_id`,`source_id`,`meaning_mid`,`meaning_text_tcid`)
 44+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 45+
 46+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/bootstrapped_defined_meanings (
 47+ `name` varchar(255) NOT NULL,
 48+ `defined_meaning_id` int(11) NOT NULL,
 49+ KEY /*$wgWDprefix*/unversioned_meaning (`defined_meaning_id`),
 50+ KEY /*$wgWDprefix*/unversioned_name (`name` (255),`defined_meaning_id`)
 51+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 52+
 53+-- object_id - key for the attribute, used elsewhere as a foreign key
 54+-- class_mid - which class (identified by DMID) has this attribute?
 55+-- level_mid - on which level can we annotate: Annotation, DefinedMeaning, Definition, Relation, SynTrans; these are also cached in *_bootstrapped_defined_meanings
 56+-- attribute_mid - which attribute are we describing?
 57+-- attribute_type - what kind of information are we talking about? can be 'DM', 'TRNS' (translatable text), 'TEXT', 'URL', 'OPTN' (multiple DMs to choose from)a
 58+-- attribute_id - refers to the object_id from xx_class_attributes
 59+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/class_attributes (
 60+ `object_id` int(11) NOT NULL,
 61+ `class_mid` int(11) NOT NULL default '0',
 62+ `level_mid` int(11) NOT NULL,
 63+ `attribute_mid` int(11) NOT NULL default '0',
 64+ `attribute_type` char(4) collate utf8_bin NOT NULL default 'TEXT',
 65+ `add_transaction_id` int(11) NOT NULL,
 66+ `remove_transaction_id` int(11) default NULL,
 67+ KEY /*$wgWDprefix*/versioned_end_class (`remove_transaction_id`,`class_mid`,`attribute_mid`,`object_id`),
 68+ KEY /*$wgWDprefix*/versioned_end_attribute (`remove_transaction_id`,`attribute_mid`,`class_mid`,`object_id`),
 69+ KEY /*$wgWDprefix*/versioned_end_object (`remove_transaction_id`,`object_id`),
 70+ KEY /*$wgWDprefix*/versioned_start_class (`add_transaction_id`,`class_mid`,`attribute_mid`,`object_id`),
 71+ KEY /*$wgWDprefix*/versioned_start_attribute (`add_transaction_id`,`attribute_mid`,`class_mid`,`object_id`),
 72+ KEY /*$wgWDprefix*/versioned_start_object (`add_transaction_id`,`object_id`)
 73+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 74+
 75+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/class_membership (
 76+ `class_membership_id` int(11) NOT NULL,
 77+ `class_mid` int(11) NOT NULL default '0',
 78+ `class_member_mid` int(11) NOT NULL default '0',
 79+ `add_transaction_id` int(11) NOT NULL,
 80+ `remove_transaction_id` int(11) default NULL,
 81+ KEY /*$wgWDprefix*/versioned_end_class (`remove_transaction_id`,`class_mid`,`class_member_mid`),
 82+ KEY /*$wgWDprefix*/versioned_end_class_member (`remove_transaction_id`,`class_member_mid`,`class_mid`),
 83+ KEY /*$wgWDprefix*/versioned_end_class_membership (`remove_transaction_id`,`class_membership_id`),
 84+ KEY /*$wgWDprefix*/versioned_start_class (`add_transaction_id`,`class_mid`,`class_member_mid`),
 85+ KEY /*$wgWDprefix*/versioned_start_class_member (`add_transaction_id`,`class_member_mid`,`class_mid`),
 86+ KEY /*$wgWDprefix*/versioned_start_class_membership (`add_transaction_id`,`class_membership_id`)
 87+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 88+
 89+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/collection_contents (
 90+`object_id` int(11) default NULL,
 91+ `collection_id` int(10) NOT NULL default '0',
 92+ `member_mid` int(10) NOT NULL default '0',
 93+ `internal_member_id` varchar(255) default NULL,
 94+ `applicable_language_id` int(10) default NULL,
 95+ `add_transaction_id` int(11) NOT NULL,
 96+ `remove_transaction_id` int(11) default NULL,
 97+ KEY /*$wgWDprefix*/versioned_end_collection (`remove_transaction_id`,`collection_id`,`member_mid`),
 98+ KEY /*$wgWDprefix*/versioned_end_collection_member (`remove_transaction_id`,`member_mid`,`collection_id`),
 99+ KEY /*$wgWDprefix*/versioned_end_internal_id (`remove_transaction_id`,`internal_member_id`,`collection_id`,`member_mid`),
 100+ KEY /*$wgWDprefix*/versioned_start_collection (`add_transaction_id`,`collection_id`,`member_mid`),
 101+ KEY /*$wgWDprefix*/versioned_start_collection_member (`add_transaction_id`,`member_mid`,`collection_id`),
 102+ KEY /*$wgWDprefix*/versioned_start_internal_id (`add_transaction_id`,`internal_member_id`,`collection_id`,`member_mid`)
 103+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 104+
 105+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/collection_language (
 106+ `collection_id` int(10) NOT NULL default '0',
 107+ `language_id` int(10) NOT NULL default '0'
 108+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 109+
 110+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/collection (
 111+ `collection_id` int(10) unsigned NOT NULL,
 112+ `collection_mid` int(10) NOT NULL default '0',
 113+ `collection_type` char(4) default NULL,
 114+ `add_transaction_id` int(11) NOT NULL,
 115+ `remove_transaction_id` int(11) default NULL,
 116+ KEY /*$wgWDprefix*/versioned_end_collection (`remove_transaction_id`,`collection_id`,`collection_mid`),
 117+ KEY /*$wgWDprefix*/versioned_end_collection_meaning (`remove_transaction_id`,`collection_mid`,`collection_id`),
 118+ KEY /*$wgWDprefix*/versioned_end_collection_type (`remove_transaction_id`,`collection_type` (4),`collection_id`,`collection_mid`),
 119+ KEY /*$wgWDprefix*/versioned_start_collection (`add_transaction_id`,`collection_id`,`collection_mid`),
 120+ KEY /*$wgWDprefix*/versioned_start_collection_meaning (`add_transaction_id`,`collection_mid`,`collection_id`),
 121+ KEY /*$wgWDprefix*/versioned_start_collection_type (`add_transaction_id`,`collection_type` (4),`collection_id`,`collection_mid`)
 122+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 123+
 124+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/defined_meaning (
 125+ `defined_meaning_id` int(8) unsigned NOT NULL,
 126+ `expression_id` int(10) NOT NULL,
 127+ `meaning_text_tcid` int(10) NOT NULL default '0',
 128+ `add_transaction_id` int(11) NOT NULL,
 129+ `remove_transaction_id` int(11) default NULL,
 130+ KEY /*$wgWDprefix*/versioned_end_meaning (`remove_transaction_id`,`defined_meaning_id`,`expression_id`),
 131+ KEY /*$wgWDprefix*/versioned_end_expression (`remove_transaction_id`,`expression_id`,`defined_meaning_id`),
 132+ KEY /*$wgWDprefix*/versioned_end_meaning_text (`remove_transaction_id`,`meaning_text_tcid`,`defined_meaning_id`),
 133+ KEY /*$wgWDprefix*/versioned_start_meaning (`add_transaction_id`,`defined_meaning_id`,`expression_id`),
 134+ KEY /*$wgWDprefix*/versioned_start_expression (`add_transaction_id`,`expression_id`,`defined_meaning_id`),
 135+ KEY /*$wgWDprefix*/versioned_start_meaning_text (`add_transaction_id`,`meaning_text_tcid`,`defined_meaning_id`)
 136+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 137+
 138+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/expression (
 139+ `expression_id` int(10) unsigned NOT NULL,
 140+ `spelling` varchar(255) NOT NULL default '',
 141+ `language_id` int(10) NOT NULL default '0',
 142+ `add_transaction_id` int(11) NOT NULL,
 143+ `remove_transaction_id` int(11) default NULL,
 144+ KEY /*$wgWDprefix*/versioned_end_expression (`remove_transaction_id`,`expression_id`,`language_id`),
 145+ KEY /*$wgWDprefix*/versioned_end_language (`remove_transaction_id`,`language_id`,`expression_id`),
 146+ KEY /*$wgWDprefix*/versioned_end_spelling (`remove_transaction_id`,`spelling`(255),`expression_id`,`language_id`),
 147+ KEY /*$wgWDprefix*/versioned_start_expression (`add_transaction_id`,`expression_id`,`language_id`),
 148+ KEY /*$wgWDprefix*/versioned_start_language (`add_transaction_id`,`language_id`,`expression_id`),
 149+ KEY /*$wgWDprefix*/versioned_start_spelling (`add_transaction_id`,`spelling`,`expression_id`,`language_id`)
 150+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 151+
 152+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/meaning_relations (
 153+ `relation_id` int(11) NOT NULL,
 154+ `meaning1_mid` int(10) NOT NULL default '0',
 155+ `meaning2_mid` int(10) NOT NULL default '0',
 156+ `relationtype_mid` int(10) default NULL,
 157+ `add_transaction_id` int(11) NOT NULL,
 158+ `remove_transaction_id` int(11) default NULL,
 159+ KEY /*$wgWDprefix*/versioned_end_outgoing (`remove_transaction_id`,`meaning1_mid`,`relationtype_mid`,`meaning2_mid`),
 160+ KEY /*$wgWDprefix*/versioned_end_incoming (`remove_transaction_id`,`meaning2_mid`,`relationtype_mid`,`meaning1_mid`),
 161+ KEY /*$wgWDprefix*/versioned_end_relation (`remove_transaction_id`,`relation_id`),
 162+ KEY /*$wgWDprefix*/versioned_start_outgoing (`add_transaction_id`,`meaning1_mid`,`relationtype_mid`,`meaning2_mid`),
 163+ KEY /*$wgWDprefix*/versioned_start_incoming (`add_transaction_id`,`meaning2_mid`,`relationtype_mid`,`meaning1_mid`),
 164+ KEY /*$wgWDprefix*/versioned_start_relation (`add_transaction_id`,`relation_id`)
 165+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 166+
 167+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/objects (
 168+ `object_id` int(11) NOT NULL auto_increment,
 169+ `table` varchar(100) collate utf8_bin NOT NULL,
 170+ `original_id` int(11) default NULL,
 171+ `UUID` varchar(36) collate utf8_bin NOT NULL,
 172+ PRIMARY KEY (`object_id`),
 173+ KEY `table` (`table`),
 174+ KEY `original_id` (`original_id`)
 175+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 176+
 177+-- attribute_id - refers to the object_id from xx_class_attributes
 178+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/option_attribute_options (
 179+ `option_id` int(11) NOT NULL default '0',
 180+ `attribute_id` int(11) NOT NULL default '0',
 181+ `option_mid` int(11) NOT NULL default '0',
 182+ `language_id` int(11) NOT NULL default '0',
 183+ `add_transaction_id` int(11) NOT NULL default '0',
 184+ `remove_transaction_id` int(11) default NULL,
 185+ KEY /*$wgWDprefix*/versioned_end_option (`remove_transaction_id`,`option_mid`,`attribute_id`,`option_id`),
 186+ KEY /*$wgWDprefix*/versioned_end_attribute (`remove_transaction_id`,`attribute_id`,`option_id`,`option_mid`),
 187+ KEY /*$wgWDprefix*/versioned_end_id (`remove_transaction_id`,`option_id`),
 188+ KEY /*$wgWDprefix*/versioned_start_option (`add_transaction_id`,`option_mid`,`attribute_id`,`option_id`),
 189+ KEY /*$wgWDprefix*/versioned_start_attribute (`add_transaction_id`,`attribute_id`,`option_id`,`option_mid`),
 190+ KEY /*$wgWDprefix*/versioned_start_id (`add_transaction_id`,`option_id`)
 191+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 192+
 193+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/option_attribute_values (
 194+ `value_id` int(11) NOT NULL default '0',
 195+ `object_id` int(11) NOT NULL default '0',
 196+ `option_id` int(11) NOT NULL default '0',
 197+ `add_transaction_id` int(11) NOT NULL default '0',
 198+ `remove_transaction_id` int(11) default NULL,
 199+ KEY /*$wgWDprefix*/versioned_end_object (`remove_transaction_id`,`object_id`,`option_id`,`value_id`),
 200+ KEY /*$wgWDprefix*/versioned_end_option (`remove_transaction_id`,`option_id`,`object_id`,`value_id`),
 201+ KEY /*$wgWDprefix*/versioned_end_value (`remove_transaction_id`,`value_id`),
 202+ KEY /*$wgWDprefix*/versioned_start_object (`add_transaction_id`,`object_id`,`option_id`,`value_id`),
 203+ KEY /*$wgWDprefix*/versioned_start_option (`add_transaction_id`,`option_id`,`object_id`,`value_id`),
 204+ KEY /*$wgWDprefix*/versioned_start_value (`add_transaction_id`,`value_id`)
 205+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 206+
 207+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/script_log (
 208+ `script_id` int(11) NOT NULL default '0',
 209+ `time` datetime NOT NULL default '0000-00-00 00:00:00',
 210+ `script_name` varchar(128) collate utf8_bin NOT NULL default '',
 211+ `comment` varchar(128) collate utf8_bin NOT NULL default ''
 212+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 213+
 214+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/syntrans (
 215+ `syntrans_sid` int(10) NOT NULL default '0',
 216+ `defined_meaning_id` int(10) NOT NULL default '0',
 217+ `expression_id` int(10) NOT NULL,
 218+ `identical_meaning` tinyint(1) NOT NULL default '0',
 219+ `add_transaction_id` int(11) NOT NULL,
 220+ `remove_transaction_id` int(11) default NULL,
 221+ KEY /*$wgWDprefix*/versioned_end_syntrans (`remove_transaction_id`,`syntrans_sid`),
 222+ KEY /*$wgWDprefix*/versioned_end_expression (`remove_transaction_id`,`expression_id`,`identical_meaning`,`defined_meaning_id`),
 223+ KEY /*$wgWDprefix*/versioned_end_defined_meaning (`remove_transaction_id`,`defined_meaning_id`,`identical_meaning`,`expression_id`),
 224+ KEY /*$wgWDprefix*/versioned_start_syntrans (`add_transaction_id`,`syntrans_sid`),
 225+ KEY /*$wgWDprefix*/versioned_start_expression (`add_transaction_id`,`expression_id`,`identical_meaning`,`defined_meaning_id`),
 226+ KEY /*$wgWDprefix*/versioned_start_defined_meaning (`add_transaction_id`,`defined_meaning_id`,`identical_meaning`,`expression_id`)
 227+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 228+
 229+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/text (
 230+ `text_id` int(8) unsigned NOT NULL auto_increment,
 231+ `text_text` mediumblob NOT NULL,
 232+ `text_flags` tinyblob default NULL,
 233+ PRIMARY KEY (`text_id`)
 234+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 235+
 236+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/text_attribute_values (
 237+ `value_id` int(11) NOT NULL,
 238+ `object_id` int(11) NOT NULL,
 239+ `attribute_mid` int(11) NOT NULL,
 240+ `text` mediumblob NOT NULL,
 241+ `add_transaction_id` int(11) NOT NULL,
 242+ `remove_transaction_id` int(11) default NULL,
 243+ KEY /*$wgWDprefix*/versioned_end_object (`remove_transaction_id`,`object_id`,`attribute_mid`,`value_id`),
 244+ KEY /*$wgWDprefix*/versioned_end_attribute (`remove_transaction_id`,`attribute_mid`,`object_id`,`value_id`),
 245+ KEY /*$wgWDprefix*/versioned_end_value (`remove_transaction_id`,`value_id`),
 246+ KEY /*$wgWDprefix*/versioned_start_object (`add_transaction_id`,`object_id`,`attribute_mid`,`value_id`),
 247+ KEY /*$wgWDprefix*/versioned_start_attribute (`add_transaction_id`,`attribute_mid`,`object_id`,`value_id`),
 248+ KEY /*$wgWDprefix*/versioned_start_value (`add_transaction_id`,`value_id`)
 249+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 250+
 251+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/transactions (
 252+ `transaction_id` int(11) NOT NULL auto_increment,
 253+ `user_id` int(5) NOT NULL,
 254+ `user_ip` varchar(15) NOT NULL,
 255+ `timestamp` varchar(14) NOT NULL,
 256+ `comment` tinyblob NOT NULL,
 257+ PRIMARY KEY (`transaction_id`),
 258+ KEY `user` (`user_id`,`transaction_id`)
 259+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 260+
 261+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/translated_content (
 262+ `translated_content_id` int(11) NOT NULL default '0',
 263+ `language_id` int(10) NOT NULL default '0',
 264+ `text_id` int(10) NOT NULL default '0',
 265+ `add_transaction_id` int(11) NOT NULL,
 266+ `remove_transaction_id` int(11) default NULL,
 267+ KEY /*$wgWDprefix*/versioned_end_translated_content (`remove_transaction_id`,`translated_content_id`,`language_id`,`text_id`),
 268+ KEY /*$wgWDprefix*/versioned_end_text (`remove_transaction_id`,`text_id`,`translated_content_id`,`language_id`),
 269+ KEY /*$wgWDprefix*/versioned_start_translated_content (`add_transaction_id`,`translated_content_id`,`language_id`,`text_id`),
 270+ KEY /*$wgWDprefix*/versioned_start_text (`add_transaction_id`,`text_id`,`translated_content_id`,`language_id`)
 271+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 272+
 273+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/translated_content_attribute_values (
 274+ `value_id` int(11) NOT NULL default '0',
 275+ `object_id` int(11) NOT NULL,
 276+ `attribute_mid` int(11) NOT NULL,
 277+ `value_tcid` int(11) NOT NULL,
 278+ `add_transaction_id` int(11) NOT NULL,
 279+ `remove_transaction_id` int(11) default NULL,
 280+ KEY /*$wgWDprefix*/versioned_end_object (`remove_transaction_id`,`object_id`,`attribute_mid`,`value_tcid`),
 281+ KEY /*$wgWDprefix*/versioned_end_attribute (`remove_transaction_id`,`attribute_mid`,`object_id`,`value_tcid`),
 282+ KEY /*$wgWDprefix*/versioned_end_translated_content (`remove_transaction_id`,`value_tcid`,`value_id`),
 283+ KEY /*$wgWDprefix*/versioned_end_value (`remove_transaction_id`,`value_id`),
 284+ KEY /*$wgWDprefix*/versioned_start_object (`add_transaction_id`,`object_id`,`attribute_mid`,`value_tcid`),
 285+ KEY /*$wgWDprefix*/versioned_start_attribute (`add_transaction_id`,`attribute_mid`,`object_id`,`value_tcid`),
 286+ KEY /*$wgWDprefix*/versioned_start_translated_content (`add_transaction_id`,`value_tcid`,`value_id`),
 287+ KEY /*$wgWDprefix*/versioned_start_value (`add_transaction_id`,`value_id`)
 288+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 289+
 290+CREATE TABLE IF NOT EXISTS /*$wgWDprefix*/url_attribute_values (
 291+ `value_id` int(11) NOT NULL,
 292+ `object_id` int(11) NOT NULL,
 293+ `attribute_mid` int(11) NOT NULL,
 294+ `url` varchar(255) collate utf8_bin NOT NULL,
 295+ `label` varchar(255) collate utf8_bin NOT NULL,
 296+ `add_transaction_id` int(11) NOT NULL,
 297+ `remove_transaction_id` int(11) default NULL,
 298+ KEY /*$wgWDprefix*/versioned_end_object (`remove_transaction_id`,`object_id`,`attribute_mid`,`value_id`),
 299+ KEY /*$wgWDprefix*/versioned_end_attribute (`remove_transaction_id`,`attribute_mid`,`object_id`,`value_id`),
 300+ KEY /*$wgWDprefix*/versioned_end_value (`remove_transaction_id`,`value_id`),
 301+ KEY /*$wgWDprefix*/versioned_start_object (`add_transaction_id`,`object_id`,`attribute_mid`,`value_id`),
 302+ KEY /*$wgWDprefix*/versioned_start_attribute (`add_transaction_id`,`attribute_mid`,`object_id`,`value_id`),
 303+ KEY /*$wgWDprefix*/versioned_start_value (`add_transaction_id`,`value_id`)
 304+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
 305+
Property changes on: trunk/extensions/Wikidata/Console/wikidataTemplate.sql
___________________________________________________________________
Added: svn:eol-style
1306 + native
Index: trunk/extensions/Wikidata/Console/installWikidata.php
@@ -0,0 +1,243 @@
 2+<?php
 3+
 4+/**
 5+* Maintenance script to create a wikidata extension for mediawiki
 6+* it generates the tables in a database (passed as parameter) with a defined prefix (passed as parameter)
 7+*/
 8+
 9+$baseDir = dirname( __FILE__ ) . '/../../..' ;
 10+require_once( $baseDir . '/maintenance/Maintenance.php' );
 11+
 12+echo "start\n";
 13+
 14+class InstallWikidata extends Maintenance {
 15+
 16+ public function __construct() {
 17+ parent::__construct();
 18+ $this->mDescription = "Install Wikidata by creating the tables and filling them with the minimal necessary data\n"
 19+ . 'Example usage: php installWikidata.php --prefix=uw '
 20+ . '--template=wikidataTemplate.sql --datasetname="OmegaWiki community"' ;
 21+ $this->addOption( 'prefix', 'The prefix to use for Wikidata relational tables. e.g. --prefix=uw' );
 22+ $this->addOption( 'template', 'A sql template describing the relational tables. e.g. --template=wikidataTemplate.sql' );
 23+ $this->addOption( 'datasetname', 'A name for your dataset. e.g. --datasetname="OmegaWiki community"' );
 24+ }
 25+
 26+ public function execute() {
 27+
 28+ global $wdCurrentContext;
 29+
 30+ // checking that the needed parameters are given
 31+ if ( !$this->hasOption( 'prefix' ) ) {
 32+ $this->output( "A prefix is missing. Use for example --prefix=uw\n");
 33+ exit(0);
 34+ }
 35+ if ( !$this->hasOption( 'template' ) ) {
 36+ $this->output( "A template is missing. Use for example --template=wikidataTemplate.sql\n");
 37+ exit(0);
 38+ }
 39+
 40+ $prefix = $this->getOption( 'prefix' );
 41+ $template = $this->getOption( 'template' );
 42+ $datasetname = $this->getOption( 'datasetname' );
 43+ $wdCurrentContext = $prefix ;
 44+
 45+ $this->output( "Creating Wikidata tables...\n" );
 46+
 47+ $this->ReadTemplateSQLFile( "/*\$wgWDprefix*/", $prefix . "_", dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $template );
 48+
 49+ // entering dataset in table wikidata_sets
 50+ $dbw = wfGetDB( DB_MASTER );
 51+ $dbw->query( "DELETE FROM wikidata_sets WHERE set_prefix = '$prefix'" );
 52+ $dbw->query( "INSERT INTO wikidata_sets (set_prefix,set_fallback_name,set_dmid) VALUES ('$prefix','$datasetname',0)" );
 53+
 54+ $this->output( "Adding language English...\n" );
 55+ $this->createLanguageEnglish( $prefix );
 56+
 57+ $this->output( "Filling table {$prefix}_bootstrapped_defined_meanings...\n" );
 58+ $this->bootStrappedDefinedMeanings( $prefix );
 59+
 60+ $this->output( "Adding some more data to enable annotations...\n" );
 61+ $this->enableAnnotations( $prefix );
 62+ }
 63+
 64+
 65+ protected function createLanguageEnglish( $dc ) {
 66+ $dbw = wfGetDB( DB_MASTER );
 67+
 68+ $langname = "English";
 69+ $langiso6392 = "en";
 70+ $langiso6393 = "eng";
 71+ $langwmf = "en";
 72+ $sql = 'INSERT IGNORE INTO language(language_id, iso639_2,iso639_3,wikimedia_key) values('
 73+ . WD_ENGLISH_LANG_ID . ','
 74+ . $dbw->addQuotes( $langiso6392 ) . ','
 75+ . $dbw->addQuotes( $langiso6393 ) . ','
 76+ . $dbw->addQuotes( $langwmf ) . ')';
 77+
 78+ $dbw->query( $sql );
 79+
 80+ $sql = 'INSERT IGNORE INTO language_names(language_id,name_language_id,language_name) values ('
 81+ . WD_ENGLISH_LANG_ID . ','
 82+ . WD_ENGLISH_LANG_ID . ','
 83+ . $dbw->addQuotes( $langname ) . ')';
 84+ $dbw->query( $sql );
 85+ }
 86+
 87+ protected function bootStrappedDefinedMeanings( $dc ) {
 88+ // Admin user
 89+ $userId = 1 ;
 90+ $dbw = wfGetDB( DB_MASTER );
 91+
 92+ // check that it is really a fresh install
 93+ $query = "SELECT * FROM {$dc}_collection" ;
 94+ $queryResult = $dbw->query( $query );
 95+ if ( $dbw->numRows( $queryResult ) > 0 ) {
 96+ echo "Table {$dc}_collection not empty.\n" ;
 97+ echo "\nERROR: It appears that Wikidata is at least already partially installed on your system\n" ;
 98+ echo "\nIf you would like to do a fresh install, drop the following tables, and run the install script again:\n" ;
 99+ $this->printDropTablesCommand( $dc );
 100+ exit(0);
 101+ }
 102+
 103+
 104+ startNewTransaction( $userId, 0, "Script bootstrap class attribute meanings", $dc );
 105+ $collectionId = bootstrapCollection( "Class attribute levels", WD_ENGLISH_LANG_ID, "LEVL", $dc );
 106+
 107+ $definedMeaningMeaningName = "DefinedMeaning";
 108+ $definitionMeaningName = "Definition";
 109+ $relationMeaningName = "Relation";
 110+ $synTransMeaningName = "SynTrans";
 111+ $annotationMeaningName = "Annotation";
 112+
 113+ $meanings = array();
 114+ $meanings[$definedMeaningMeaningName] = $this->bootstrapDefinedMeaning( $definedMeaningMeaningName, WD_ENGLISH_LANG_ID, "The combination of an expression and definition in one language defining a concept." );
 115+ $meanings[$definitionMeaningName] = $this->bootstrapDefinedMeaning( $definitionMeaningName, WD_ENGLISH_LANG_ID, "A paraphrase describing a concept." );
 116+ $meanings[$synTransMeaningName] = $this->bootstrapDefinedMeaning( $synTransMeaningName, WD_ENGLISH_LANG_ID, "A translation or a synonym that is equal or near equal to the concept defined by the defined meaning." );
 117+ $meanings[$relationMeaningName] = $this->bootstrapDefinedMeaning( $relationMeaningName, WD_ENGLISH_LANG_ID, "The association of two defined meanings through a specific relation type." );
 118+ $meanings[$annotationMeaningName] = $this->bootstrapDefinedMeaning( $annotationMeaningName, WD_ENGLISH_LANG_ID, "Characteristic information of a concept." );
 119+
 120+ foreach ( $meanings as $internalName => $meaningId ) {
 121+ addDefinedMeaningToCollection( $meaningId, $collectionId, $internalName );
 122+
 123+ $dbw->query( "INSERT INTO `{$dc}_bootstrapped_defined_meanings` (name, defined_meaning_id) " .
 124+ "VALUES (" . $dbw->addQuotes( $internalName ) . ", " . $meaningId . ")" );
 125+ }
 126+
 127+ }
 128+
 129+ protected function enableAnnotations( $dc ) {
 130+ // Admin user
 131+ $userId = 1 ;
 132+ $dbw = wfGetDB( DB_MASTER );
 133+
 134+ startNewTransaction( $userId, 0, "Script bootstrap class attribute meanings", $dc );
 135+
 136+ // a collection of classes. A word added to that collection becomes a class
 137+ $lexicalCollectionId = bootstrapCollection( "lexical functionality", WD_ENGLISH_LANG_ID, "CLAS", $dc );
 138+
 139+ // a collection of iso639-3 codes, to enable translation of the interface
 140+ // and language specific annotations
 141+ $iso6393CollectionId = bootstrapCollection( "ISO 639-3 codes", WD_ENGLISH_LANG_ID, "", $dc );
 142+
 143+ // DM lexical item, a class by default for every word
 144+ $lexicalItemDMId = $this->bootstrapDefinedMeaning( "lexical item", WD_ENGLISH_LANG_ID, "Lexical item is used as a class by default." );
 145+ addDefinedMeaningToCollection( $lexicalItemDMId, $lexicalCollectionId, "" );
 146+
 147+ // DM English, a class by default for English words
 148+ $englishDMId = $this->bootstrapDefinedMeaning( "English", WD_ENGLISH_LANG_ID,
 149+ "A West-Germanic language originating in England but now spoken in all parts of the British Isles,"
 150+ . " the Commonwealth of Nations, the United States of America, and other parts of the world."
 151+ );
 152+ addDefinedMeaningToCollection( $englishDMId, $lexicalCollectionId, "" );
 153+ addDefinedMeaningToCollection( $englishDMId, $iso6393CollectionId, "eng" );
 154+
 155+ echo "**\n";
 156+ echo "Add to your LocalSettings.php: \n";
 157+ echo '$wgDefaultClassMids = array(' . $lexicalItemDMId . ");\n";
 158+ echo '$wgIso639_3CollectionId = ' . $iso6393CollectionId . ";\n";
 159+ echo "**\n";
 160+ }
 161+
 162+ protected function bootstrapDefinedMeaning( $spelling, $languageId, $definition ) {
 163+ $expression = findOrCreateExpression( $spelling, $languageId );
 164+ $definedMeaningId = createNewDefinedMeaning( $expression->id, $languageId, $definition );
 165+
 166+ return $definedMeaningId;
 167+ }
 168+
 169+
 170+ protected function printDropTablesCommand( $dc ) {
 171+ $dropCommand = "drop table ";
 172+ $dropCommand .= $dc . "_alt_meaningtexts, ";
 173+ $dropCommand .= $dc . "_bootstrapped_defined_meanings, ";
 174+ $dropCommand .= $dc . "_class_attributes, ";
 175+ $dropCommand .= $dc . "_class_membership, ";
 176+ $dropCommand .= $dc . "_collection, ";
 177+ $dropCommand .= $dc . "_collection_contents, ";
 178+ $dropCommand .= $dc . "_collection_language, ";
 179+ $dropCommand .= $dc . "_defined_meaning, ";
 180+ $dropCommand .= $dc . "_expression, ";
 181+ $dropCommand .= $dc . "_meaning_relations, ";
 182+ $dropCommand .= $dc . "_objects, ";
 183+ $dropCommand .= $dc . "_option_attribute_options, ";
 184+ $dropCommand .= $dc . "_option_attribute_values, ";
 185+ $dropCommand .= $dc . "_script_log, ";
 186+ $dropCommand .= $dc . "_syntrans, ";
 187+ $dropCommand .= $dc . "_text, ";
 188+ $dropCommand .= $dc . "_text_attribute_values, ";
 189+ $dropCommand .= $dc . "_transactions, ";
 190+ $dropCommand .= $dc . "_translated_content, ";
 191+ $dropCommand .= $dc . "_translated_content_attribute_values, ";
 192+ $dropCommand .= $dc . "_url_attribute_values ";
 193+
 194+ echo "\n\n$dropCommand\n\n";
 195+ }
 196+
 197+ protected function ReadTemplateSQLFile( $pattern, $prefix, $filename ) {
 198+ $dbw = wfGetDB( DB_MASTER );
 199+
 200+ $fp = fopen( $filename, 'r' );
 201+ if ( false === $fp ) {
 202+ return "Could not open \"{$filename}\".\n";
 203+ }
 204+
 205+ $cmd = "";
 206+ $done = false;
 207+
 208+ while ( ! feof( $fp ) ) {
 209+ $line = trim( fgets( $fp, 1024 ) );
 210+ $sl = strlen( $line ) - 1;
 211+
 212+ if ( $sl < 0 ) { continue; }
 213+ if ( '-' == $line { 0 } && '-' == $line { 1 } ) { continue; }
 214+
 215+ if ( ';' == $line { $sl } && ( $sl < 2 || ';' != $line { $sl - 1 } ) ) {
 216+ $done = true;
 217+ $line = substr( $line, 0, $sl );
 218+ }
 219+
 220+ if ( '' != $cmd ) { $cmd .= ' '; }
 221+ $cmd .= "$line\n";
 222+
 223+ if ( $done ) {
 224+ $cmd = str_replace( ';;', ";", $cmd );
 225+ $cmd = trim( str_replace( $pattern, $prefix, $cmd ) );
 226+
 227+ $res = $dbw->query( $cmd );
 228+
 229+ if ( false === $res ) {
 230+ return "Query \"{$cmd}\" failed with error code \".\n";
 231+ }
 232+
 233+ $cmd = '';
 234+ $done = false;
 235+ }
 236+ }
 237+ fclose( $fp );
 238+ return true;
 239+ }
 240+
 241+}
 242+
 243+$maintClass = 'InstallWikidata';
 244+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
Property changes on: trunk/extensions/Wikidata/Console/installWikidata.php
___________________________________________________________________
Added: svn:eol-style
1245 + native

Status & tagging log