r23009 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23008‎ | r23009 | r23010 >
Date:11:53, 15 June 2007
Author:mulligen
Status:old
Tags:
Comment:
added a test for creating page with duplicate title/namespace
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -26,17 +26,17 @@
2727 return createPage($expressionNameSpaceId, getPageTitle($this->spelling));
2828 }
2929
30 - function isBoundToDefinedMeaning($definedMeaningId, $dc=null) {
31 - return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id, $dc);
 30+ function isBoundToDefinedMeaning($definedMeaningId) {
 31+ return expressionIsBoundToDefinedMeaning($definedMeaningId, $this->id);
3232 }
3333
34 - function bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) {
35 - createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning, $dc);
 34+ function bindToDefinedMeaning($definedMeaningId, $identicalMeaning) {
 35+ createSynonymOrTranslation($definedMeaningId, $this->id, $identicalMeaning);
3636 }
3737
38 - function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc=null) {
39 - if (!$this->isBoundToDefinedMeaning($definedMeaningId, $dc))
40 - $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning, $dc);
 38+ function assureIsBoundToDefinedMeaning($definedMeaningId, $identicalMeaning) {
 39+ if (!$this->isBoundToDefinedMeaning($definedMeaningId))
 40+ $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning);
4141 }
4242 }
4343
@@ -58,7 +58,7 @@
5959
6060 $dbr = &wfGetDB(DB_MASTER);
6161 $dbr->query("INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (". $dbr->addQuotes($table) . ", UUID())");
62 -
 62+
6363 return $dbr->insertId();
6464 }
6565
@@ -73,14 +73,14 @@
7474 );
7575
7676 if ($objectRecord = $dbr->fetchObject($queryResult))
77 - return $objectRecord->table;
 77+ return $objectRecord->table;
7878 else
7979 return "";
8080 }
8181
82 -function getExpressionId($spelling, $languageId, $dc=null) {
 82+function getExpressionId($spelling, $languageId) {
8383
84 - $dc=wdGetDataSetContext($dc);
 84+ $dc=wdGetDataSetContext();
8585
8686 $dbr = &wfGetDB(DB_SLAVE);
8787 $sql = "SELECT expression_id FROM {$dc}_expression_ns " .
@@ -91,10 +91,9 @@
9292 return isset($expression->expression_id) ? $expression->expression_id : null;
9393 }
9494
95 -function createExpressionId($spelling, $languageId, $dc=null) {
 95+function createExpressionId($spelling, $languageId) {
9696
97 - $dc=wdGetDataSetContext($dc);
98 - wfDebug("Context : $dc");
 97+ $dc=wdGetDataSetContext();
9998
10099 $expressionId = newObjectId("{$dc}_expression_ns");
101100
@@ -115,11 +114,20 @@
116115 $title = $dbr->addQuotes($title);
117116 $timestamp = $dbr->timestamp();
118117
119 - $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) ".
120 - "values($namespace, $title, 1, $timestamp)";
121 - $dbr->query($sql);
122 -
123 - return $dbr->insertId();
 118+ echo "createPage(): namespace = $namespace and title = $title\n";
 119+ $sql = "select page_id from page where page_namespace = $namespace and page_title = $title";
 120+ $queryResult = $dbr->query($sql);
 121+ $page = $dbr->fetchObject($queryResult);
 122+ if (isset($page->page_id) ){
 123+ return $page->page_id;
 124+ }
 125+ else{
 126+ $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) ".
 127+ "values($namespace, $title, 1, $timestamp)";
 128+ $dbr->query($sql);
 129+
 130+ return $dbr->insertId();
 131+ }
124132 }
125133
126134 function setPageLatestRevision($pageId, $latestRevision) {
@@ -147,24 +155,29 @@
148156 return $revisionId;
149157 }
150158
151 -function findExpression($spelling, $languageId, $dc=null) {
152 - if ($expressionId = getExpressionId($spelling, $languageId, $dc))
 159+function findExpression($spelling, $languageId) {
 160+ wfDebug( "findExpression $spelling" );
 161+ if ($expressionId = getExpressionId($spelling, $languageId)){
 162+ //wfDebug( "expression $spelling found in database" );
 163+ //exit();
153164 return new Expression($expressionId, $spelling, $languageId);
154 - else
 165+ }
 166+ else{
155167 return null;
 168+ }
156169 }
157170
158 -function createExpression($spelling, $languageId, $dc=null) {
159 - $expression = new Expression(createExpressionId($spelling, $languageId, $dc), $spelling, $languageId);
 171+function createExpression($spelling, $languageId) {
 172+ $expression = new Expression(createExpressionId($spelling, $languageId), $spelling, $languageId);
160173 $expression->createNewInDatabase();
161174 return $expression;
162175 }
163176
164 -function findOrCreateExpression($spelling, $languageId, $dc=null) {
165 - if ($expression = findExpression($spelling, $languageId, $dc))
 177+function findOrCreateExpression($spelling, $languageId) {
 178+ if ($expression = findExpression($spelling, $languageId))
166179 return $expression;
167180 else
168 - return createExpression($spelling, $languageId, $dc);
 181+ return createExpression($spelling, $languageId);
169182 }
170183
171184 function getSynonymId($definedMeaningId, $expressionId) {
@@ -179,9 +192,9 @@
180193 return 0;
181194 }
182195
183 -function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning, $dc=null) {
 196+function createSynonymOrTranslation($definedMeaningId, $expressionId, $identicalMeaning) {
184197
185 - $dc=wdGetDataSetContext($dc);
 198+ $dc=wdGetDataSetContext();
186199
187200 $synonymId = getSynonymId($definedMeaningId, $expressionId);
188201
@@ -195,8 +208,8 @@
196209 $queryResult = $dbr->query($sql);
197210 }
198211
199 -function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId, $dc=null) {
200 - $dc=wdGetDataSetContext($dc);
 212+function expressionIsBoundToDefinedMeaning($definedMeaningId, $expressionId) {
 213+ $dc=wdGetDataSetContext();
201214 $dbr = &wfGetDB(DB_SLAVE);
202215 $queryResult = $dbr->query("SELECT expression_id FROM {$dc}_syntrans WHERE expression_id=$expressionId AND defined_meaning_id=$definedMeaningId AND ". getLatestTransactionRestriction("{$dc}_syntrans") ." LIMIT 1");
203216
@@ -432,8 +445,8 @@
433446 addTranslatedText($setId, $languageId, $text);
434447 }
435448
436 -function createText($text, $dc=null) {
437 - $dc=wdGetDataSetContext($dc);
 449+function createText($text) {
 450+ $dc=wdGetDataSetContext();
438451 $dbr = &wfGetDB(DB_MASTER);
439452 $text = $dbr->addQuotes($text);
440453 $sql = "insert into {$dc}_text(text_text) values($text)";
@@ -442,8 +455,8 @@
443456 return $dbr->insertId();
444457 }
445458
446 -function createTranslatedContent($translatedContentId, $languageId, $textId, $dc=null) {
447 - $dc=wdGetDataSetContext($dc);
 459+function createTranslatedContent($translatedContentId, $languageId, $textId) {
 460+ $dc=wdGetDataSetContext();
448461
449462 $dbr = &wfGetDB(DB_MASTER);
450463 $sql = "insert into {$dc}_translated_content(translated_content_id,language_id,text_id,add_transaction_id) values($translatedContentId, $languageId, $textId, ". getUpdateTransactionId() .")";
@@ -452,8 +465,8 @@
453466 return $dbr->insertId();
454467 }
455468
456 -function translatedTextExists($textId, $languageId, $dc=null) {
457 - $dc=wdGetDataSetContext($dc);
 469+function translatedTextExists($textId, $languageId) {
 470+ $dc=wdGetDataSetContext();
458471 $dbr = &wfGetDB(DB_SLAVE);
459472 $queryResult = $dbr->query(
460473 "SELECT translated_content_id" .
@@ -466,18 +479,18 @@
467480 return $dbr->numRows($queryResult) > 0;
468481 }
469482
470 -function addTranslatedText($translatedContentId, $languageId, $text,$dc=null) {
471 - $textId = createText($text, $dc);
472 - createTranslatedContent($translatedContentId, $languageId, $textId, $dc);
 483+function addTranslatedText($translatedContentId, $languageId, $text) {
 484+ $textId = createText($text);
 485+ createTranslatedContent($translatedContentId, $languageId, $textId);
473486 }
474487
475 -function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text, $dc=null) {
476 - if (!translatedTextExists($translatedContentId, $languageId, $dc))
477 - addTranslatedText($translatedContentId, $languageId, $text, $dc);
 488+function addTranslatedTextIfNotPresent($translatedContentId, $languageId, $text) {
 489+ if (!translatedTextExists($translatedContentId, $languageId))
 490+ addTranslatedText($translatedContentId, $languageId, $text);
478491 }
479492
480 -function getDefinedMeaningDefinitionId($definedMeaningId, $dc=null) {
481 - $dc=wdGetDataSetContext($dc);
 493+function getDefinedMeaningDefinitionId($definedMeaningId) {
 494+ $dc=wdGetDataSetContext();
482495 $dbr = &wfGetDB(DB_SLAVE);
483496 $queryResult = $dbr->query("SELECT meaning_text_tcid FROM {$dc}_defined_meaning WHERE defined_meaning_id=$definedMeaningId " .
484497 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning"));
@@ -485,9 +498,9 @@
486499 return $dbr->fetchObject($queryResult)->meaning_text_tcid;
487500 }
488501
489 -function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc=null) {
 502+function updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId) {
490503 $dbr = &wfGetDB(DB_MASTER);
491 - $dc=wdGetDataSetContext($dc);
 504+ $dc=wdGetDataSetContext();
492505 $dbr->query("UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" .
493506 " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning"));
494507 }
@@ -497,19 +510,19 @@
498511 return newObjectId("{$dc}_translated_content");
499512 }
500513
501 -function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc=null) {
 514+function addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text) {
502515 $definitionId = newTranslatedContentId();
503 - addTranslatedText($definitionId, $languageId, $text, $dc);
504 - updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId, $dc);
 516+ addTranslatedText($definitionId, $languageId, $text);
 517+ updateDefinedMeaningDefinitionId($definedMeaningId, $definitionId);
505518 }
506519
507 -function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text, $dc=null) {
508 - $definitionId = getDefinedMeaningDefinitionId($definedMeaningId, $dc);
 520+function addDefinedMeaningDefinition($definedMeaningId, $languageId, $text) {
 521+ $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
509522
510523 if ($definitionId == 0)
511 - addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text, $dc);
 524+ addDefinedMeaningDefiningDefinition($definedMeaningId, $languageId, $text);
512525 else
513 - addTranslatedTextIfNotPresent($definitionId, $languageId, $text, $dc);
 526+ addTranslatedTextIfNotPresent($definitionId, $languageId, $text);
514527 }
515528
516529 function createDefinedMeaningAlternativeDefinition($definedMeaningId, $translatedContentId, $sourceMeaningId) {
@@ -607,12 +620,12 @@
608621 addDefinedMeaningToCollection($definedMeaningId, $collectionId, $internalId);
609622 }
610623
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);
 624+function bootstrapCollection($collection, $languageId, $collectionType){
 625+ $expression = findOrCreateExpression($collection, $languageId);
 626+ $definedMeaningId = addDefinedMeaning($expression->id);
 627+ $expression->assureIsBoundToDefinedMeaning($definedMeaningId, true);
 628+ addDefinedMeaningDefinition($definedMeaningId, $languageId, $collection);
 629+ return addCollection($definedMeaningId, $collectionType);
617630 }
618631
619632 function getCollectionMeaningId($collectionId) {
@@ -633,8 +646,8 @@
634647 return $dbr->fetchObject($queryResult)->collection_id;
635648 }
636649
637 -function addCollection($definedMeaningId, $collectionType, $dc=null) {
638 - $dc=wdGetDataSetContext($dc);
 650+function addCollection($definedMeaningId, $collectionType) {
 651+ $dc=wdGetDataSetContext();
639652 $collectionId = newObjectId("{$dc}_collection_ns");
640653
641654 $dbr = &wfGetDB(DB_MASTER);
@@ -644,15 +657,18 @@
645658 return $collectionId;
646659 }
647660
648 -function addDefinedMeaning($definingExpressionId, $dc=null) {
 661+function addDefinedMeaning($definingExpressionId) {
649662 $definedMeaningNameSpaceId = Namespace::getIndexForName('definedmeaning');
650 - $dc=wdGetDataSetContext($dc);
 663+ $dc=wdGetDataSetContext();
651664
652665 $definedMeaningId = newObjectId("{$dc}_defined_meaning");
653666
 667+ //wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" );
654668 $dbr = &wfGetDB(DB_MASTER);
655669 $dbr->query("INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, ". getUpdateTransactionId() .")");
656 -
 670+
 671+ //wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" );
 672+
657673 $expression = getExpression($definingExpressionId);
658674 $pageId = createPage($definedMeaningNameSpaceId, getPageTitle("$expression->spelling ($definedMeaningId)"));
659675 createInitialRevisionForPage($pageId, 'Created by adding defined meaning');
@@ -760,8 +776,8 @@
761777 "VALUES ($valueId, $objectId, $attributeId, $translatedContentId, ". getUpdateTransactionId() .")");
762778 }
763779
764 -function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text, $dc) {
765 - $dc=wdGetDataSetContext($dc);
 780+function addTranslatedTextAttributeValue($objectId, $attributeId, $languageId, $text) {
 781+ $dc=wdGetDataSetContext();
766782 $translatedTextValueAttributeId = newObjectId("{$dc}_translated_content_attribute_values");
767783 $translatedContentId = newTranslatedContentId();
768784
@@ -1167,8 +1183,6 @@
11681184 $dc=wdGetDataSetContext();
11691185 }
11701186 $collection_id=getCollectionIdForDC($dc);
1171 - if (is_null($collection_id))
1172 - return null;
11731187 $dbr = & wfGetDB(DB_SLAVE);
11741188 $dm=$dbr->addQuotes($dm);
11751189 $query = "
@@ -1177,7 +1191,7 @@
11781192 WHERE member_mid=$dm
11791193 AND collection_id=$collection_id;
11801194 ";
1181 - $queryResult = $dbr->query($query,"getConceptId");
 1195+ $queryResult = $dbr->query($query);
11821196 $row=$dbr->fetchObject($queryResult);
11831197 return isset($row->concept_id) ? $row->concept_id : null;
11841198 }

Status & tagging log