Index: trunk/extensions/Wikidata/OmegaWiki/resources/tables.css |
— | — | @@ -148,7 +148,6 @@ |
149 | 149 | |
150 | 150 | .level3 { |
151 | 151 | font-size:120% ; |
152 | | - font-weight: bold; |
153 | 152 | background-color: #e0ffff; |
154 | 153 | margin-top:10px; |
155 | 154 | padding:5px; |
— | — | @@ -165,6 +164,19 @@ |
166 | 165 | padding:5px; |
167 | 166 | } |
168 | 167 | |
| 168 | +li.exp-meanings-exact div.level3 { |
| 169 | + font-weight: bold; |
| 170 | +} |
| 171 | + |
| 172 | +li.exp-meanings-exact>div>ul { |
| 173 | + margin: 0px; |
| 174 | +} |
| 175 | + |
| 176 | +li.exp-meanings-approx { |
| 177 | + font-weight: normal; |
| 178 | + font-style: italic; |
| 179 | +} |
| 180 | + |
169 | 181 | td.add { |
170 | 182 | text-align: center; |
171 | 183 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -5,7 +5,6 @@ |
6 | 6 | require_once( "WikiDataBootstrappedMeanings.php" ); |
7 | 7 | require_once( "ContextFetcher.php" ); |
8 | 8 | require_once( "WikiDataGlobals.php" ); |
9 | | -// require_once( "GotoSourceTemplate.php" ); // not used, disabled |
10 | 9 | require_once( "ViewInformation.php" ); |
11 | 10 | |
12 | 11 | class DummyViewer extends Viewer { |
— | — | @@ -537,6 +536,7 @@ |
538 | 537 | |
539 | 538 | $o = OmegaWikiAttributes::getInstance(); |
540 | 539 | |
| 540 | + // defining the language + expression editor (syntrans) |
541 | 541 | $tableEditor = new RecordSetTableEditor( |
542 | 542 | $o->synonymsAndTranslations, |
543 | 543 | new SimplePermissionController( true ), |
— | — | @@ -546,10 +546,21 @@ |
547 | 547 | false, |
548 | 548 | new SynonymTranslationController( $viewInformation->filterLanguageId ) |
549 | 549 | ); |
550 | | - |
| 550 | + |
| 551 | + |
| 552 | + // defining the identicalMeaning Editor |
| 553 | + $attribute = $o->identicalMeaning ; |
| 554 | + $permissionController = new SimplePermissionController( true ) ; |
| 555 | + $isAddField = true ; |
| 556 | + $identicalMeaningEditor = new IdenticalMeaningEditor( |
| 557 | + $attribute, $permissionController, $isAddField |
| 558 | + ); |
| 559 | + $tableEditor->addEditor( $identicalMeaningEditor ); |
| 560 | + |
| 561 | + // expression Editor |
551 | 562 | $tableEditor->addEditor( getExpressionTableCellEditor( $o->expression, $viewInformation ) ); |
552 | | - $tableEditor->addEditor( new BooleanEditor( $o->identicalMeaning, new SimplePermissionController( true ), true, true ) ); |
553 | | - |
| 563 | + |
| 564 | + // not sure what this does |
554 | 565 | addPropertyToColumnFilterEditors( $tableEditor, $viewInformation, $o->syntransId, $synTransMeaningName ); |
555 | 566 | |
556 | 567 | // Add annotation editor on the rightmost column. |
— | — | @@ -623,17 +634,12 @@ |
624 | 635 | } |
625 | 636 | |
626 | 637 | function getDefinedMeaningCollectionMembershipEditor( ViewInformation $viewInformation ) { |
627 | | - global $wgGotoSourceTemplates; |
628 | | - |
629 | 638 | $o = OmegaWikiAttributes::getInstance(); |
630 | 639 | |
631 | 640 | $editor = new RecordSetTableEditor( $o->collectionMembership, new SimplePermissionController( true ), new ShowEditFieldChecker( true ), new AllowAddController( true ), true, false, new DefinedMeaningCollectionController() ); |
632 | 641 | $editor->addEditor( new CollectionReferenceEditor( $o->collectionMeaning, new SimplePermissionController( false ), true ) ); |
633 | 642 | $editor->addEditor( new ShortTextEditor( $o->sourceIdentifier, new SimplePermissionController( false ), true ) ); |
634 | 643 | |
635 | | - if ( count( $wgGotoSourceTemplates ) > 1 ) |
636 | | - $editor->addEditor( new GotoSourceEditor( $o->gotoSource, new SimplePermissionController( true ), true ) ); |
637 | | - |
638 | 644 | addTableMetadataEditors( $editor, $viewInformation ); |
639 | 645 | |
640 | 646 | return $editor; |
— | — | @@ -757,10 +763,15 @@ |
758 | 764 | function getExpressionsEditor( $spelling, ViewInformation $viewInformation ) { |
759 | 765 | $o = OmegaWikiAttributes::getInstance(); |
760 | 766 | |
761 | | - $expressionMeaningsRecordEditor = new RecordUnorderedListEditor( $o->expressionMeanings, 3 ); |
| 767 | + $headerLevel = 3 ; |
| 768 | + $expressionMeaningsRecordEditor = new RecordUnorderedListEditor( $o->expressionMeanings, $headerLevel ); |
762 | 769 | |
763 | | - $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, true, $viewInformation ); |
| 770 | + $allowAdd = true; |
| 771 | + $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, $allowAdd, $viewInformation ); |
| 772 | + $exactMeaningsEditor->setDisplayHeader(false); |
764 | 773 | $expressionMeaningsRecordEditor->addEditor( $exactMeaningsEditor ); |
| 774 | + |
| 775 | +// add an approximate meaning editor (identicalMeaning = 0): |
765 | 776 | $approximateMeaningsEditor = getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) ; |
766 | 777 | $expressionMeaningsRecordEditor->addEditor( $approximateMeaningsEditor ); |
767 | 778 | |
Index: trunk/extensions/Wikidata/OmegaWiki/type.php |
— | — | @@ -9,18 +9,20 @@ |
10 | 10 | require_once( 'Wikidata.php' ); |
11 | 11 | require_once( 'WikiDataGlobals.php' ); |
12 | 12 | |
13 | | -function booleanAsText( $value ) { |
14 | | - if ( $value ) |
15 | | - return "Yes"; |
16 | | - else |
17 | | - return "No"; |
| 13 | +function booleanAsText( $boolValue, $textValues = array("true" => "Yes", "false" => "No") ) { |
| 14 | + if ( $boolValue ) { |
| 15 | + return $textValues["true"]; |
| 16 | + } else { |
| 17 | + return $textValues["false"]; |
| 18 | + } |
18 | 19 | } |
19 | 20 | |
20 | 21 | function booleanAsHTML( $value ) { |
21 | | - if ( $value ) |
| 22 | + if ( $value ) { |
22 | 23 | return '<input type="checkbox" checked="checked" disabled="disabled"/>'; |
23 | | - else |
| 24 | + } else { |
24 | 25 | return '<input type="checkbox" disabled="disabled"/>'; |
| 26 | + } |
25 | 27 | } |
26 | 28 | |
27 | 29 | function pageAsURL( $nameSpace, $title, $usedc = true ) { |
— | — | @@ -117,6 +119,8 @@ |
118 | 120 | function collectionAsLink( $collectionId ) { |
119 | 121 | return definedMeaningAsLink( getCollectionMeaningId( $collectionId ) ); |
120 | 122 | } |
| 123 | +/* |
| 124 | +useless? |
121 | 125 | |
122 | 126 | function convertToHTML( $value, $type ) { |
123 | 127 | switch( $type ) { |
— | — | @@ -166,4 +170,4 @@ |
167 | 171 | } |
168 | 172 | } |
169 | 173 | |
170 | | - |
| 174 | +*/ |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php |
— | — | @@ -96,7 +96,8 @@ |
97 | 97 | $t->definedMeaningAttributes = new Attribute( WD_DEFINED_MEANING_ATTRIBUTES, wfMsgSc( "DefinedMeaningAttributes" ), "will-be-specified-below" ); |
98 | 98 | $t->objectAttributes = new Attribute( WD_OBJECT_ATTRIBUTES, wfMsgSc( "Annotation" ), "will-be-specified-below" ); |
99 | 99 | $t->expressionId = new Attribute( "expression-id", "Expression Id", "expression-id" ); |
100 | | - $t->identicalMeaning = new Attribute( "identMeaning", wfMsgSc( "IdenticalMeaning" ), "boolean" ); |
| 100 | + // instead of " ", could be wfMsgSc( "IdenticalMeaning" ), but then the header is too long |
| 101 | + $t->identicalMeaning = new Attribute( WD_IDENTICAL_MEANING, " ", "combobox" ); |
101 | 102 | |
102 | 103 | if ( $viewInformation->filterOnLanguage() ) { |
103 | 104 | $t->expression = new Attribute( WD_EXPRESSION, wfMsgSc( "Spelling" ), "spelling" ); |
— | — | @@ -161,13 +162,15 @@ |
162 | 163 | $t->alternativeDefinitionsStructure = new Structure( WD_ALTERNATIVE_DEFINITIONS, $t->definitionId, $t->alternativeDefinition, $t->source ); |
163 | 164 | $t->alternativeDefinitions = new Attribute( null, wfMsgSc( "AlternativeDefinitions" ), $t->alternativeDefinitionsStructure ); |
164 | 165 | |
165 | | - if ( $viewInformation->filterOnLanguage() ) |
| 166 | + if ( $viewInformation->filterOnLanguage() ) { |
166 | 167 | $synonymsAndTranslationsCaption = wfMsgSc( "Synonyms" ); |
167 | | - else |
| 168 | + } else { |
168 | 169 | $synonymsAndTranslationsCaption = wfMsgSc( "SynonymsAndTranslations" ); |
| 170 | + } |
169 | 171 | |
170 | 172 | $t->syntransId = new Attribute( "syntrans-id", "$synonymsAndTranslationsCaption identifier", "integer" ); |
171 | | - $t->synonymsTranslationsStructure = new Structure( WD_SYNONYMS_TRANSLATIONS, $t->syntransId, $t->expression, $t->identicalMeaning ); |
| 173 | +// $t->synonymsTranslationsStructure = new Structure( WD_SYNONYMS_TRANSLATIONS, $t->syntransId, $t->expression, $t->identicalMeaning ); |
| 174 | + $t->synonymsTranslationsStructure = new Structure( WD_SYNONYMS_TRANSLATIONS, $t->identicalMeaning, $t->syntransId, $t->expression ); |
172 | 175 | $t->synonymsAndTranslations = new Attribute( null, "$synonymsAndTranslationsCaption", $t->synonymsTranslationsStructure ); |
173 | 176 | $t->translatedTextAttributeId = new Attribute( "translated-text-attribute-id", "Attribute identifier", "object-id" ); |
174 | 177 | $t->translatedTextAttribute = new Attribute( "translated-text-attribute", wfMsgSc( "TranslatedTextAttribute" ), $definedMeaningReferenceType ); |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -235,18 +235,23 @@ |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | | -/* XXX: Basic Editor class. */ |
| 239 | +/** |
| 240 | + * Basic Editor class. |
| 241 | + */ |
240 | 242 | abstract class DefaultEditor implements Editor { |
241 | 243 | protected $editors; |
242 | 244 | protected $attributeEditorMap; |
243 | 245 | protected $attribute; |
244 | 246 | protected $isCollapsible; |
| 247 | + protected $displayHeader; |
245 | 248 | |
246 | 249 | public function __construct( Attribute $attribute = null ) { |
247 | 250 | $this->attribute = $attribute; |
248 | 251 | $this->editors = array(); |
249 | 252 | $this->attributeEditorMap = new AttributeEditorMap(); |
250 | 253 | $this->isCollapsible = true; |
| 254 | + // show header by default |
| 255 | + $this->displayHeader = true; |
251 | 256 | } |
252 | 257 | |
253 | 258 | public function addEditor( Editor $editor ) { |
— | — | @@ -282,6 +287,15 @@ |
283 | 288 | $this->isCollapsible = $value; |
284 | 289 | } |
285 | 290 | |
| 291 | + public function setDisplayHeader( $value ) { |
| 292 | + $this->displayHeader = $value; |
| 293 | + } |
| 294 | + |
| 295 | + public function getDisplayHeader() { |
| 296 | + return $this->displayHeader; |
| 297 | + } |
| 298 | + |
| 299 | + |
286 | 300 | public function getExpansionPrefix( $class, $elementId ) { |
287 | 301 | if ( ! $this->isCollapsible ) { |
288 | 302 | return ''; |
— | — | @@ -522,13 +536,13 @@ |
523 | 537 | public function getUpdateRecord( IdStack $idPath, Structure $structure, $editors ) { |
524 | 538 | $result = new ArrayRecord( $structure ); |
525 | 539 | |
526 | | - foreach ( $editors as $editor ) |
| 540 | + foreach ( $editors as $editor ) { |
527 | 541 | if ( $attribute = $editor->getUpdateAttribute() ) { |
528 | 542 | $idPath->pushAttribute( $attribute ); |
529 | 543 | $result->setAttributeValue( $attribute, $editor->getUpdateValue( $idPath ) ); |
530 | 544 | $idPath->popAttribute(); |
531 | 545 | } |
532 | | - |
| 546 | + } |
533 | 547 | return $result; |
534 | 548 | } |
535 | 549 | |
— | — | @@ -1390,15 +1404,15 @@ |
1391 | 1405 | } |
1392 | 1406 | |
1393 | 1407 | public function add( IdStack $idPath ) { |
1394 | | - if ( $this->isAddField ) |
| 1408 | + if ( $this->isAddField ) { |
1395 | 1409 | return getTextBox( $this->addId( $idPath->getId() ), "", $this->onChangeHandler ); |
1396 | | - else |
| 1410 | + } else { |
1397 | 1411 | return ""; |
| 1412 | + } |
1398 | 1413 | } |
1399 | 1414 | |
1400 | 1415 | public function getInputValue( $id ) { |
1401 | | - global |
1402 | | - $wgRequest; |
| 1416 | + global $wgRequest; |
1403 | 1417 | |
1404 | 1418 | return trim( $wgRequest->getText( $id ) ); |
1405 | 1419 | } |
— | — | @@ -1415,9 +1429,9 @@ |
1416 | 1430 | $label = htmlspecialchars( $value->linkLabel ); |
1417 | 1431 | $url = htmlspecialchars( $value->linkURL ); |
1418 | 1432 | |
1419 | | - if ( $label == "" ) |
| 1433 | + if ( $label == "" ) { |
1420 | 1434 | $label = $url; |
1421 | | - |
| 1435 | + } |
1422 | 1436 | return |
1423 | 1437 | '<a href="' . $url . '">' . $label . '</a>' . EOL; |
1424 | 1438 | } |
— | — | @@ -1447,10 +1461,11 @@ |
1448 | 1462 | } |
1449 | 1463 | |
1450 | 1464 | public function add( IdStack $idPath ) { |
1451 | | - if ( $this->isAddField ) |
| 1465 | + if ( $this->isAddField ) { |
1452 | 1466 | return getCheckBox( $this->addId( $idPath->getId() ), $this->defaultValue ); |
1453 | | - else |
| 1467 | + } else { |
1454 | 1468 | return ""; |
| 1469 | + } |
1455 | 1470 | } |
1456 | 1471 | |
1457 | 1472 | public function getInputValue( $id ) { |
— | — | @@ -1460,12 +1475,69 @@ |
1461 | 1476 | } |
1462 | 1477 | } |
1463 | 1478 | |
| 1479 | +/* |
| 1480 | +* IdenticalMeaningEditor |
| 1481 | +* in view mode, shows either = or ≈ |
| 1482 | +* in edit mode, shows a combobox to choose. |
| 1483 | +* for html we use strings "true" and "false" instead of "0" and "1" |
| 1484 | +* to be sure that an undefined value will not be considered as a "0". |
| 1485 | +*/ |
| 1486 | +class IdenticalMeaningEditor extends ScalarEditor { |
| 1487 | + protected $defaultValue; |
| 1488 | + // textValues is an array of "value" => "how the value is displayed" |
| 1489 | + // e.g. array( "true" => "=", "false" => "≈" ); |
| 1490 | + protected $textValues; |
| 1491 | + |
| 1492 | + public function __construct( Attribute $attribute = null, PermissionController $permissionController, $isAddField ) { |
| 1493 | + parent::__construct( $attribute, $permissionController, $isAddField ); |
| 1494 | + |
| 1495 | + $this->defaultValue = "true"; |
| 1496 | + $this->textValues = array( "true" => "=", "false" => "≈" ); |
| 1497 | + } |
| 1498 | + |
| 1499 | + public function getViewHTML( IdStack $idPath, $value ) { |
| 1500 | + // $value is what is returned from the database, i.e. an integer, 0 or 1 |
| 1501 | + if ( $value == 0 ) return $this->textValues["false"]; |
| 1502 | + if ( $value == 1 ) return $this->textValues["true"]; |
| 1503 | + return "undefined"; // should not happen |
| 1504 | + } |
| 1505 | + |
| 1506 | + public function getEditHTML( IdStack $idPath, $value ) { |
| 1507 | + // $value is what is returned from the database, i.e. an integer, 0 or 1 |
| 1508 | + if ( $value == 0 ) { |
| 1509 | + return getSelect( $this->updateId( $idPath->getId() ), $this->textValues, "false" ); |
| 1510 | + } |
| 1511 | + if ( $value == 1 ) { |
| 1512 | + return getSelect( $this->updateId( $idPath->getId() ), $this->textValues, "true" ); |
| 1513 | + } |
| 1514 | + |
| 1515 | + // if no $value is not 0 and not 1, should not happen |
| 1516 | + return "undefined"; |
| 1517 | + } |
| 1518 | + |
| 1519 | + public function add( IdStack $idPath ) { |
| 1520 | + if ( $this->isAddField ) { |
| 1521 | + return getSelect( $this->addId( $idPath->getId() ), $this->textValues, $this->defaultValue); |
| 1522 | + } else { |
| 1523 | + return ""; |
| 1524 | + } |
| 1525 | + } |
| 1526 | + |
| 1527 | + public function getInputValue( $id ) { |
| 1528 | + global $wgRequest; |
| 1529 | + $inputvalue = trim( $wgRequest->getText( $id ) ); |
| 1530 | + return $inputvalue; |
| 1531 | + } |
| 1532 | +} |
| 1533 | + |
| 1534 | + |
1464 | 1535 | abstract class SuggestEditor extends ScalarEditor { |
1465 | 1536 | public function add( IdStack $idPath ) { |
1466 | | - if ( $this->isAddField ) |
| 1537 | + if ( $this->isAddField ) { |
1467 | 1538 | return getSuggest( $this->addId( $idPath->getId() ), $this->suggestType() ); |
1468 | | - else |
| 1539 | + } else { |
1469 | 1540 | return ""; |
| 1541 | + } |
1470 | 1542 | } |
1471 | 1543 | |
1472 | 1544 | protected abstract function suggestType(); |
— | — | @@ -1730,22 +1802,25 @@ |
1731 | 1803 | $class = $idPath->getClass(); |
1732 | 1804 | $attributeId = $idPath->getId(); |
1733 | 1805 | $attributeValue = $value->getAttributeValue( $attribute ); |
1734 | | - |
| 1806 | + |
1735 | 1807 | if ( $editor->showsData( $attributeValue ) ) { |
1736 | | - if ( !$compress ) |
1737 | | - $result .= |
1738 | | - '<' . $htmlTag . '>' . |
1739 | | - $this->childHeader( $editor, $attribute, $class, $attributeId ); |
1740 | | - |
| 1808 | + if ( !$compress ) { |
| 1809 | + $result .= Html::openElement( $htmlTag, array('class' => $class )) ; |
| 1810 | + |
| 1811 | + if ( $editor->getDisplayHeader() ) { |
| 1812 | + $result .= $this->childHeader( $editor, $attribute, $class, $attributeId ); |
| 1813 | + } |
| 1814 | + } |
1741 | 1815 | $result .= $this->viewChild( $editor, $idPath, $value, $attribute, $class, $attributeId ); |
1742 | | - |
1743 | | - if ( !$compress ) |
1744 | | - $result .= '</' . $htmlTag . '>'; |
| 1816 | + |
| 1817 | + if ( !$compress ) { |
| 1818 | + $result .= Html::closeElement( $htmlTag ); |
| 1819 | + } |
1745 | 1820 | } |
1746 | 1821 | |
1747 | 1822 | $idPath->popAttribute(); |
1748 | | - } |
1749 | | - |
| 1823 | + } // foreach editors |
| 1824 | + |
1750 | 1825 | return $result; |
1751 | 1826 | } |
1752 | 1827 | |
— | — | @@ -1785,17 +1860,21 @@ |
1786 | 1861 | $class = $idPath->getClass(); |
1787 | 1862 | $attributeId = $idPath->getId(); |
1788 | 1863 | |
1789 | | - if ( !$compress ) |
1790 | | - $result .= |
1791 | | - '<' . $htmlTag . '>' . |
1792 | | - $this->childHeader( $editor, $attribute, $class, $attributeId ); |
1793 | | - |
1794 | | - $result .= $this->editChild( $editor, $idPath, $value, $attribute, $class, $attributeId ); |
1795 | | - |
1796 | | - if ( !$compress ) |
1797 | | - $result .= '</' . $htmlTag . '>'; |
| 1864 | + if ( !$compress ) { |
| 1865 | + $result .= Html::openElement( $htmlTag, array('class' => $class )) ; |
| 1866 | + |
| 1867 | + if ( $editor->getDisplayHeader() ) { |
| 1868 | + $result .= $this->childHeader( $editor, $attribute, $class, $attributeId ); |
| 1869 | + } |
| 1870 | + } |
| 1871 | + |
| 1872 | + $result .= $this->editChild( $editor, $idPath, $value, $attribute, $class, $attributeId ); |
| 1873 | + |
| 1874 | + if ( !$compress ) { |
| 1875 | + $result .= Html::closeElement( $htmlTag ); |
| 1876 | + } |
1798 | 1877 | } |
1799 | | - |
| 1878 | + |
1800 | 1879 | $idPath->popAttribute(); |
1801 | 1880 | } |
1802 | 1881 | |
— | — | @@ -1877,7 +1956,9 @@ |
1878 | 1957 | |
1879 | 1958 | public function view( IdStack $idPath, $value ) { |
1880 | 1959 | $editors = $this->getEditors(); |
1881 | | - $compress = $this->shouldCompressOnView( $idPath, $value, $editors ); |
| 1960 | +// |
| 1961 | +// $compress = $this->shouldCompressOnView( $idPath, $value, $editors ); |
| 1962 | + $compress = false ; |
1882 | 1963 | $result = $this->viewEditors( $idPath, $value, $editors, $this->htmlTag, $compress ); |
1883 | 1964 | |
1884 | 1965 | if ( !$compress ) |
— | — | @@ -2662,35 +2743,6 @@ |
2663 | 2744 | } |
2664 | 2745 | } |
2665 | 2746 | |
2666 | | -/* |
2667 | | -Don't know what it is, but obviously only used for SwissProt |
2668 | | -cf. GoToSourceTemplate.php |
2669 | | -*/ |
2670 | | -class GotoSourceEditor extends Viewer { |
2671 | | - public function view( IdStack $idPath, $value ) { |
2672 | | - global $wgGotoSourceTemplates; |
2673 | | - if ( count( $wgGotoSourceTemplates ) <= 1 ) return "" ; |
2674 | | - |
2675 | | - $collectionId = $value->collectionId; |
2676 | | - $sourceIdentifier = $value->sourceIdentifier; |
2677 | | - |
2678 | | - $gotoSourceTemplate = $wgGotoSourceTemplates[$collectionId]; |
2679 | | - |
2680 | | - if ( $gotoSourceTemplate != null ) { |
2681 | | - $url = $gotoSourceTemplate->getURL( $sourceIdentifier ); |
2682 | | - return '<a href="' . htmlspecialchars( $url ) . '">Go to source</a>' . EOL; |
2683 | | - } |
2684 | | - else |
2685 | | - return ""; |
2686 | | - |
2687 | | - } |
2688 | | - |
2689 | | - public function showsData( $value ) { |
2690 | | - return true; |
2691 | | - } |
2692 | | -} |
2693 | | - |
2694 | | - |
2695 | 2747 | class DefinedMeaningContextEditor extends WrappingEditor { |
2696 | 2748 | public function view( IdStack $idPath, $value ) { |
2697 | 2749 | $definedMeaningId = (int) $value->definedMeaningId; |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -42,23 +42,12 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | function assureIsBoundToDefinedMeaning( $definedMeaningId, $identicalMeaning ) { |
46 | | - if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) |
| 46 | + if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) { |
47 | 47 | $this->bindToDefinedMeaning( $definedMeaningId, $identicalMeaning ); |
48 | | - } |
49 | | - |
50 | | - function fetchMeaningIds() { |
51 | | - |
52 | | - $dbr = wfGetDB( DB_SLAVE ); |
53 | | - $dc = $this->dataset; |
54 | | - $id = $this->id; |
55 | | - $queryResult = $dbr->query( "SELECT * FROM {$dc}_syntrans where expression_id=$id AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) ); |
56 | | - while ( $syntransRecord = $dbr->fetchObject( $queryResult ) ) { |
57 | | - $this->meaningIds[] = $syntransRecord->defined_meaning_id; |
58 | 48 | } |
59 | | - $dbr->freeResult( $queryResult ) ; |
60 | 49 | } |
61 | | - |
62 | 50 | } |
| 51 | + |
63 | 52 | function getExpression( $expressionId, $dc = null ) { |
64 | 53 | if ( is_null( $dc ) ) { |
65 | 54 | $dc = wdGetDataSetContext(); |
— | — | @@ -208,13 +197,14 @@ |
209 | 198 | "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId " . |
210 | 199 | ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . " LIMIT 1" ); |
211 | 200 | |
212 | | - if ( $synonym = $dbr->fetchObject( $queryResult ) ) |
| 201 | + if ( $synonym = $dbr->fetchObject( $queryResult ) ) { |
213 | 202 | return $synonym->syntrans_sid; |
214 | | - else |
215 | | - return 0; |
| 203 | + } |
| 204 | + // else |
| 205 | + return 0; |
216 | 206 | } |
217 | 207 | |
218 | | -function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = 1 ) { |
| 208 | +function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = "true" ) { |
219 | 209 | |
220 | 210 | $dc = wdGetDataSetContext(); |
221 | 211 | $synonymId = getSynonymId( $definedMeaningId, $expressionId ); |
— | — | @@ -224,9 +214,15 @@ |
225 | 215 | } |
226 | 216 | |
227 | 217 | $dbw = wfGetDB( DB_MASTER ); |
228 | | - $identicalMeaningInteger = (int) $identicalMeaning; |
| 218 | + if ( $identicalMeaning == "true" ) { |
| 219 | + $identicalMeaningInteger = 1; |
| 220 | + } else { |
| 221 | + // if ( $identicalMeaning == "false" ) |
| 222 | + $identicalMeaningInteger = 0; |
| 223 | + } |
229 | 224 | $sql = "insert into {$dc}_syntrans(syntrans_sid, defined_meaning_id, expression_id, identical_meaning, add_transaction_id) " . |
230 | 225 | "values($synonymId, $definedMeaningId, $expressionId, $identicalMeaningInteger, " . getUpdateTransactionId() . ")"; |
| 226 | + |
231 | 227 | $queryResult = $dbw->query( $sql ); |
232 | 228 | } |
233 | 229 | |
— | — | @@ -249,7 +245,7 @@ |
250 | 246 | $expression = findOrCreateExpression( $spelling, $languageId ); |
251 | 247 | $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, $identicalMeaning ); |
252 | 248 | } |
253 | | - |
| 249 | + |
254 | 250 | function getMaximum( $field, $table ) { |
255 | 251 | $dbr = wfGetDB( DB_SLAVE ); |
256 | 252 | $sql = "select max($field) as maximum from $table"; |
— | — | @@ -526,15 +522,29 @@ |
527 | 523 | createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning ); |
528 | 524 | } |
529 | 525 | |
530 | | -function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaning ) { |
| 526 | +function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaningInput ) { |
531 | 527 | $dc = wdGetDataSetContext(); |
532 | 528 | $dbr = wfGetDB( DB_SLAVE ); |
533 | | - $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id" . |
| 529 | + |
| 530 | + // check that $identicalMeaningInput has the correct form |
| 531 | + if ( $identicalMeaningInput != "true" && $identicalMeaningInput != "false" ) { |
| 532 | + // unknown value, no update possible |
| 533 | + return; |
| 534 | + } |
| 535 | + |
| 536 | + $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id, identical_meaning" . |
534 | 537 | " FROM {$dc}_syntrans" . |
535 | 538 | " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" ); |
536 | 539 | |
537 | 540 | if ( $syntrans = $dbr->fetchObject( $queryResult ) ) { |
538 | | - updateSynonymOrTranslation( $syntrans->defined_meaning_id, $syntrans->expression_id, $identicalMeaning ); |
| 541 | + // transform the identical_meaning value into the string form used in the html form |
| 542 | + $identicalMeaningDB = ( $syntrans->identical_meaning == 1 ) ? "true" : "false" ; |
| 543 | + |
| 544 | + // check if the "identicalMeaning" value of the database is different |
| 545 | + // from the value provided as an input in the html form. |
| 546 | + if ( $identicalMeaningInput != $identicalMeaningDB ) { |
| 547 | + updateSynonymOrTranslation( $syntrans->defined_meaning_id, $syntrans->expression_id, $identicalMeaningInput ); |
| 548 | + } |
539 | 549 | } |
540 | 550 | } |
541 | 551 | |
— | — | @@ -609,8 +619,9 @@ |
610 | 620 | } |
611 | 621 | |
612 | 622 | function addTranslatedTextIfNotPresent( $translatedContentId, $languageId, $text ) { |
613 | | - if ( !translatedTextExists( $translatedContentId, $languageId ) ) |
| 623 | + if ( !translatedTextExists( $translatedContentId, $languageId ) ) { |
614 | 624 | addTranslatedText( $translatedContentId, $languageId, $text ); |
| 625 | + } |
615 | 626 | } |
616 | 627 | |
617 | 628 | function getDefinedMeaningDefinitionId( $definedMeaningId ) { |
— | — | @@ -750,7 +761,7 @@ |
751 | 762 | function bootstrapCollection( $collection, $languageId, $collectionType ) { |
752 | 763 | $expression = findOrCreateExpression( $collection, $languageId ); |
753 | 764 | $definedMeaningId = addDefinedMeaning( $expression->id ); |
754 | | - $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, true ); |
| 765 | + $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, "true" ); |
755 | 766 | addDefinedMeaningDefinition( $definedMeaningId, $languageId, $collection ); |
756 | 767 | return addCollection( $definedMeaningId, $collectionType ); |
757 | 768 | } |
— | — | @@ -789,12 +800,12 @@ |
790 | 801 | |
791 | 802 | $definedMeaningId = newObjectId( "{$dc}_defined_meaning" ); |
792 | 803 | |
793 | | - // wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" ); |
794 | 804 | $dbw = wfGetDB( DB_MASTER ); |
795 | | - $dbw->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" ); |
796 | | - |
797 | | - // wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" ); |
| 805 | + $insertquery = "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) " |
| 806 | + . "values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" ; |
798 | 807 | |
| 808 | + $dbw->query( $insertquery ); |
| 809 | + |
799 | 810 | $expression = getExpression( $definingExpressionId ); |
800 | 811 | $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( "$expression->spelling ($definedMeaningId)" ) ); |
801 | 812 | createInitialRevisionForPage( $pageId, 'Created by adding defined meaning' ); |
— | — | @@ -804,9 +815,9 @@ |
805 | 816 | |
806 | 817 | function createNewDefinedMeaning( $definingExpressionId, $languageId, $text ) { |
807 | 818 | $definedMeaningId = addDefinedMeaning( $definingExpressionId ); |
808 | | - createSynonymOrTranslation( $definedMeaningId, $definingExpressionId, true ); |
| 819 | + createSynonymOrTranslation( $definedMeaningId, $definingExpressionId, "true" ); |
809 | 820 | addDefinedMeaningDefiningDefinition( $definedMeaningId, $languageId, $text ); |
810 | | - |
| 821 | + |
811 | 822 | return $definedMeaningId; |
812 | 823 | } |
813 | 824 | |
— | — | @@ -1118,6 +1129,13 @@ |
1119 | 1130 | } |
1120 | 1131 | |
1121 | 1132 | |
| 1133 | +/** |
| 1134 | +* returns one of the possible translations of |
| 1135 | +* a given DefinedMeaning ( $definedMeaningId ) |
| 1136 | +* preferably in a given language ( $languageCode ) |
| 1137 | +* or in English otherwise. |
| 1138 | +* null if not found |
| 1139 | +*/ |
1122 | 1140 | function getSpellingForLanguage( $definedMeaningId, $languageCode, $fallbackLanguageCode = 'en', $dc = null ) { |
1123 | 1141 | |
1124 | 1142 | $dc = wdGetDataSetContext( $dc ); |
— | — | @@ -1134,7 +1152,13 @@ |
1135 | 1153 | $userLanguageId = $dbr->addQuotes( $userLanguageId ); |
1136 | 1154 | |
1137 | 1155 | if ( $userLanguageId ) { |
1138 | | - $actual_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1"; |
| 1156 | + $actual_query = |
| 1157 | + "select spelling from {$dc}_syntrans,{$dc}_expression " . |
| 1158 | + " where {$dc}_syntrans.defined_meaning_id=$definedMeaningId " . |
| 1159 | + " and {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
| 1160 | + " and language_id=$userLanguageId " . |
| 1161 | + " and {$dc}_expression.remove_transaction_id is NULL " . |
| 1162 | + " LIMIT 1"; |
1139 | 1163 | |
1140 | 1164 | $res = $dbr->query( $actual_query ); |
1141 | 1165 | $row = $dbr->fetchObject( $res ); |
— | — | @@ -1144,7 +1168,13 @@ |
1145 | 1169 | } |
1146 | 1170 | |
1147 | 1171 | $fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId ); |
1148 | | - $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1"; |
| 1172 | + $fallback_query = |
| 1173 | + "select spelling from {$dc}_syntrans,{$dc}_expression " . |
| 1174 | + " where {$dc}_syntrans.defined_meaning_id=$definedMeaningId " . |
| 1175 | + " and {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
| 1176 | + " and language_id=$fallbackLanguageId " . |
| 1177 | + " and {$dc}_expression.remove_transaction_id is NULL " . |
| 1178 | + " LIMIT 1"; |
1149 | 1179 | |
1150 | 1180 | $res = $dbr->query( $fallback_query ); |
1151 | 1181 | $row = $dbr->fetchObject( $res ); |
— | — | @@ -1152,7 +1182,12 @@ |
1153 | 1183 | return $row->spelling; |
1154 | 1184 | } |
1155 | 1185 | |
1156 | | - $final_fallback = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and {$dc}_expression.remove_transaction_id is NULL LIMIT 1"; |
| 1186 | + $final_fallback = |
| 1187 | + "select spelling from {$dc}_syntrans,{$dc}_expression " . |
| 1188 | + " where {$dc}_syntrans.defined_meaning_id=$definedMeaningId " . |
| 1189 | + " and {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
| 1190 | + " and {$dc}_expression.remove_transaction_id is NULL " . |
| 1191 | + " LIMIT 1"; |
1157 | 1192 | |
1158 | 1193 | $res = $dbr->query( $final_fallback ); |
1159 | 1194 | $row = $dbr->fetchObject( $res ); |
— | — | @@ -1287,18 +1322,18 @@ |
1288 | 1323 | } |
1289 | 1324 | |
1290 | 1325 | function getExpressionMeaningIds( $spelling, $dc = null ) { |
1291 | | - if ( is_null( $dc ) ) { |
1292 | | - $dc = wdGetDataSetContext(); |
1293 | | - } |
1294 | | - $dbr = & wfGetDB( DB_SLAVE ); |
1295 | | - $queryResult = $dbr->query( |
| 1326 | + if ( is_null( $dc ) ) { |
| 1327 | + $dc = wdGetDataSetContext(); |
| 1328 | + } |
| 1329 | + $dbr = & wfGetDB( DB_SLAVE ); |
| 1330 | + $queryResult = $dbr->query( |
1296 | 1331 | "SELECT defined_meaning_id" . |
1297 | 1332 | " FROM {$dc}_expression, {$dc}_syntrans " . |
1298 | | - " WHERE spelling=" . $dbr->addQuotes( $spelling ) . |
1299 | | - " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" . |
1300 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
1301 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) |
1302 | | - ); |
| 1333 | + " WHERE spelling=" . $dbr->addQuotes( $spelling ) . |
| 1334 | + " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" . |
| 1335 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 1336 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) |
| 1337 | + ); |
1303 | 1338 | |
1304 | 1339 | $result = array(); |
1305 | 1340 | |
— | — | @@ -1311,18 +1346,18 @@ |
1312 | 1347 | } |
1313 | 1348 | |
1314 | 1349 | function getExpressionMeaningIdsForLanguages( $spelling, $languageIds, $dc = null ) { |
1315 | | - if ( is_null( $dc ) ) { |
1316 | | - $dc = wdGetDataSetContext(); |
1317 | | - } |
1318 | | - $dbr = & wfGetDB( DB_SLAVE ); |
1319 | | - $queryResult = $dbr->query( |
| 1350 | + if ( is_null( $dc ) ) { |
| 1351 | + $dc = wdGetDataSetContext(); |
| 1352 | + } |
| 1353 | + $dbr = & wfGetDB( DB_SLAVE ); |
| 1354 | + $queryResult = $dbr->query( |
1320 | 1355 | "SELECT defined_meaning_id, language_id" . |
1321 | 1356 | " FROM {$dc}_expression, {$dc}_syntrans " . |
1322 | | - " WHERE spelling=" . $dbr->addQuotes( $spelling ) . |
1323 | | - " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" . |
1324 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
1325 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) |
1326 | | - ); |
| 1357 | + " WHERE spelling=" . $dbr->addQuotes( $spelling ) . |
| 1358 | + " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" . |
| 1359 | + " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 1360 | + " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) |
| 1361 | + ); |
1327 | 1362 | |
1328 | 1363 | $result = array(); |
1329 | 1364 | |
— | — | @@ -1688,81 +1723,6 @@ |
1689 | 1724 | |
1690 | 1725 | } |
1691 | 1726 | |
1692 | | -/** |
1693 | | - * Returns the definitions and translations of the given defined meaning in the |
1694 | | - * given languages in an associative array. |
1695 | | - * @param $dmid the defined meaning id. |
1696 | | - * @param $languages an aray of language id's. |
1697 | | - * @return array an associative array with two entries per language: def_lid and trans_lid |
1698 | | - * (where lid is the language id); def_lid contains the definition in the language, |
1699 | | - * trans_lid contains the translations in a single string separated by the | character. |
1700 | | - */ |
1701 | | -function getDefinitionsAndTranslationsForLanguages( $dmid, $languages, $dc = null ) { |
1702 | | - if ( is_null( $dc ) ) { |
1703 | | - $dc = wdGetDataSetContext(); |
1704 | | - } |
1705 | | - $dbr = wfGetDB( DB_SLAVE ); |
1706 | | - |
1707 | | - // First we'll fill an associative array with the definitions and |
1708 | | - // translations. Then we'll use the isoCodes array to put them in the |
1709 | | - // proper order. |
1710 | | - |
1711 | | - // the associative array holding the definitions and translations |
1712 | | - $data = array(); |
1713 | | - |
1714 | | - // **************************** |
1715 | | - // query to get the definitions |
1716 | | - // **************************** |
1717 | | - $qry = 'SELECT txt.text_text, trans.language_id '; |
1718 | | - $qry .= "FROM {$dc}_text txt, {$dc}_translated_content trans, {$dc}_defined_meaning dm "; |
1719 | | - $qry .= 'WHERE txt.text_id = trans.text_id '; |
1720 | | - $qry .= 'AND trans.translated_content_id = dm.meaning_text_tcid '; |
1721 | | - $qry .= "AND dm.defined_meaning_id = $dmid "; |
1722 | | - $qry .= 'AND trans.language_id IN (' . implode( ',', $languages ) . ') '; |
1723 | | - $qry .= 'AND ' . getLatestTransactionRestriction( 'trans' ); |
1724 | | - $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' ); |
1725 | | - |
1726 | | - |
1727 | | - $definitions = $dbr->query( $qry ); |
1728 | | - while ( $row = $dbr->fetchRow( $definitions ) ) { |
1729 | | - // $key becomes something like def_23 |
1730 | | - $key = 'def_' . $row['language_id']; |
1731 | | - $data[$key] = $row['text_text']; |
1732 | | - } |
1733 | | - $dbr->freeResult( $definitions ); |
1734 | | - |
1735 | | - // ***************************** |
1736 | | - // query to get the translations |
1737 | | - // ***************************** |
1738 | | - $qry = "SELECT exp.spelling, exp.language_id "; |
1739 | | - $qry .= "FROM {$dc}_expression exp "; |
1740 | | - $qry .= "INNER JOIN {$dc}_syntrans trans ON exp.expression_id=trans.expression_id "; |
1741 | | - $qry .= "WHERE trans.defined_meaning_id=$dmid "; |
1742 | | - $qry .= "AND " . getLatestTransactionRestriction( "exp" ); |
1743 | | - $qry .= "AND " . getLatestTransactionRestriction( "trans" ); |
1744 | | - |
1745 | | - $translations = $dbr->query( $qry ); |
1746 | | - while ( $row = $dbr->fetchRow( $translations ) ) { |
1747 | | - // qry gets all languages, we filter them here. Saves an order |
1748 | | - // of magnitude execution time. |
1749 | | - if ( in_array( $row['language_id'], $languages ) ) { |
1750 | | - // $key becomes something like trans_23 |
1751 | | - $key = 'trans_' . $row['language_id']; |
1752 | | - if ( !isset( $data[$key] ) ) { |
1753 | | - $data[$key] = $row['spelling']; |
1754 | | - } else { |
1755 | | - $data[$key] = $data[$key] . '|' . $row['spelling']; |
1756 | | - } |
1757 | | - } |
1758 | | - } |
1759 | | - $dbr->freeResult( $translations ); |
1760 | | - |
1761 | | - return $data; |
1762 | | - |
1763 | | -} |
1764 | | - |
1765 | | - |
1766 | | - |
1767 | 1727 | class ClassAttribute { |
1768 | 1728 | public $attributeId; |
1769 | 1729 | public $levelName; |