Index: trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | initializeOmegaWikiAttributes( new ViewInformation() ); |
24 | 24 | $wgOut->setPageTitle( wfMsg( 'ow_needs_xlation_title' ) ); |
25 | 25 | |
26 | | - $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:''; |
| 26 | + $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:''; |
27 | 27 | $collectionId = array_key_exists( 'collection', $_GET ) ? $_GET['collection'] : ''; |
28 | 28 | $sourceLanguageId = array_key_exists( 'from-lang', $_GET ) ? $_GET['from-lang'] : ''; |
29 | 29 | |
— | — | @@ -43,7 +43,6 @@ |
44 | 44 | protected function showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ) { |
45 | 45 | |
46 | 46 | $o = OmegaWikiAttributes::getInstance(); |
47 | | - $o = OmegaWikiAttributes::getInstance(); |
48 | 47 | |
49 | 48 | $dc = wdGetDataSetContext(); |
50 | 49 | require_once( "Transaction.php" ); |
— | — | @@ -113,24 +112,31 @@ |
114 | 113 | |
115 | 114 | |
116 | 115 | $definitionAttribute = new Attribute( "definition", wfMsg( "ow_Definition" ), "definition" ); |
117 | | - $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->expression, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) ); |
118 | 116 | |
| 117 | + $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->definedMeaningReference, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) ); |
| 118 | + |
119 | 119 | while ( $row = $dbr->fetchObject( $queryResult ) ) { |
120 | | - $expressionRecord = new ArrayRecord( $o->expressionStructure ); |
121 | | - $expressionRecord->language = $row->source_language_id; |
122 | | - $expressionRecord->spelling = $row->source_spelling; |
| 120 | + $DMRecord = new ArrayRecord( $o->definedMeaningReferenceStructure ); |
| 121 | + $DMRecord->definedMeaningId = $row->source_defined_meaning_id ; |
| 122 | + $DMRecord->definedMeaningLabel = $row->source_spelling ; |
| 123 | + $DMRecord->definedMeaningDefiningExpression = $row->source_spelling ; |
| 124 | + $DMRecord->language = $row->source_language_id; |
123 | 125 | |
124 | | - $recordSet->addRecord( array( $row->source_defined_meaning_id, $row->source_expression_id, $expressionRecord, getDefinedMeaningDefinition( $row->source_defined_meaning_id ) ) ); |
| 126 | + $recordSet->addRecord( array( $row->source_defined_meaning_id, $row->source_expression_id, $DMRecord, getDefinedMeaningDefinition( $row->source_defined_meaning_id ) ) ); |
125 | 127 | } |
126 | 128 | |
127 | | - $expressionEditor = new RecordTableCellEditor( $o->expression ); |
| 129 | + $expressionEditor = new RecordTableCellEditor( $o->definedMeaningReference ); |
128 | 130 | $expressionEditor->addEditor( new LanguageEditor( $o->language, new SimplePermissionController( false ), false ) ); |
129 | | - $expressionEditor->addEditor( new SpellingEditor( $o->spelling, new SimplePermissionController( false ), false ) ); |
| 131 | + $expressionEditor->addEditor( new DefinedMeaningEditor( $o->definedMeaningId, new SimplePermissionController( false ), false ) ); |
130 | 132 | |
131 | 133 | $editor = new RecordSetTableEditor( null, new SimplePermissionController( false ), new ShowEditFieldChecker( true ), new AllowAddController( false ), false, false, null ); |
132 | 134 | $editor->addEditor( $expressionEditor ); |
133 | 135 | $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) ); |
134 | 136 | |
| 137 | + // cosmetics : changing the titles of the columns |
| 138 | + $o->definedMeaningReference->name = wfMsgSc( "Expression" ) ; |
| 139 | + $o->definedMeaningId->name = wfMsgSc( "Spelling" ) ; |
| 140 | + |
135 | 141 | global $wgOut; |
136 | 142 | |
137 | 143 | $wgOut->addHTML( "Showing $nbshown out of $queryResultCount" ) ; |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php |
— | — | @@ -35,7 +35,10 @@ |
36 | 36 | SpecialPage::addPage( new SpecialSuggest() ); |
37 | 37 | } |
38 | 38 | |
39 | | - |
| 39 | +/** |
| 40 | + * Creates and runs the appropriate SQL query when a combo box is clicked |
| 41 | + * the combo box table is filled with the SQL query results |
| 42 | + */ |
40 | 43 | function getSuggestions() { |
41 | 44 | $o = OmegaWikiAttributes::getInstance(); |
42 | 45 | global $wgUser; |
— | — | @@ -59,9 +62,9 @@ |
60 | 63 | $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) ); |
61 | 64 | break; |
62 | 65 | case 'class': |
63 | | - $sqlActual = getSQLForCollectionOfType( 'CLAS', $wgUser->getOption( 'language' ) ); |
64 | | - $sqlFallback = getSQLForCollectionOfType( 'CLAS', 'en' ); |
65 | | - $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) ); |
| 66 | + // constructSQLWithFallback is a bit broken in this case, showing several time the same lines |
| 67 | + // so : not using it. The English fall back has been included in the SQL query |
| 68 | + $sql = getSQLForClasses( $wgUser->getOption( 'language' ) ); |
66 | 69 | break; |
67 | 70 | case 'defined-meaning-attribute': |
68 | 71 | $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'DM' ); |
— | — | @@ -142,6 +145,7 @@ |
143 | 146 | if ( $offset > 0 ) |
144 | 147 | $sql .= " $offset, "; |
145 | 148 | |
| 149 | + // print only 10 results |
146 | 150 | $sql .= "10"; |
147 | 151 | |
148 | 152 | # == Actual query here |
— | — | @@ -364,6 +368,43 @@ |
365 | 369 | return $sql; |
366 | 370 | } |
367 | 371 | |
| 372 | +/** |
| 373 | + * Returns the name of all classes and their spelling in the user language or in English |
| 374 | + * |
| 375 | + * @param $language the 2 letter wikimedia code |
| 376 | + */ |
| 377 | +function getSQLForClasses( $language ) { |
| 378 | + $dc = wdGetDataSetContext(); |
| 379 | + |
| 380 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 381 | + $lng = '( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' )'; |
| 382 | + |
| 383 | + // exp.spelling, txt.text_text |
| 384 | + $sql = "SELECT member_mid, spelling " . |
| 385 | + " FROM {$dc}_collection_contents col_contents, {$dc}_collection col, {$dc}_syntrans synt," . |
| 386 | + " {$dc}_expression exp, {$dc}_defined_meaning dm" . |
| 387 | + " WHERE col.collection_type='CLAS' " . |
| 388 | + " AND col_contents.collection_id = col.collection_id " . |
| 389 | + " AND synt.defined_meaning_id = col_contents.member_mid " . |
| 390 | + " AND synt.identical_meaning=1 " . |
| 391 | + " AND exp.expression_id = synt.expression_id " . |
| 392 | + " AND dm.defined_meaning_id = synt.defined_meaning_id " . |
| 393 | + " AND ( " . |
| 394 | + " exp.language_id=$lng " . |
| 395 | + " OR (" . |
| 396 | + " exp.language_id=85 " . |
| 397 | + " AND dm.defined_meaning_id NOT IN ( SELECT defined_meaning_id FROM {$dc}_syntrans synt, {$dc}_expression exp WHERE exp.expression_id = synt.expression_id AND exp.language_id=$lng ) " . |
| 398 | + " ) " . |
| 399 | + " ) " . |
| 400 | + " AND " . getLatestTransactionRestriction( "col" ) . |
| 401 | + " AND " . getLatestTransactionRestriction( "col_contents" ) . |
| 402 | + " AND " . getLatestTransactionRestriction( "synt" ) . |
| 403 | + " AND " . getLatestTransactionRestriction( "exp" ) . |
| 404 | + " AND " . getLatestTransactionRestriction( "dm" ) ; |
| 405 | + |
| 406 | + return $sql; |
| 407 | +} |
| 408 | + |
368 | 409 | function getSQLForCollectionOfType( $collectionType, $language = "<ANY>" ) { |
369 | 410 | $dc = wdGetDataSetContext(); |
370 | 411 | $sql = "SELECT member_mid, spelling, collection_mid " . |
— | — | @@ -453,22 +494,30 @@ |
454 | 495 | return array( $recordSet, $editor ); |
455 | 496 | } |
456 | 497 | |
| 498 | +/** |
| 499 | + * Writes an html table from a sql table corresponding to the list of classes, as shown by |
| 500 | + * http://www.omegawiki.org/index.php?title=Special:Suggest&query=class |
| 501 | + * |
| 502 | + * @param $queryResult the result of a SQL query to be made into an html table |
| 503 | + */ |
457 | 504 | function getClassAsRecordSet( $queryResult ) { |
458 | 505 | |
459 | 506 | $o = OmegaWikiAttributes::getInstance(); |
460 | 507 | |
461 | 508 | $dbr =& wfGetDB( DB_SLAVE ); |
| 509 | + // Setting the two column, with titles |
462 | 510 | $classAttribute = new Attribute( "class", wfMsg( 'ow_Class' ), "short-text" ); |
463 | | - $collectionAttribute = new Attribute( "collection", wfMsg( 'ow_Collection' ), "short-text" ); |
464 | | - |
465 | | - $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttribute, $collectionAttribute ), new Structure( $o->id ) ); |
466 | | - |
467 | | - while ( $row = $dbr->fetchObject( $queryResult ) ) |
468 | | - $recordSet->addRecord( array( $row->member_mid, $row->spelling, definedMeaningExpression( $row->collection_mid ) ) ); |
| 511 | + $definitionAttribute = new Attribute( "definition", wfMsg( 'ow_Definition' ), "short-text" ); |
469 | 512 | |
| 513 | + $recordSet = new ArrayRecordSet( new Structure( $o->id, $classAttribute, $definitionAttribute ), new Structure( $o->id ) ); |
| 514 | + |
| 515 | + while ( $row = $dbr->fetchObject( $queryResult ) ) { |
| 516 | + $recordSet->addRecord( array( $row->member_mid, $row->spelling, getDefinedMeaningDefinition( $row->member_mid ) ) ); |
| 517 | + } |
| 518 | + |
470 | 519 | $editor = createSuggestionsTableViewer( null ); |
471 | 520 | $editor->addEditor( createShortTextViewer( $classAttribute ) ); |
472 | | - $editor->addEditor( createShortTextViewer( $collectionAttribute ) ); |
| 521 | + $editor->addEditor( createShortTextViewer( $definitionAttribute ) ); |
473 | 522 | |
474 | 523 | return array( $recordSet, $editor ); |
475 | 524 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -1006,6 +1006,12 @@ |
1007 | 1007 | $dbr->query( $sql ); |
1008 | 1008 | } |
1009 | 1009 | |
| 1010 | +/** |
| 1011 | + * Returns the definition of a definedMeaning in a given language |
| 1012 | + * @param $definedMeaningId |
| 1013 | + * @param $languageId |
| 1014 | + * @param $dc |
| 1015 | + */ |
1010 | 1016 | function getDefinedMeaningDefinitionForLanguage( $definedMeaningId, $languageId, $dc = null ) { |
1011 | 1017 | if ( is_null( $dc ) ) { |
1012 | 1018 | $dc = wdGetDataSetContext(); |
— | — | @@ -1025,6 +1031,11 @@ |
1026 | 1032 | return ""; |
1027 | 1033 | } |
1028 | 1034 | |
| 1035 | +/** |
| 1036 | + * Returns the definition of a definedMeaning in any language |
| 1037 | + * according to which definition comes up first in the SQL query |
| 1038 | + * @param $definedMeaningId |
| 1039 | + */ |
1029 | 1040 | function getDefinedMeaningDefinitionForAnyLanguage( $definedMeaningId ) { |
1030 | 1041 | $dc = wdGetDataSetContext(); |
1031 | 1042 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -1041,6 +1052,11 @@ |
1042 | 1053 | return ""; |
1043 | 1054 | } |
1044 | 1055 | |
| 1056 | +/** |
| 1057 | + * Returns the definition of a definedMeaning in the user language, or in English, or in any other |
| 1058 | + * according to what is available |
| 1059 | + * @param $definedMeaningId |
| 1060 | + */ |
1045 | 1061 | function getDefinedMeaningDefinition( $definedMeaningId ) { |
1046 | 1062 | global |
1047 | 1063 | $wgUser; |
— | — | @@ -1493,6 +1509,11 @@ |
1494 | 1510 | } |
1495 | 1511 | } |
1496 | 1512 | |
| 1513 | +/** |
| 1514 | + * Returns one spelling of an expression corresponding to a given DM in a given language |
| 1515 | + * @param $definedMeaningId |
| 1516 | + * @param $languageId |
| 1517 | + */ |
1497 | 1518 | function definedMeaningExpressionForLanguage( $definedMeaningId, $languageId ) { |
1498 | 1519 | $dc = wdGetDataSetContext(); |
1499 | 1520 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -1514,6 +1535,10 @@ |
1515 | 1536 | return ""; |
1516 | 1537 | } |
1517 | 1538 | |
| 1539 | +/** |
| 1540 | + * Returns one spelling of an expression corresponding to a given DM in any language |
| 1541 | + * @param $definedMeaningId |
| 1542 | + */ |
1518 | 1543 | function definedMeaningExpressionForAnyLanguage( $definedMeaningId ) { |
1519 | 1544 | $dc = wdGetDataSetContext(); |
1520 | 1545 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -1533,6 +1558,13 @@ |
1534 | 1559 | return ""; |
1535 | 1560 | } |
1536 | 1561 | |
| 1562 | +/** |
| 1563 | + * Returns one spelling of an expression corresponding to a given DM |
| 1564 | + * - in a given language if it exists |
| 1565 | + * - or else in English |
| 1566 | + * - or else in any language |
| 1567 | + * @param $definedMeaningId |
| 1568 | + */ |
1537 | 1569 | function definedMeaningExpression( $definedMeaningId ) { |
1538 | 1570 | global |
1539 | 1571 | $wgUser; |
— | — | @@ -1550,6 +1582,7 @@ |
1551 | 1583 | $result = ""; |
1552 | 1584 | |
1553 | 1585 | if ( $result == "" ) { |
| 1586 | + // if no expression exists for the specified language : look for an expression in English |
1554 | 1587 | $result = definedMeaningExpressionForLanguage( $definedMeaningId, 85 ); |
1555 | 1588 | |
1556 | 1589 | if ( $result == "" ) { |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -1015,6 +1015,30 @@ |
1016 | 1016 | } |
1017 | 1017 | } |
1018 | 1018 | |
| 1019 | +class DefinedMeaningEditor extends ScalarEditor { |
| 1020 | + public function getViewHTML( IdStack $idPath, $value ) { |
| 1021 | + return definedMeaningAsLink( $value ); |
| 1022 | + } |
| 1023 | + |
| 1024 | + public function getEditHTML( IdStack $idPath, $value ) { |
| 1025 | + return ""; |
| 1026 | + } |
| 1027 | + |
| 1028 | + public function add( IdStack $idPath ) { |
| 1029 | + if ( $this->isAddField ) |
| 1030 | + return getTextBox( $this->addId( $idPath->getId() ) ); |
| 1031 | + else |
| 1032 | + return ""; |
| 1033 | + } |
| 1034 | + |
| 1035 | + public function getInputValue( $id ) { |
| 1036 | + global |
| 1037 | + $wgRequest; |
| 1038 | + |
| 1039 | + return trim( $wgRequest->getText( $id ) ); |
| 1040 | + } |
| 1041 | +} |
| 1042 | + |
1019 | 1043 | class DefinedMeaningHeaderEditor extends ScalarEditor { |
1020 | 1044 | protected $truncate; |
1021 | 1045 | protected $truncateAt; |