r115792 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r115791‎ | r115792 | r115793 >
Date:13:19, 19 December 2012
Author:kipcool
Status:new
Tags:
Comment:
Changed the identical meaning checkbox to a combobox
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/resources/tables.css (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/type.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/resources/tables.css
@@ -148,7 +148,6 @@
149149
150150 .level3 {
151151 font-size:120% ;
152 - font-weight: bold;
153152 background-color: #e0ffff;
154153 margin-top:10px;
155154 padding:5px;
@@ -165,6 +164,19 @@
166165 padding:5px;
167166 }
168167
 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+
169181 td.add {
170182 text-align: center;
171183 }
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -5,7 +5,6 @@
66 require_once( "WikiDataBootstrappedMeanings.php" );
77 require_once( "ContextFetcher.php" );
88 require_once( "WikiDataGlobals.php" );
9 -// require_once( "GotoSourceTemplate.php" ); // not used, disabled
109 require_once( "ViewInformation.php" );
1110
1211 class DummyViewer extends Viewer {
@@ -537,6 +536,7 @@
538537
539538 $o = OmegaWikiAttributes::getInstance();
540539
 540+ // defining the language + expression editor (syntrans)
541541 $tableEditor = new RecordSetTableEditor(
542542 $o->synonymsAndTranslations,
543543 new SimplePermissionController( true ),
@@ -546,10 +546,21 @@
547547 false,
548548 new SynonymTranslationController( $viewInformation->filterLanguageId )
549549 );
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
551562 $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
554565 addPropertyToColumnFilterEditors( $tableEditor, $viewInformation, $o->syntransId, $synTransMeaningName );
555566
556567 // Add annotation editor on the rightmost column.
@@ -623,17 +634,12 @@
624635 }
625636
626637 function getDefinedMeaningCollectionMembershipEditor( ViewInformation $viewInformation ) {
627 - global $wgGotoSourceTemplates;
628 -
629638 $o = OmegaWikiAttributes::getInstance();
630639
631640 $editor = new RecordSetTableEditor( $o->collectionMembership, new SimplePermissionController( true ), new ShowEditFieldChecker( true ), new AllowAddController( true ), true, false, new DefinedMeaningCollectionController() );
632641 $editor->addEditor( new CollectionReferenceEditor( $o->collectionMeaning, new SimplePermissionController( false ), true ) );
633642 $editor->addEditor( new ShortTextEditor( $o->sourceIdentifier, new SimplePermissionController( false ), true ) );
634643
635 - if ( count( $wgGotoSourceTemplates ) > 1 )
636 - $editor->addEditor( new GotoSourceEditor( $o->gotoSource, new SimplePermissionController( true ), true ) );
637 -
638644 addTableMetadataEditors( $editor, $viewInformation );
639645
640646 return $editor;
@@ -757,10 +763,15 @@
758764 function getExpressionsEditor( $spelling, ViewInformation $viewInformation ) {
759765 $o = OmegaWikiAttributes::getInstance();
760766
761 - $expressionMeaningsRecordEditor = new RecordUnorderedListEditor( $o->expressionMeanings, 3 );
 767+ $headerLevel = 3 ;
 768+ $expressionMeaningsRecordEditor = new RecordUnorderedListEditor( $o->expressionMeanings, $headerLevel );
762769
763 - $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, true, $viewInformation );
 770+ $allowAdd = true;
 771+ $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, $allowAdd, $viewInformation );
 772+ $exactMeaningsEditor->setDisplayHeader(false);
764773 $expressionMeaningsRecordEditor->addEditor( $exactMeaningsEditor );
 774+
 775+// add an approximate meaning editor (identicalMeaning = 0):
765776 $approximateMeaningsEditor = getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) ;
766777 $expressionMeaningsRecordEditor->addEditor( $approximateMeaningsEditor );
767778
Index: trunk/extensions/Wikidata/OmegaWiki/type.php
@@ -9,18 +9,20 @@
1010 require_once( 'Wikidata.php' );
1111 require_once( 'WikiDataGlobals.php' );
1212
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+ }
1819 }
1920
2021 function booleanAsHTML( $value ) {
21 - if ( $value )
 22+ if ( $value ) {
2223 return '<input type="checkbox" checked="checked" disabled="disabled"/>';
23 - else
 24+ } else {
2425 return '<input type="checkbox" disabled="disabled"/>';
 26+ }
2527 }
2628
2729 function pageAsURL( $nameSpace, $title, $usedc = true ) {
@@ -117,6 +119,8 @@
118120 function collectionAsLink( $collectionId ) {
119121 return definedMeaningAsLink( getCollectionMeaningId( $collectionId ) );
120122 }
 123+/*
 124+useless?
121125
122126 function convertToHTML( $value, $type ) {
123127 switch( $type ) {
@@ -166,4 +170,4 @@
167171 }
168172 }
169173
170 -
 174+*/
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -96,7 +96,8 @@
9797 $t->definedMeaningAttributes = new Attribute( WD_DEFINED_MEANING_ATTRIBUTES, wfMsgSc( "DefinedMeaningAttributes" ), "will-be-specified-below" );
9898 $t->objectAttributes = new Attribute( WD_OBJECT_ATTRIBUTES, wfMsgSc( "Annotation" ), "will-be-specified-below" );
9999 $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" );
101102
102103 if ( $viewInformation->filterOnLanguage() ) {
103104 $t->expression = new Attribute( WD_EXPRESSION, wfMsgSc( "Spelling" ), "spelling" );
@@ -161,13 +162,15 @@
162163 $t->alternativeDefinitionsStructure = new Structure( WD_ALTERNATIVE_DEFINITIONS, $t->definitionId, $t->alternativeDefinition, $t->source );
163164 $t->alternativeDefinitions = new Attribute( null, wfMsgSc( "AlternativeDefinitions" ), $t->alternativeDefinitionsStructure );
164165
165 - if ( $viewInformation->filterOnLanguage() )
 166+ if ( $viewInformation->filterOnLanguage() ) {
166167 $synonymsAndTranslationsCaption = wfMsgSc( "Synonyms" );
167 - else
 168+ } else {
168169 $synonymsAndTranslationsCaption = wfMsgSc( "SynonymsAndTranslations" );
 170+ }
169171
170172 $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 );
172175 $t->synonymsAndTranslations = new Attribute( null, "$synonymsAndTranslationsCaption", $t->synonymsTranslationsStructure );
173176 $t->translatedTextAttributeId = new Attribute( "translated-text-attribute-id", "Attribute identifier", "object-id" );
174177 $t->translatedTextAttribute = new Attribute( "translated-text-attribute", wfMsgSc( "TranslatedTextAttribute" ), $definedMeaningReferenceType );
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -235,18 +235,23 @@
236236 }
237237 }
238238
239 -/* XXX: Basic Editor class. */
 239+/**
 240+ * Basic Editor class.
 241+ */
240242 abstract class DefaultEditor implements Editor {
241243 protected $editors;
242244 protected $attributeEditorMap;
243245 protected $attribute;
244246 protected $isCollapsible;
 247+ protected $displayHeader;
245248
246249 public function __construct( Attribute $attribute = null ) {
247250 $this->attribute = $attribute;
248251 $this->editors = array();
249252 $this->attributeEditorMap = new AttributeEditorMap();
250253 $this->isCollapsible = true;
 254+ // show header by default
 255+ $this->displayHeader = true;
251256 }
252257
253258 public function addEditor( Editor $editor ) {
@@ -282,6 +287,15 @@
283288 $this->isCollapsible = $value;
284289 }
285290
 291+ public function setDisplayHeader( $value ) {
 292+ $this->displayHeader = $value;
 293+ }
 294+
 295+ public function getDisplayHeader() {
 296+ return $this->displayHeader;
 297+ }
 298+
 299+
286300 public function getExpansionPrefix( $class, $elementId ) {
287301 if ( ! $this->isCollapsible ) {
288302 return '';
@@ -522,13 +536,13 @@
523537 public function getUpdateRecord( IdStack $idPath, Structure $structure, $editors ) {
524538 $result = new ArrayRecord( $structure );
525539
526 - foreach ( $editors as $editor )
 540+ foreach ( $editors as $editor ) {
527541 if ( $attribute = $editor->getUpdateAttribute() ) {
528542 $idPath->pushAttribute( $attribute );
529543 $result->setAttributeValue( $attribute, $editor->getUpdateValue( $idPath ) );
530544 $idPath->popAttribute();
531545 }
532 -
 546+ }
533547 return $result;
534548 }
535549
@@ -1390,15 +1404,15 @@
13911405 }
13921406
13931407 public function add( IdStack $idPath ) {
1394 - if ( $this->isAddField )
 1408+ if ( $this->isAddField ) {
13951409 return getTextBox( $this->addId( $idPath->getId() ), "", $this->onChangeHandler );
1396 - else
 1410+ } else {
13971411 return "";
 1412+ }
13981413 }
13991414
14001415 public function getInputValue( $id ) {
1401 - global
1402 - $wgRequest;
 1416+ global $wgRequest;
14031417
14041418 return trim( $wgRequest->getText( $id ) );
14051419 }
@@ -1415,9 +1429,9 @@
14161430 $label = htmlspecialchars( $value->linkLabel );
14171431 $url = htmlspecialchars( $value->linkURL );
14181432
1419 - if ( $label == "" )
 1433+ if ( $label == "" ) {
14201434 $label = $url;
1421 -
 1435+ }
14221436 return
14231437 '<a href="' . $url . '">' . $label . '</a>' . EOL;
14241438 }
@@ -1447,10 +1461,11 @@
14481462 }
14491463
14501464 public function add( IdStack $idPath ) {
1451 - if ( $this->isAddField )
 1465+ if ( $this->isAddField ) {
14521466 return getCheckBox( $this->addId( $idPath->getId() ), $this->defaultValue );
1453 - else
 1467+ } else {
14541468 return "";
 1469+ }
14551470 }
14561471
14571472 public function getInputValue( $id ) {
@@ -1460,12 +1475,69 @@
14611476 }
14621477 }
14631478
 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+
14641535 abstract class SuggestEditor extends ScalarEditor {
14651536 public function add( IdStack $idPath ) {
1466 - if ( $this->isAddField )
 1537+ if ( $this->isAddField ) {
14671538 return getSuggest( $this->addId( $idPath->getId() ), $this->suggestType() );
1468 - else
 1539+ } else {
14691540 return "";
 1541+ }
14701542 }
14711543
14721544 protected abstract function suggestType();
@@ -1730,22 +1802,25 @@
17311803 $class = $idPath->getClass();
17321804 $attributeId = $idPath->getId();
17331805 $attributeValue = $value->getAttributeValue( $attribute );
1734 -
 1806+
17351807 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+ }
17411815 $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+ }
17451820 }
17461821
17471822 $idPath->popAttribute();
1748 - }
1749 -
 1823+ } // foreach editors
 1824+
17501825 return $result;
17511826 }
17521827
@@ -1785,17 +1860,21 @@
17861861 $class = $idPath->getClass();
17871862 $attributeId = $idPath->getId();
17881863
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+ }
17981877 }
1799 -
 1878+
18001879 $idPath->popAttribute();
18011880 }
18021881
@@ -1877,7 +1956,9 @@
18781957
18791958 public function view( IdStack $idPath, $value ) {
18801959 $editors = $this->getEditors();
1881 - $compress = $this->shouldCompressOnView( $idPath, $value, $editors );
 1960+//
 1961+// $compress = $this->shouldCompressOnView( $idPath, $value, $editors );
 1962+ $compress = false ;
18821963 $result = $this->viewEditors( $idPath, $value, $editors, $this->htmlTag, $compress );
18831964
18841965 if ( !$compress )
@@ -2662,35 +2743,6 @@
26632744 }
26642745 }
26652746
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 -
26952747 class DefinedMeaningContextEditor extends WrappingEditor {
26962748 public function view( IdStack $idPath, $value ) {
26972749 $definedMeaningId = (int) $value->definedMeaningId;
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -42,23 +42,12 @@
4343 }
4444
4545 function assureIsBoundToDefinedMeaning( $definedMeaningId, $identicalMeaning ) {
46 - if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) )
 46+ if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) {
4747 $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;
5848 }
59 - $dbr->freeResult( $queryResult ) ;
6049 }
61 -
6250 }
 51+
6352 function getExpression( $expressionId, $dc = null ) {
6453 if ( is_null( $dc ) ) {
6554 $dc = wdGetDataSetContext();
@@ -208,13 +197,14 @@
209198 "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId " .
210199 ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . " LIMIT 1" );
211200
212 - if ( $synonym = $dbr->fetchObject( $queryResult ) )
 201+ if ( $synonym = $dbr->fetchObject( $queryResult ) ) {
213202 return $synonym->syntrans_sid;
214 - else
215 - return 0;
 203+ }
 204+ // else
 205+ return 0;
216206 }
217207
218 -function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = 1 ) {
 208+function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = "true" ) {
219209
220210 $dc = wdGetDataSetContext();
221211 $synonymId = getSynonymId( $definedMeaningId, $expressionId );
@@ -224,9 +214,15 @@
225215 }
226216
227217 $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+ }
229224 $sql = "insert into {$dc}_syntrans(syntrans_sid, defined_meaning_id, expression_id, identical_meaning, add_transaction_id) " .
230225 "values($synonymId, $definedMeaningId, $expressionId, $identicalMeaningInteger, " . getUpdateTransactionId() . ")";
 226+
231227 $queryResult = $dbw->query( $sql );
232228 }
233229
@@ -249,7 +245,7 @@
250246 $expression = findOrCreateExpression( $spelling, $languageId );
251247 $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, $identicalMeaning );
252248 }
253 -
 249+
254250 function getMaximum( $field, $table ) {
255251 $dbr = wfGetDB( DB_SLAVE );
256252 $sql = "select max($field) as maximum from $table";
@@ -526,15 +522,29 @@
527523 createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning );
528524 }
529525
530 -function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaning ) {
 526+function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaningInput ) {
531527 $dc = wdGetDataSetContext();
532528 $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" .
534537 " FROM {$dc}_syntrans" .
535538 " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" );
536539
537540 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+ }
539549 }
540550 }
541551
@@ -609,8 +619,9 @@
610620 }
611621
612622 function addTranslatedTextIfNotPresent( $translatedContentId, $languageId, $text ) {
613 - if ( !translatedTextExists( $translatedContentId, $languageId ) )
 623+ if ( !translatedTextExists( $translatedContentId, $languageId ) ) {
614624 addTranslatedText( $translatedContentId, $languageId, $text );
 625+ }
615626 }
616627
617628 function getDefinedMeaningDefinitionId( $definedMeaningId ) {
@@ -750,7 +761,7 @@
751762 function bootstrapCollection( $collection, $languageId, $collectionType ) {
752763 $expression = findOrCreateExpression( $collection, $languageId );
753764 $definedMeaningId = addDefinedMeaning( $expression->id );
754 - $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, true );
 765+ $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, "true" );
755766 addDefinedMeaningDefinition( $definedMeaningId, $languageId, $collection );
756767 return addCollection( $definedMeaningId, $collectionType );
757768 }
@@ -789,12 +800,12 @@
790801
791802 $definedMeaningId = newObjectId( "{$dc}_defined_meaning" );
792803
793 - // wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" );
794804 $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() . ")" ;
798807
 808+ $dbw->query( $insertquery );
 809+
799810 $expression = getExpression( $definingExpressionId );
800811 $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( "$expression->spelling ($definedMeaningId)" ) );
801812 createInitialRevisionForPage( $pageId, 'Created by adding defined meaning' );
@@ -804,9 +815,9 @@
805816
806817 function createNewDefinedMeaning( $definingExpressionId, $languageId, $text ) {
807818 $definedMeaningId = addDefinedMeaning( $definingExpressionId );
808 - createSynonymOrTranslation( $definedMeaningId, $definingExpressionId, true );
 819+ createSynonymOrTranslation( $definedMeaningId, $definingExpressionId, "true" );
809820 addDefinedMeaningDefiningDefinition( $definedMeaningId, $languageId, $text );
810 -
 821+
811822 return $definedMeaningId;
812823 }
813824
@@ -1118,6 +1129,13 @@
11191130 }
11201131
11211132
 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+*/
11221140 function getSpellingForLanguage( $definedMeaningId, $languageCode, $fallbackLanguageCode = 'en', $dc = null ) {
11231141
11241142 $dc = wdGetDataSetContext( $dc );
@@ -1134,7 +1152,13 @@
11351153 $userLanguageId = $dbr->addQuotes( $userLanguageId );
11361154
11371155 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";
11391163
11401164 $res = $dbr->query( $actual_query );
11411165 $row = $dbr->fetchObject( $res );
@@ -1144,7 +1168,13 @@
11451169 }
11461170
11471171 $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";
11491179
11501180 $res = $dbr->query( $fallback_query );
11511181 $row = $dbr->fetchObject( $res );
@@ -1152,7 +1182,12 @@
11531183 return $row->spelling;
11541184 }
11551185
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";
11571192
11581193 $res = $dbr->query( $final_fallback );
11591194 $row = $dbr->fetchObject( $res );
@@ -1287,18 +1322,18 @@
12881323 }
12891324
12901325 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(
12961331 "SELECT defined_meaning_id" .
12971332 " 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+ );
13031338
13041339 $result = array();
13051340
@@ -1311,18 +1346,18 @@
13121347 }
13131348
13141349 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(
13201355 "SELECT defined_meaning_id, language_id" .
13211356 " 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+ );
13271362
13281363 $result = array();
13291364
@@ -1688,81 +1723,6 @@
16891724
16901725 }
16911726
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 -
17671727 class ClassAttribute {
17681728 public $attributeId;
17691729 public $levelName;