r22819 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22818‎ | r22819 | r22820 >
Date:18:55, 7 June 2007
Author:kim
Status:old
Tags:
Comment:
i18n + refactoring many WikidataAPI functions to accept $dc as parameter.
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/Database+scripts/Convenience/Create+wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -84,6 +84,31 @@
8585 'ow_uipref_datasets' => 'Default view',
8686 'ow_uiprefs' => 'Wikidata',
8787 'ow_none_selected' => '<None selected>',
 88+ 'ow_conceptmapping_help' => "<p>possible actions: <ul>
 89+ <li>&action=insert&<data_context_prefix>=<defined_id>&... insert a mapping</li>
 90+ <li>&action=get&concept=<concept_id> read a mapping back</li>
 91+ <li>&action=list_sets return a list of possible data context prefixes and what they refer to.</li>
 92+ <li>&action=get_associated&dm=<defined_meaning_id>&dc=<dataset_context_prefix> for one defined meaning in a concept, return all others</li>
 93+ <li>&action=help Show helpful help.</li>
 94+ </ul></p>",
 95+ 'ow_conceptmapping_uitext' => "
 96+ <p>Concept Mapping allows you to identify
 97+ which defined meaning in one dataset is identical
 98+ to defined meanings in other datasets.</p>\n
 99+ <p>Please enter or cut and paste the defined
 100+ meanings (with id), or simply the defined meaning ids
 101+ which are identical.</p>\n
 102+ <p> For example, you could paste <code>DefinedMeaning:Boat (7774)</code>
 103+ or simply type <code>7774</code>.</p>\n",
 104+ 'ow_conceptmapping_no_action_specified'=>"Apologies, I don't know how to '$1'.",
 105+ 'ow_OK'=>'OK',
 106+ 'ow_not_present_or_malformed'=>'not present or malformed',
 107+ 'ow_mapping_successful'=>"Mapped all fields marked with [OK]<br>\n",
 108+ 'ow_mapping_unsuccessful'=>"Need to have at least two defined meanings before I can link them.\n",
 109+ 'ow_will_insert'=>"Will insert the following:",
 110+ 'ow_contents_of_mapping'=>'Contents of mapping',
 111+ 'ow_available_contexts'=>'Available contexts',
 112+ 'add_concept_link'=>'Add link to other concepts'
88113 )
89114 );
90115
Index: trunk/extensions/Wikidata/Database scripts/Convenience/Create wikidata.php
@@ -3,9 +3,12 @@
44 # this module create a wikidata extension for mediawiki
55 # it generates the tables in a database (passed as parameter) with a defined prefix (passed as parameter)
66
 7+define('MEDIAWIKI', true );
 8+
79 $wgUseMasterForMaintenance = true;
 10+require_once( "../../../../LocalSettings.php");
811 require_once( "../../../../maintenance/commandLine.inc");
9 -#require_once( "../../../../LocalSettings.php");
 12+require_once( "../../OmegaWiki/WikiDataAPI.php");
1013 #require_once( "install-utils.inc" );
1114 #require_once( "AdminSettings.php");
1215 #require_once( "GlobalFunctions.php" );
@@ -125,6 +128,8 @@
126129 ReadSQLFile( $wdDatabase, "/*\$wgWDprefix*/", $wgWDprefix, $wgWDtemplate );
127130 $wdDatabase->query( "DELETE FROM wikidata_sets WHERE set_prefix = '$prefix'" );
128131 $wdDatabase->query( "INSERT INTO wikidata_sets (set_prefix,set_fallback_name,set_dmid) VALUES ('$prefix','$comment',0)" );
 132+bootstrapCollection("datasets",85,"MAPP",$wgWDprefix);
 133+
129134 $wdDatabase->close();
130135
131 -?>
\ No newline at end of file
 136+?>
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -163,7 +163,7 @@
164164 }
165165 $cmtitle=Title::newFromText("Special:ConceptMapping");
166166 $titleText=$wgTitle->getPrefixedURL();
167 - $cmlink=$sk->makeLinkObj($cmtitle,"<small>Add link to other concepts</small>","set_$dc=$titleText&suppressWarnings=true");
 167+ $cmlink=$sk->makeLinkObj($cmtitle,"<small>".wfMsg("add_concept_link")."</small>","set_$dc=$titleText&suppressWarnings=true");
168168 $html.="<tr><td>$cmlink</td></tr>\n";
169169 $html.="</table>\n";
170170 $html.="</div>\n";
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -26,17 +26,17 @@
2727 return createPage($expressionNameSpaceId, getPageTitle($this->spelling));
2828 }
2929
30 - function isBoundToDefinedMeaning($definedMeaningId) {
31 - return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id);
 30+ function isBoundToDefinedMeaning($definedMeaningId, $dc=null) {
 31+ return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id, $dc);
3232 }
3333
34 - function bindToDefinedMeaning($definedMeaningId, $identicalMeaning) {
35 - createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning);
 34+ function bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) {
 35+ createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning, $dc);
3636 }
3737
38 - function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning) {
39 - if (!$this->isBoundToDefinedMeaning($definedMeaningId))
40 - $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning);
 38+ function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) {
 39+ if (!$this->isBoundToDefinedMeaning($definedMeaningId, $dc))
 40+ $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc);
4141 }
4242 }
4343
@@ -78,9 +78,9 @@
7979 return "";
8080 }
8181
82 -function getExpressionId($spelling, $languageId) {
 82+function getExpressionId($spelling, $languageId, $dc=null) {
8383
84 - $dc=wdGetDataSetContext();
 84+ $dc=wdGetDataSetContext($dc);
8585
8686 $dbr = &wfGetDB(DB_SLAVE);
8787 $sql = "SELECT expression_id FROM {$dc}_expression_ns " .
@@ -91,9 +91,10 @@
9292 return isset($expression->expression_id) ? $expression->expression_id : null;
9393 }
9494
95 -function createExpressionId($spelling, $languageId) {
 95+function createExpressionId($spelling, $languageId, $dc=null) {
9696
97 - $dc=wdGetDataSetContext();
 97+ $dc=wdGetDataSetContext($dc);
 98+ wfDebug("Context : $dc");
9899
99100 $expressionId = newObjectId("{$dc}_expression_ns");
100101
@@ -146,24 +147,24 @@
147148 return $revisionId;
148149 }
149150
150 -function findExpression($spelling, $languageId) {
151 - if ($expressionId = getExpressionId($spelling, $languageId))
 151+function findExpression($spelling, $languageId, $dc=null) {
 152+ if ($expressionId = getExpressionId($spelling, $languageId, $dc))
152153 return new Expression($expressionId, $spelling, $languageId);
153154 else
154155 return null;
155156 }
156157
157 -function createExpression($spelling, $languageId) {
158 - $expression = new Expression(createExpressionId($spelling, $languageId), $spelling, $languageId);
 158+function createExpression($spelling, $languageId, $dc=null) {
 159+ $expression = new Expression(createExpressionId($spelling, $languageId, $dc), $spelling, $languageId);
159160 $expression->createNewInDatabase();
160161 return $expression;
161162 }
162163
163 -function findOrCreateExpression($spelling, $languageId) {
164 - if ($expression = findExpression($spelling, $languageId))
 164+function findOrCreateExpression($spelling, $languageId, $dc=null) {
 165+ if ($expression = findExpression($spelling, $languageId, $dc))
165166 return $expression;
166167 else
167 - return createExpression($spelling, $languageId);
 168+ return createExpression($spelling, $languageId, $dc);
168169 }
169170
170171 function getSynonymId($definedMeaningId, $expressionId) {
@@ -178,9 +179,9 @@
179180 return 0;
180181 }
181182
182 -function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning) {
 183+function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning, $dc=null) {
183184
184 - $dc=wdGetDataSetContext();
 185+ $dc=wdGetDataSetContext($dc);
185186
186187 $synonymId = getSynonymId($definedMeaningId, $expressionId);
187188
@@ -194,8 +195,8 @@
195196 $queryResult = $dbr->query($sql);
196197 }
197198
198 -function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId) {
199 - $dc=wdGetDataSetContext();
 199+function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId, $dc=null) {
 200+ $dc=wdGetDataSetContext($dc);
200201 $dbr = &wfGetDB(DB_SLAVE);
201202 $queryResult = $dbr->query("SELECT expression_id FROM {$dc}_syntrans WHERE expression_id=$expressionId AND defined_meaning_id=$definedMeaningId AND ". getLatestTransactionRestriction("{$dc}_syntrans") ." LIMIT 1");
202203
@@ -431,8 +432,8 @@
432433 addTranslatedText($setId, $languageId, $text);
433434 }
434435
435 -function createText($text) {
436 - $dc=wdGetDataSetContext();
 436+function createText($text, $dc=null) {
 437+ $dc=wdGetDataSetContext($dc);
437438 $dbr = &wfGetDB(DB_MASTER);
438439 $text = $dbr->addQuotes($text);
439440 $sql = "insert into {$dc}_text(text_text) values($text)";
@@ -441,8 +442,8 @@
442443 return $dbr->insertId();
443444 }
444445
445 -function createTranslatedContent($translatedContentId, $languageId, $textId) {
446 - $dc=wdGetDataSetContext();
 446+function createTranslatedContent($translatedContentId, $languageId, $textId, $dc=null) {
 447+ $dc=wdGetDataSetContext($dc);
447448
448449 $dbr = &wfGetDB(DB_MASTER);
449450 $sql = "insert into {$dc}_translated_content(translated_content_id,language_id,text_id,add_transaction_id) values($translatedContentId, $languageId, $textId, ". getUpdateTransactionId() .")";
@@ -451,8 +452,8 @@
452453 return $dbr->insertId();
453454 }
454455
455 -function translatedTextExists($textId, $languageId) {
456 - $dc=wdGetDataSetContext();
 456+function translatedTextExists($textId, $languageId, $dc=null) {
 457+ $dc=wdGetDataSetContext($dc);
457458 $dbr = &wfGetDB(DB_SLAVE);
458459 $queryResult = $dbr->query(
459460 "SELECT translated_content_id" .
@@ -465,18 +466,18 @@
466467 return $dbr->numRows($queryResult) > 0;
467468 }
468469
469 -function addTranslatedText($translatedContentId, $languageId, $text) {
470 - $textId = createText($text);
471 - createTranslatedContent($translatedContentId, $languageId, $textId);
 470+function addTranslatedText($translatedContentId, $languageId, $text,$dc=null) {
 471+ $textId = createText($text, $dc);
 472+ createTranslatedContent($translatedContentId, $languageId, $textId, $dc);
472473 }
473474
474 -function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text) {
475 - if (!translatedTextExists($translatedContentId, $languageId))
476 - addTranslatedText($translatedContentId, $languageId, $text);
 475+function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text, $dc=null) {
 476+ if (!translatedTextExists($translatedContentId, $languageId, $dc))
 477+ addTranslatedText($translatedContentId, $languageId, $text, $dc);
477478 }
478479
479 -function getDefinedMeaningDefinitionId($definedMeaningId) {
480 - $dc=wdGetDataSetContext();
 480+function getDefinedMeaningDefinitionId($definedMeaningId, $dc=null) {
 481+ $dc=wdGetDataSetContext($dc);
481482 $dbr = &wfGetDB(DB_SLAVE);
482483 $queryResult = $dbr->query("SELECT meaning_text_tcid FROM {$dc}_defined_meaning WHERE defined_meaning_id=$definedMeaningId " .
483484 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning"));
@@ -484,9 +485,9 @@
485486 return $dbr->fetchObject($queryResult)->meaning_text_tcid;
486487 }
487488
488 -function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId) {
 489+function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc=null) {
489490 $dbr = &wfGetDB(DB_MASTER);
490 - $dc=wdGetDataSetContext();
 491+ $dc=wdGetDataSetContext($dc);
491492 $dbr->query("UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" .
492493 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning"));
493494 }
@@ -496,19 +497,19 @@
497498 return newObjectId("{$dc}_translated_content");
498499 }
499500
500 -function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text) {
 501+function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc=null) {
501502 $definitionId = newTranslatedContentId();
502 - addTranslatedText($definitionId, $languageId, $text);
503 - updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId);
 503+ addTranslatedText($definitionId, $languageId, $text, $dc);
 504+ updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc);
504505 }
505506
506 -function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text) {
507 - $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
 507+function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text, $dc=null) {
 508+ $definitionId = getDefinedMeaningDefinitionId($definedMeaningId, $dc);
508509
509510 if ($definitionId == 0)
510 - addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text);
 511+ addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc);
511512 else
512 - addTranslatedTextIfNotPresent($definitionId, $languageId, $text);
 513+ addTranslatedTextIfNotPresent($definitionId, $languageId, $text, $dc);
513514 }
514515
515516 function createDefinedMeaningAlternativeDefinition($definedMeaningId, $translatedContentId, $sourceMeaningId) {
@@ -606,12 +607,12 @@
607608 addDefinedMeaningToCollection($definedMeaningId, $collectionId, $internalId);
608609 }
609610
610 -function bootstrapCollection($collection, $languageId, $collectionType){
611 - $expression = findOrCreateExpression($collection, $languageId);
612 - $definedMeaningId = addDefinedMeaning($expression->id);
613 - $expression->assureIsBoundToDefinedMeaning($definedMeaningId, true);
614 - addDefinedMeaningDefinition($definedMeaningId, $languageId, $collection);
615 - return addCollection($definedMeaningId, $collectionType);
 611+function bootstrapCollection($collection, $languageId, $collectionType,$dc=null){
 612+ $expression = findOrCreateExpression($collection, $languageId, $dc);
 613+ $definedMeaningId = addDefinedMeaning($expression->id, $dc);
 614+ $expression->assureIsBoundToDefinedMeaning($definedMeaningId, true, $dc);
 615+ addDefinedMeaningDefinition($definedMeaningId, $languageId, $collection, $dc);
 616+ return addCollection($definedMeaningId, $collectionType, $dc);
616617 }
617618
618619 function getCollectionMeaningId($collectionId) {
@@ -632,8 +633,8 @@
633634 return $dbr->fetchObject($queryResult)->collection_id;
634635 }
635636
636 -function addCollection($definedMeaningId, $collectionType) {
637 - $dc=wdGetDataSetContext();
 637+function addCollection($definedMeaningId, $collectionType, $dc=null) {
 638+ $dc=wdGetDataSetContext($dc);
638639 $collectionId = newObjectId("{$dc}_collection_ns");
639640
640641 $dbr = &wfGetDB(DB_MASTER);
@@ -643,9 +644,9 @@
644645 return $collectionId;
645646 }
646647
647 -function addDefinedMeaning($definingExpressionId) {
 648+function addDefinedMeaning($definingExpressionId, $dc=null) {
648649 $definedMeaningNameSpaceId = Namespace::getIndexForName('definedmeaning');
649 - $dc=wdGetDataSetContext();
 650+ $dc=wdGetDataSetContext($dc);
650651
651652 $definedMeaningId = newObjectId("{$dc}_defined_meaning");
652653
@@ -759,8 +760,8 @@
760761 "VALUES ($valueId, $objectId, $attributeId, $translatedContentId, ". getUpdateTransactionId() .")");
761762 }
762763
763 -function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text) {
764 - $dc=wdGetDataSetContext();
 764+function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text, $dc) {
 765+ $dc=wdGetDataSetContext($dc);
765766 $translatedTextValueAttributeId = newObjectId("{$dc}_translated_content_attribute_values");
766767 $translatedContentId = newTranslatedContentId();
767768
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -72,7 +72,7 @@
7373 http.onreadystatechange = function() {
7474 if (http.readyState == 4) {
7575 var newTable = document.createElement('div');
76 -
 76+ //alert(http.responseText);
7777 if (http.responseText != '') {
7878 newTable.innerHTML = leftTrim(http.responseText);
7979 table.parentNode.replaceChild(newTable.firstChild, table);
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php
@@ -17,18 +17,6 @@
1818 'author' => 'Kim Bruning',
1919 );
2020
21 -define('help_text',
22 - "<p>possible actions: <ul>
23 - <li>&action=insert&<data_context_prefix>=<defined_id>&... insert a mapping</li>
24 - <li>&action=get&concept=<concept_id> read a mapping back</li>
25 - <li>&action=list_sets return a list of possible data context prefixes and what they refer to.</li>
26 - <li>&action=get_associated&dm=<defined_meaning_id>&dc=<dataset_context_prefix> for one defined meaning in a concept, return all others</li>
27 - <li>&action=help Show helpful help.</li>
28 - </ul></p>"); #brief help message
29 -
30 -
31 -
32 -
3321 function wfSpecialConceptMapping() {
3422 # Add messages
3523 #require_once "$IP/includes/SpecialPage.php";
@@ -58,8 +46,8 @@
5947 } elseif ($action=="get_associated"){
6048 $this->get_associated();
6149 } else {
62 - $wgOut->addWikiText("Apologies, I don't know how to '$action'.");
63 - $wgOut->addWikiText(help_text);
 50+ $wgOut->addWikiText(wfMsg('ow_conceptmapping_no_action_specified',$action));
 51+ $wgOut->addWikiText(wfMsg('ow_conceptmapping_help'));
6452 }
6553 }
6654
@@ -67,16 +55,7 @@
6856 global $wgOut;
6957 require_once("forms.php");
7058
71 - $wgOut->addHTML("
72 - <p>Concept Mapping allows you to identify
73 - which defined meaning in one dataset is identical
74 - to defined meanings in other datasets.</p>\n
75 - <p>Please enter or cut and paste the defined
76 - meanings (with id), or simply the defined meaning ids
77 - which are identical.</p>\n
78 - <p> For example, you could paste <code>DefinedMeaning:Boat (7774)</code>
79 - or simply type <code>7774</code>.</p>\n");
80 -
 59+ $wgOut->addHTML(wfMsg('ow_conceptmapping_uitext'));
8160 $sets=wdGetDataSets();
8261 $options = array();
8362 $html="";
@@ -110,20 +89,20 @@
11190 if ($id!=null) {
11291 $mappings[$key]=$id;
11392 if(!$noerror) {
114 - $wgOut->addHTML(' <span style="color:green">[OK]</span>');
 93+ $wgOut->addHTML(' <span style="color:green">['.wfMsg('ow_OK').']</span>');
11594 }
11695 } else {
11796 if(!$noerror) {
118 - $wgOut->addHTML(' <span style="color:red">[not present or malformed]</span>');
 97+ $wgOut->addHTML(' <span style="color:red">['.wfMsg('ow_not_present_or_malformed').']</span>');
11998 }
12099 }
121100 $wgOut->addHTML("<br>\n");
122101 }
123102 if (sizeOf($mappings)>1) {
124103 createConceptMapping($mappings);
125 - $wgOut->addHTML("Mapped all fields marked with [OK]<br>\n");
 104+ $wgOut->addHTML(wfMsg('ow_mapping_successful'));
126105 } else {
127 - $wgOut->addHTML("Need to have at least two defined meanings before I can link them");
 106+ $wgOut->addHTML(wfMsg('ow_mapping_unsuccessful'));
128107 }
129108
130109 }
@@ -140,7 +119,7 @@
141120 protected function help() {
142121 global $wgOut;
143122 $wgOut->addWikiText("<h2>Help</h2>");
144 - $wgOut->addWikiText(help_text);
 123+ $wgOut->addWikiText(wfMsg('ow_conceptmapping_help'));
145124 }
146125
147126 protected function insert() {
@@ -150,7 +129,7 @@
151130 # $wgRequest->getText( 'page' );
152131 $sets=wdGetDataSets();
153132 #$requests=$wgRequest->getValues();
154 - $wgOut->addWikiText("<h2>Will insert the following:</h2>");
 133+ $wgOut->addWikiText("<h2>".wfMsg('ow_will_insert')."</h2>");
155134 $map=array();
156135 foreach ($sets as $key => $set) {
157136 $dc=$set->getPrefix();
@@ -171,7 +150,7 @@
172151 global
173152 $wgOut, $wgRequest;
174153 $concept_id=$wgRequest->getText("concept");
175 - $wgOut->addWikiText("<h2>Contents of mapping:</h2>");
 154+ $wgOut->addWikiText("<h2>".wfMsg('ow_contents_of_mapping')."</h2>");
176155 $map=readConceptMapping($concept_id);
177156 #$sets=wdGetDataSets();
178157
@@ -182,7 +161,7 @@
183162
184163 protected function list_sets() {
185164 global $wgOut;
186 - $wgOut->addWikiText("<h2>available contexts</h2>");
 165+ $wgOut->addWikiText("<h2>".wfMsg('available contexts')."</h2>");
187166 $sets=wdGetDataSets();
188167 foreach ($sets as $key => $set) {
189168 $name=$set->fetchName();

Status & tagging log