r14641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14640‎ | r14641 | r14642 >
Date:14:24, 7 June 2006
Author:proes
Status:old
Tags:
Comment:
Introduced PageElements to make view and edit pages more generic.
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/Expression.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZ.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/forms.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/relation.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/type.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/WiktionaryZ.php
@@ -7,6 +7,100 @@
88 require_once('type.php');
99 require_once('languages.php');
1010
 11+function getLatestRevisionForDefinedMeaning($definedMeaningId) {
 12+ $dbr =& wfGetDB(DB_SLAVE);
 13+ $sql = "SELECT revision_id from uw_defined_meaning where defined_meaning_id=$definedMeaningId and is_latest_ver=1 limit 1";
 14+ $queryResult = $dbr->query($sql);
 15+
 16+ return $dbr->fetchObject($queryResult)->revision_id;
 17+}
 18+
 19+function relationExists($setId, $definedMeaning1Id, $relationTypeId, $definedMeaning2Id) {
 20+ $dbr =& wfGetDB(DB_SLAVE);
 21+ $queryResult = $dbr->query("SELECT * FROM uw_meaning_relations WHERE set_id=$setId AND meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId AND is_latest_set=1");
 22+
 23+ return $dbr->numRows($queryResult) > 0;
 24+}
 25+
 26+function getSetIdForDefinedMeaningRelations($definedMeaningId) {
 27+ $dbr =& wfGetDB(DB_SLAVE);
 28+ $sql = "SELECT set_id from uw_meaning_relations where meaning1_mid=$definedMeaningId and is_latest_set=1 limit 1";
 29+ $queryResult = $dbr->query($sql);
 30+
 31+ $setId = $dbr->fetchObject($queryResult)->set_id;
 32+
 33+ if (!$setId) {
 34+ $sql = "SELECT max(set_id) as max_id from uw_meaning_relations";
 35+ $queryResult = $dbr->query($sql);
 36+ $setId = $dbr->fetchObject($queryResult)->max_id + 1;
 37+ }
 38+
 39+ return $setId;
 40+}
 41+
 42+function addRelation($definedMeaning1Id, $relationTypeId, $definedMeaning2Id) {
 43+ $setId = getSetIdForDefinedMeaningRelations($definedMeaning1Id);
 44+ $revisionId = getLatestRevisionForDefinedMeaning($definedMeaning1Id);
 45+
 46+ if (!relationExists($setId, $definedMeaning1Id, $relationTypeId, $definedMeaning2Id)) {
 47+ $dbr =& wfGetDB(DB_MASTER);
 48+ $sql = "insert into uw_meaning_relations(set_id, meaning1_mid, meaning2_mid, relationtype_mid, is_latest_set, first_set, revision_id) " .
 49+ "values($setId, $definedMeaning1Id, $definedMeaning2Id, $relationTypeId, 1, $setId, $revisionId)";
 50+ $dbr->query($sql);
 51+ }
 52+}
 53+
 54+
 55+class SynonymTranslationController implements PageElementController {
 56+ protected $definedMeaningId;
 57+
 58+ public function __construct($definedMeaningId) {
 59+ $this->definedMeaningId = $definedMeaningId;
 60+ }
 61+
 62+ public function add($values) {
 63+ $languageId = $values[0];
 64+ $spelling = $values[1];
 65+ $endemicMeaning = $values[2];
 66+
 67+ if ($spelling != '') {
 68+ $expression = findOrCreateExpression($spelling, $languageId);
 69+ $expression->assureIsBoundToDefinedMeaning($this->definedMeaningId, $endemicMeaning);
 70+ }
 71+ }
 72+}
 73+
 74+class DefinedMeaningRelationController implements PageElementController {
 75+ protected $definedMeaningId;
 76+
 77+ public function __construct($definedMeaningId) {
 78+ $this->definedMeaningId = $definedMeaningId;
 79+ }
 80+
 81+ public function add($values) {
 82+ $relationTypeId = $values[0];
 83+ $otherDefinedMeaningId = $values[1];
 84+
 85+ if ($relationTypeId != 0 && $otherDefinedMeaningId != 0)
 86+ addRelation($this->definedMeaningId, $relationTypeId, $otherDefinedMeaningId);
 87+ }
 88+}
 89+
 90+class DefinedMeaningAttributeController implements PageElementController {
 91+ protected $definedMeaningId;
 92+
 93+ public function __construct($definedMeaningId) {
 94+ $this->definedMeaningId = $definedMeaningId;
 95+ }
 96+
 97+ public function add($values) {
 98+ $attributeId = $values[0];
 99+
 100+ if ($attributeId != 0)
 101+ addRelation($this->definedMeaningId, 0, $attributeId);
 102+ }
 103+}
 104+
11105 /**
12106 * Renders a content page from WiktionaryZ based on the GEMET database.
13107 * @package MediaWiki
@@ -26,13 +120,11 @@
27121
28122 $wgOut->addHTML("Your user interface language preference: <b>$userlang</b> - " . $skin->makeLink("Special:Preferences", "set your preferences"));
29123
30 - # Get entry record from GEMET namespace
31124 $res=$dbr->query("SELECT * from uw_expression_ns WHERE spelling=BINARY ".$dbr->addQuotes($wgTitle->getText()));
32125
33126 while($row=$dbr->fetchObject($res)) {
34127 $expressionId = $row->expression_id;
35128 $definedMeaningIds = $this->getDefinedMeaningsForExpression($expressionId);
36 - $synonymAndTranslationRelations = $this->getSynonymAndTranslationRelations($definedMeaningIds, $expressionId);
37129 $definedMeaningTexts = $this->getDefinedMeaningTexts($definedMeaningIds);
38130 $alternativeMeaningTexts = $this->getAlternativeMeaningTexts($definedMeaningIds);
39131
@@ -53,9 +145,10 @@
54146 }
55147
56148 $wgOut->addHTML('<div class="wiki-data-blocks">');
57 - addWikiDataBlock("Translations and synonyms", getRelationAsHTML($synonymAndTranslationRelations[$definedMeaningId]));
58 - addWikiDataBlock("Relations", getRelationAsHTML($this->getDefinedMeaningRelationsRelation($definedMeaningId)));
59 - addWikiDataBlock("Attributes", getRelationAsHTML($this->getDefinedMeaningAttributesRelation($definedMeaningId)));
 149+ $pageElements = $this->getDefinedMeaningPageElements($definedMeaningId, $expressionId);
 150+
 151+ foreach($pageElements as $pageElement)
 152+ $this->displayPageElement($pageElement);
60153 $wgOut->addHTML('</div>');
61154
62155 $wgOut->addHTML('<div class="clear-float"/>');
@@ -68,6 +161,81 @@
69162 # $wgOut->setPageTitleArray($this->mTitle->getTitleArray());
70163 }
71164
 165+ function displayPageElement($pageElement) {
 166+ addWikiDataBlock($pageElement->getCaption(), getRelationAsHTML($pageElement->getRelationModel()));
 167+ }
 168+
 169+ function editPageElement($pageElement) {
 170+ $inputRow = array();
 171+ $addId = "add-".$pageElement->getId();
 172+
 173+ foreach($pageElement->getRelationModel()->getAttributes() as $attribute)
 174+ $inputRow[] = getInputFieldForType($addId . "-" . $attribute->id, $attribute->type, "");
 175+
 176+ addWikiDataBlock($pageElement->getCaption(), getRelationAsEditHTML($pageElement->getRelationModel(), $addId,
 177+ $inputRow, $pageElement->repeatInput()));
 178+ }
 179+
 180+ function addRowForPageElement($pageElement, $postFix) {
 181+ $addId = "add-".$pageElement->getId();
 182+ $attributes = $pageElement->getRelationModel()->getAttributes();
 183+
 184+ if (array_key_exists($addId . "-" . $attributes[0]->id . $postFix, $_POST)) {
 185+ $values = array();
 186+
 187+ foreach($attributes as $attribute)
 188+ $values[] = getFieldValueForType($addId . "-". $attribute->id . $postFix, $attribute->type);
 189+
 190+ $pageElement->getController()->add($values);
 191+ }
 192+ }
 193+
 194+ function savePageElement($pageElement) {
 195+ global
 196+ $wgRequest;
 197+
 198+ if ($pageElement->getController()) {
 199+ $addId = "add-" . $pageElement->getId();
 200+ $inputRow = array();
 201+ $rowCount = $wgRequest->getInt($addId . '-RC');
 202+
 203+ $this->addRowForPageElement($pageElement, "");
 204+
 205+ for ($i = 2; $i <= $rowCount; $i++)
 206+ $this->addRowForPageElement($pageElement, '-' . $i);
 207+ }
 208+ }
 209+
 210+ function getSynonymsAndTranslationsPageElement($definedMeaningId, $expressionId) {
 211+ return new DefaultPageElement("synonym-translation-$definedMeaningId", "Translations and synonyms",
 212+ $this->getSynonymAndTranslationRelation($definedMeaningId, $expressionId),
 213+ false,
 214+ true,
 215+ new SynonymTranslationController($definedMeaningId));
 216+ }
 217+
 218+ function getDefinedMeaningRelationsPageElement($definedMeaningId) {
 219+ return new DefaultPageElement("defined-meaning-relation-$definedMeaningId", "Relations",
 220+ $this->getDefinedMeaningRelationsRelation($definedMeaningId),
 221+ false,
 222+ false,
 223+ new DefinedMeaningRelationController($definedMeaningId));
 224+ }
 225+
 226+ function getDefinedMeaningAttributesPageElement($definedMeaningId) {
 227+ return new DefaultPageElement("defined-meaning-attribute-$definedMeaningId", "Attributes",
 228+ $this->getDefinedMeaningAttributesRelation($definedMeaningId),
 229+ false,
 230+ false,
 231+ new DefinedMeaningAttributeController($definedMeaningId));
 232+ }
 233+
 234+ function getDefinedMeaningPageElements($definedMeaningId, $expressionId) {
 235+ return array($this->getSynonymsAndTranslationsPageElement($definedMeaningId, $expressionId),
 236+ $this->getDefinedMeaningRelationsPageElement($definedMeaningId),
 237+ $this->getDefinedMeaningAttributesPageElement($definedMeaningId));
 238+ }
 239+
72240 function viewTranslatedContent($setId) {
73241 global
74242 $wgOut, $wgLanguageNames;
@@ -80,18 +248,6 @@
81249 }
82250 }
83251
84 - function getRelationTypeSuggest($definedMeaningId) {
85 - return getSuggest("new-relation-type-$definedMeaningId", "relation-type");
86 - }
87 -
88 - function getAttributeSuggest($definedMeaningId) {
89 - return getSuggest("new-attribute-$definedMeaningId", "attribute");
90 - }
91 -
92 - function getDefinedMeaningSuggest($definedMeaningId) {
93 - return getSuggest("new-relation-other-meaning-$definedMeaningId", "defined-meaning");
94 - }
95 -
96252 function getRelationTypes() {
97253 $relationtypes=array();
98254 $reltypecollections=$this->getReltypeCollections();
@@ -170,9 +326,10 @@
171327 if (count($translatedContents))
172328 $this->addTranslatedDefinitionFromRequest($definedMeaningId, $definedMeaningTextId, getRevisionForExpressionId($expressionId), array_keys($translatedContents));
173329
174 - $this->addSynonymsOrTranslationsFromRequest($definedMeaningId);
175 - $this->addRelationFromRequest($definedMeaningId);
176 - $this->addAttributeFromRequest($definedMeaningId);
 330+ $pageElements = $this->getDefinedMeaningPageElements($definedMeaningId, $expressionId);
 331+
 332+ foreach($pageElements as $pageElement)
 333+ $this->savePageElement($pageElement);
177334 }
178335
179336 function edit() {
@@ -241,19 +398,18 @@
242399
243400 $wgOut->addHTML("<h2><i>Spelling:</i>" . $spelling . " - <i>Language:</i> ".$wgLanguageNames[$languageId]."</h2>");
244401
245 - $synonymAndTranslationRelations = $this->getSynonymAndTranslationRelations($definedMeaningIds, $expressionId);
246402 $definedMeaningTexts = $this->getDefinedMeaningTexts($definedMeaningIds);
247403
248404 $wgOut->addHTML('<ul>');
249405 foreach ($definedMeaningIds as $definedMeaningId) {
250406 $wgOut->addHTML('<li>');
251 - $this->displayDefinedMeaningEditForm($definedMeaningId, $synonymAndTranslationRelations[$definedMeaningId], $definedMeaningTexts[$definedMeaningId]);
 407+ $this->displayDefinedMeaningEditForm($definedMeaningId, $expressionId, $this->getSynonymAndTranslationRelation($definedMeaningId, $expressionId), $definedMeaningTexts[$definedMeaningId]);
252408 $wgOut->addHTML('</li>');
253409 }
254410 $wgOut->addHTML('</ul>');
255411 }
256412
257 - function displayDefinedMeaningEditForm($definedMeaningId, $synonymAndTranslationTable, $definedMeaningTextId) {
 413+ function displayDefinedMeaningEditForm($definedMeaningId, $expressionId, $synonymAndTranslationTable, $definedMeaningTextId) {
258414 global
259415 $wgOut, $wgLanguageNames;
260416
@@ -267,14 +423,16 @@
268424
269425 if (count($translatedContents) > 0) {
270426 $wgOut->addHTML('<div><i>Translate into</i>: '.
271 - $this->getLanguageSelect("translated-definition-language-$definedMeaningId", array_keys($translatedContents)).'</div>'.
 427+ getLanguageSelect("translated-definition-language-$definedMeaningId", array_keys($translatedContents)).'</div>'.
272428 getTextArea("translated-definition-$definedMeaningId"));
273429 }
274430
275431 $wgOut->addHTML('<div class="wiki-data-blocks">');
276 - addWikiDataBlock("Translations and synonyms", getRelationAsEditHTML($synonymAndTranslationTable, "add-translation-synonym-$definedMeaningId", $this->getAddTranslationsAndSynonymsRowFields($definedMeaningId), true));
277 - addWikiDataBlock("Relations", getRelationAsEditHTML($this->getDefinedMeaningRelationsRelation($definedMeaningId), "", array($this->getRelationTypeSuggest($definedMeaningId), $this->getDefinedMeaningSuggest($definedMeaningId)), false));
278 - addWikiDataBlock("Attributes", getRelationAsEditHTML($this->getDefinedMeaningAttributesRelation($definedMeaningId), "", array($this->getAttributeSuggest($definedMeaningId)), false));
 432+ $pageElements = $this->getDefinedMeaningPageElements($definedMeaningId, $expressionId);
 433+
 434+ foreach($pageElements as $pageElement)
 435+ $this->editPageElement($pageElement);
 436+
279437 $wgOut->addHTML('</div>');
280438
281439 $wgOut->addHTML('<div class="clear-float"/>');
@@ -364,30 +522,24 @@
365523 return $synonymAndTranslationIds;
366524 }
367525
368 - function getSynonymAndTranslationRelations($definedMeaningIds, $skippedExpressionId) {
 526+ function getSynonymAndTranslationRelation($definedMeaningId, $skippedExpressionId) {
369527 $dbr =& wfGetDB(DB_SLAVE);
370 - $result = array();
371 - $attributes = array(new Attribute("Language", "language"), new Attribute("Spelling", "spelling"), new Attribute("Identical meaning?", "boolean"));
 528+ $attributes = array(new Attribute("language", "Language", "language"), new Attribute("spelling", "Spelling", "spelling"), new Attribute("endemic_meaning", "Identical meaning?", "boolean"));
 529+ $relation = new ArrayRelation($attributes);
 530+ $queryResult = $dbr->query("SELECT expression_id, endemic_meaning from uw_syntrans where defined_meaning_id=$definedMeaningId and expression_id!=$skippedExpressionId");
 531+
 532+ while($synonymOrTranslation = $dbr->fetchObject($queryResult)) {
 533+ $spellingAndLanguage = $this->getSpellingAndLanguageForExpression($synonymOrTranslation->expression_id);
 534+
 535+ foreach($spellingAndLanguage as $languageId => $spelling)
 536+ $relation->addTuple(array($languageId, $spelling, $synonymOrTranslation->endemic_meaning));
 537+ }
372538
373 - foreach($definedMeaningIds as $definedMeaningId) {
374 - $table = new ArrayRelation($attributes);
375 - $queryResult = $dbr->query("SELECT expression_id, endemic_meaning from uw_syntrans where defined_meaning_id=$definedMeaningId and expression_id!=$skippedExpressionId");
376 -
377 - while($synonymOrTranslation = $dbr->fetchObject($queryResult)) {
378 - $spellingAndLanguage = $this->getSpellingAndLanguageForExpression($synonymOrTranslation->expression_id);
379 -
380 - foreach($spellingAndLanguage as $languageId => $spelling)
381 - $table->addTuple(array($languageId, $spelling, $synonymOrTranslation->endemic_meaning));
382 - }
383 -
384 - $result[$definedMeaningId] = $table;
385 - }
386 -
387 - return $result;
 539+ return $relation;
388540 }
389541
390542 function getDefinedMeaningRelationsRelation($definedMeaningId) {
391 - $attributes = array(new Attribute("Relation type", "defined-meaning"), new Attribute("Other defined meaning", "defined-meaning"));
 543+ $attributes = array(new Attribute("relation-type", "Relation type", "relation-type"), new Attribute("other-defined_meaning", "Other defined meaning", "defined-meaning"));
392544 $relation = new ArrayRelation($attributes);
393545
394546 $dbr =& wfGetDB(DB_SLAVE);
@@ -395,13 +547,13 @@
396548
397549 while($definedMeaningRelation = $dbr->fetchObject($queryResult))
398550 $relation->addTuple(array($this->getExpressionForMeaningId($definedMeaningRelation->relationtype_mid, 85),
399 - $this->getExpressionForMeaningId($definedMeaningRelation->meaning2_mid, 85)));
 551+ $this->getExpressionForMeaningId($definedMeaningRelation->meaning2_mid, 85)));
400552
401553 return $relation;
402554 }
403555
404556 function getDefinedMeaningAttributesRelation($definedMeaningId) {
405 - $attributes = array(new Attribute("Attribute", "defined-meaning"));
 557+ $attributes = array(new Attribute("attribute", "Attribute", "attribute"));
406558 $relation = new ArrayRelation($attributes);
407559
408560 $dbr =& wfGetDB(DB_SLAVE);
@@ -459,41 +611,11 @@
460612 return $translatedContents;
461613 }
462614
463 - function getAddTranslationsAndSynonymsRowFields($definedMeaningId) {
464 - return array($this->getLanguageSelect("language-$definedMeaningId"), getTextBox("spelling-$definedMeaningId"), getCheckBox("endemic-meaning-$definedMeaningId", true));
465 - }
466 -
467615 function getTranslationIdsForDefinedMeaning($definedMeaningId) {
468616 $dbr =& wfGetDB(DB_SLAVE);
469617 $queryResult = $dbr->query("SELECT * from text where old_id=$textId");
470618 }
471619
472 - function getLanguageOptions($languageIdsToExclude = array()) {
473 - global
474 - $wgUser;
475 -
476 - $userLanguage = $wgUser->getOption('language');
477 - $idNameIndex = getLangNames($userLanguage);
478 -
479 - $result = array();
480 -
481 - foreach($idNameIndex as $id => $name)
482 - if (!in_array($id, $languageIdsToExclude))
483 - $result[$id] = $name;
484 -
485 - return $result;
486 - }
487 -
488 - function getLanguageSelect($name, $languageIdsToExclude = array()) {
489 - global
490 - $wgUser;
491 -
492 - $userLanguage = $wgUser->getOption('language');
493 - $userLanguageId = getLanguageIdForCode($userLanguage);
494 -
495 - return getSelect($name, $this->getLanguageOptions($languageIdsToExclude), $userLanguageId);
496 - }
497 -
498620 function getText($textId) {
499621 $dbr =& wfGetDB(DB_SLAVE);
500622 $queryResult = $dbr->query("SELECT old_text from text where old_id=$textId");
@@ -520,35 +642,6 @@
521643 return $dbr->insertId();
522644 }
523645
524 - function addSynonymOrTranslation($spelling, $languageId, $definedMeaningId, $endemicMeaning) {
525 - $expression = findOrCreateExpression($spelling, $languageId);
526 - $expression->assureIsBoundToDefinedMeaning($definedMeaningId, $endemicMeaning);
527 - }
528 -
529 - function addSynonymOrTranslationFromRequest($definedMeaningId, $postFix) {
530 - global
531 - $wgRequest;
532 -
533 - if (array_key_exists('language-'. $postFix, $_POST)) {
534 - $languageId = $wgRequest->getInt('language-'. $postFix);
535 - $spelling = trim($wgRequest->getText('spelling-'. $postFix));
536 - $endemicMeaning = $wgRequest->getCheck('endemic-meaning-'.$postFix);
537 -
538 - if ($spelling != '')
539 - $this->addSynonymOrTranslation($spelling, $languageId, $definedMeaningId, $endemicMeaning);
540 - }
541 - }
542 -
543 - function addSynonymsOrTranslationsFromRequest($definedMeaningId) {
544 - global
545 - $wgRequest;
546 -
547 - $this->addSynonymOrTranslationFromRequest($definedMeaningId, $definedMeaningId);
548 -
549 - for ($i = 2; $i <= $wgRequest->getInt('add-translation-synonym-'. $definedMeaningId . '-RC'); $i++)
550 - $this->addSynonymOrTranslationFromRequest($definedMeaningId, $definedMeaningId . '-' . $i);
551 - }
552 -
553646 function createTranslatedContent($setId, $languageId, $textId, $revisionId) {
554647 $dbr = &wfGetDB(DB_MASTER);
555648 $sql = "insert into translated_content(set_id,language_id,text_id,first_set,revision_id) values($setId, $languageId, $textId, $setId, $revisionId)";
@@ -615,78 +708,15 @@
616709 # Should be expressions in the language of preference, with an appropriate fallback scheme
617710 function getExpressionsForDefinedMeaningIds($definedMeaningIds) {
618711 $dbr =& wfGetDB(DB_SLAVE);
619 - $queryResult = $dbr->query("SELECT defined_meaning_id, spelling from uw_syntrans, uw_expression_ns where defined_meaning_id in (". implode(",", $definedMeaningIds) . ") and uw_expression_ns.expression_id=uw_syntrans.expression_id and uw_expression_ns.language_id=85");
 712+ $queryResult = $dbr->query("SELECT defined_meaning_id, spelling from uw_syntrans, uw_expression_ns where defined_meaning_id in (". implode(",", $definedMeaningIds) . ") and uw_expression_ns.expression_id=uw_syntrans.expression_id and uw_expression_ns.language_id=85 and uw_syntrans.endemic_meaning=1");
620713 $expressions = array();
621714
622 - while ($expression = $dbr->fetchObject($queryResult))
623 - $expressions[$expression->defined_meaning_id] = $expression->spelling;
 715+ while ($expression = $dbr->fetchObject($queryResult))
 716+ if (!array_key_exists($expression->defined_meaning_id, $expressions))
 717+ $expressions[$expression->defined_meaning_id] = $expression->spelling;
624718
625719 return $expressions;
626720 }
627 -
628 - function addRelationFromRequest($definedMeaningId) {
629 - global
630 - $wgRequest;
631 -
632 - $relationTypeId = $wgRequest->getInt("new-relation-type-$definedMeaningId");
633 - $otherDefinedMeaningId = $wgRequest->getInt("new-relation-other-meaning-$definedMeaningId");
634 -
635 - if ($relationTypeId != 0 && $otherDefinedMeaningId != 0)
636 - $this->addRelation($definedMeaningId, $relationTypeId, $otherDefinedMeaningId);
637 - }
638 -
639 - function addAttributeFromRequest($definedMeaningId) {
640 - global
641 - $wgRequest;
642 -
643 - $attributeId = $wgRequest->getInt("new-attribute-$definedMeaningId");
644 -
645 - if ($attributeId != 0)
646 - $this->addRelation($definedMeaningId, 0, $attributeId);
647 - }
648 -
649 - function getSetIdForDefinedMeaningRelations($definedMeaningId) {
650 - $dbr =& wfGetDB(DB_SLAVE);
651 - $sql = "SELECT set_id from uw_meaning_relations where meaning1_mid=$definedMeaningId and is_latest_set=1 limit 1";
652 - $queryResult = $dbr->query($sql);
653 -
654 - $setId = $dbr->fetchObject($queryResult)->set_id;
655 -
656 - if (!$setId) {
657 - $sql = "SELECT max(set_id) as max_id from uw_meaning_relations";
658 - $queryResult = $dbr->query($sql);
659 - $setId = $dbr->fetchObject($queryResult)->max_id + 1;
660 - }
661 -
662 - return $setId;
663 - }
664 -
665 - function getLatestRevisionForDefinedMeaning($definedMeaningId) {
666 - $dbr =& wfGetDB(DB_SLAVE);
667 - $sql = "SELECT revision_id from uw_defined_meaning where defined_meaning_id=$definedMeaningId and is_latest_ver=1 limit 1";
668 - $queryResult = $dbr->query($sql);
669 -
670 - return $dbr->fetchObject($queryResult)->revision_id;
671 - }
672 -
673 - function relationExists($setId, $definedMeaning1Id, $relationTypeId, $definedMeaning2Id) {
674 - $dbr =& wfGetDB(DB_MASTER);
675 - $queryResult = $dbr->query("SELECT * FROM uw_meaning_relations WHERE set_id=$setId AND meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId AND is_latest_set=1");
676 -
677 - return $dbr->numRows($queryResult) > 0;
678 - }
679 -
680 - function addRelation($definedMeaning1Id, $relationTypeId, $definedMeaning2Id) {
681 - $setId = $this->getSetIdForDefinedMeaningRelations($definedMeaning1Id);
682 - $revisionId = $this->getLatestRevisionForDefinedMeaning($definedMeaning1Id);
683 -
684 - if (!$this->relationExists($setId, $definedMeaning1Id, $relationTypeId, $definedMeaning2Id)) {
685 - $dbr =& wfGetDB(DB_MASTER);
686 - $sql = "insert into uw_meaning_relations(set_id, meaning1_mid, meaning2_mid, relationtype_mid, is_latest_set, first_set, revision_id) " .
687 - "values($setId, $definedMeaning1Id, $definedMeaning2Id, $relationTypeId, 1, $setId, $revisionId)";
688 - $dbr->query($sql);
689 - }
690 - }
691721 }
692722
693723 ?>
Index: trunk/extensions/Wikidata/WiktionaryZ/relation.php
@@ -1,10 +1,12 @@
22 <?php
33
44 class Attribute {
 5+ public $id = "";
56 public $name = "";
67 public $type = "";
78
8 - public function __construct($name, $type) {
 9+ public function __construct($id, $name, $type) {
 10+ $this->id = $id;
911 $this->name = $name;
1012 $this->type = $type;
1113 }
Index: trunk/extensions/Wikidata/WiktionaryZ/wikidata.php
@@ -1,11 +1,68 @@
22 <?php
3 - function addWikiDataBlock($title, $content) {
4 - global
5 - $wgOut;
6 -
7 - $wgOut->addHTML('<div class="wiki-data-block">
8 - <h4>'. $title . '</h4>'.
9 - $content .
10 - '</div>');
 3+function addWikiDataBlock($title, $content) {
 4+ global
 5+ $wgOut;
 6+
 7+ $wgOut->addHTML('<div class="wiki-data-block">
 8+ <h4>'. $title . '</h4>'.
 9+ $content .
 10+ '</div>');
 11+}
 12+
 13+interface PageElement {
 14+ public function getId();
 15+ public function getCaption();
 16+ public function getRelationModel();
 17+ public function allowRemove();
 18+ public function repeatInput();
 19+ public function getController();
 20+}
 21+
 22+interface PageElementController {
 23+ public function add($values);
 24+}
 25+
 26+class DefaultPageElement implements PageElement {
 27+ public $id;
 28+ public $caption;
 29+ public $relationModel;
 30+ public $allowRemove;
 31+ public $inputRow;
 32+ public $repeatInput;
 33+ public $controller;
 34+
 35+ public function __construct($id, $caption, $relationModel, $allowRemove, $repeatInput, $controller) {
 36+ $this->id = $id;
 37+ $this->caption = $caption;
 38+ $this->relationModel = $relationModel;
 39+ $this->allowRemove = $allowRemove;
 40+ $this->repeatInput = $repeatInput;
 41+ $this->controller = $controller;
1142 }
 43+
 44+ public function getId() {
 45+ return $this->id;
 46+ }
 47+
 48+ public function getCaption() {
 49+ return $this->caption;
 50+ }
 51+
 52+ public function getRelationModel() {
 53+ return $this->relationModel;
 54+ }
 55+
 56+ public function allowRemove() {
 57+ return $this->allowRemove;
 58+ }
 59+
 60+ public function repeatInput() {
 61+ return $this->repeatInput;
 62+ }
 63+
 64+ public function getController() {
 65+ return $this->controller;
 66+ }
 67+}
 68+
1269 ?>
Index: trunk/extensions/Wikidata/WiktionaryZ/Expression.php
@@ -190,6 +190,11 @@
191191 $queryResult = $dbr->query($sql);
192192 }
193193
 194+function addSynonymOrTranslation($spelling, $languageId, $definedMeaningId, $endemicMeaning) {
 195+ $expression = findOrCreateExpression($spelling, $languageId);
 196+ $expression->assureIsBoundToDefinedMeaning($definedMeaningId, $endemicMeaning);
 197+}
 198+
194199 function getMaximum($field, $table) {
195200 $dbr = &wfGetDB(DB_SLAVE);
196201 $sql = "select max($field) as maximum from $table";
Index: trunk/extensions/Wikidata/WiktionaryZ/type.php
@@ -1,6 +1,7 @@
22 <?php
33
44 require_once('languages.php');
 5+require_once('forms.php');
56
67 function booleanAsText($value) {
78 if ($value)
@@ -35,9 +36,37 @@
3637 case "boolean": return booleanAsHTML($value);
3738 case "spelling": return spellingAsLink($value);
3839 case "defined-meaning": return spellingAsLink($value);
 40+ case "relation-type": return spellingAsLink($value);
 41+ case "attribute": return spellingAsLink($value);
3942 case "language": return languageIdAsText($value);
4043 default: return $value;
4144 }
4245 }
4346
 47+function getInputFieldForType($name, $type, $value) {
 48+ switch($type) {
 49+ case "language": return getLanguageSelect($name);
 50+ case "spelling": return getTextBox($name);
 51+ case "boolean": return getCheckBox($name, true);
 52+ case "defined-meaning": return getSuggest($name, "defined-meaning");
 53+ case "relation-type": return getSuggest($name, "relation-type");
 54+ case "attribute": return getSuggest($name, "attribute");
 55+ }
 56+}
 57+
 58+function getFieldValueForType($name, $type) {
 59+ global
 60+ $wgRequest;
 61+
 62+ switch($type) {
 63+ case "language": return $wgRequest->getInt($name);
 64+ case "spelling": return trim($wgRequest->getText($name));
 65+ case "boolean": return $wgRequest->getCheck($name);
 66+ case "defined-meaning": return $wgRequest->getInt($name);
 67+ case "relation-type": return $wgRequest->getInt($name);
 68+ case "attribute": return $wgRequest->getInt($name);
 69+ }
 70+}
 71+
 72+
4473 ?>
Index: trunk/extensions/Wikidata/WiktionaryZ/forms.php
@@ -1,4 +1,7 @@
22 <?php
 3+
 4+require_once('languages.php');
 5+
36 function getTextBox($name, $maximumLength = 255, $value = "") {
47 return '<input type="text" name="'. $name .'" value="'. $value .'" maxlength="'. $maximumLength .'"/>';
58 }
@@ -47,6 +50,32 @@
4851 return $result;
4952 }
5053
 54+function getLanguageOptions($languageIdsToExclude = array()) {
 55+ global
 56+ $wgUser;
 57+
 58+ $userLanguage = $wgUser->getOption('language');
 59+ $idNameIndex = getLangNames($userLanguage);
 60+
 61+ $result = array();
 62+
 63+ foreach($idNameIndex as $id => $name)
 64+ if (!in_array($id, $languageIdsToExclude))
 65+ $result[$id] = $name;
 66+
 67+ return $result;
 68+}
 69+
 70+function getLanguageSelect($name, $languageIdsToExclude = array()) {
 71+ global
 72+ $wgUser;
 73+
 74+ $userLanguage = $wgUser->getOption('language');
 75+ $userLanguageId = getLanguageIdForCode($userLanguage);
 76+
 77+ return getSelect($name, getLanguageOptions($languageIdsToExclude), $userLanguageId);
 78+}
 79+
5180 function getSubmitButton($name, $value) {
5281 return '<input type="submit" name="'. $name .'" value="'. $value .'"/>';
5382 }

Status & tagging log