Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -214,14 +214,14 @@ |
215 | 215 | return 0; |
216 | 216 | } |
217 | 217 | |
218 | | -function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning ) { |
| 218 | +function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = 1 ) { |
219 | 219 | |
220 | 220 | $dc = wdGetDataSetContext(); |
221 | | - |
222 | 221 | $synonymId = getSynonymId( $definedMeaningId, $expressionId ); |
223 | 222 | |
224 | | - if ( $synonymId == 0 ) |
| 223 | + if ( $synonymId == 0 ) { |
225 | 224 | $synonymId = newObjectId( "{$dc}_syntrans" ); |
| 225 | + } |
226 | 226 | |
227 | 227 | $dbw = wfGetDB( DB_MASTER ); |
228 | 228 | $identicalMeaningInteger = (int) $identicalMeaning; |
— | — | @@ -1664,10 +1664,22 @@ |
1665 | 1665 | $dbr = wfGetDB( DB_SLAVE ); |
1666 | 1666 | |
1667 | 1667 | $spelling = $dbr->addQuotes( $spelling ); |
1668 | | - $queryResult = $dbr->query( "SELECT * FROM {$dc}_expression WHERE spelling=$spelling AND " . getLatestTransactionRestriction( "{$dc}_expression" ) ); |
| 1668 | + $sql = "SELECT * FROM {$dc}_expression " . |
| 1669 | + " WHERE spelling=binary $spelling " . |
| 1670 | + " AND {$dc}_expression.remove_transaction_id IS NULL" ; |
1669 | 1671 | |
| 1672 | + // needed because expression.remove_transaction_id is not updated automatically |
| 1673 | + $sql .= " AND EXISTS (" . |
| 1674 | + "SELECT * " . |
| 1675 | + " FROM {$dc}_syntrans " . |
| 1676 | + " WHERE {$dc}_syntrans.expression_id={$dc}_expression.expression_id" . |
| 1677 | + " AND {$dc}_syntrans.remove_transaction_id IS NULL " . |
| 1678 | + ")"; |
| 1679 | + |
| 1680 | + $queryResult = $dbr->query( $sql ); |
| 1681 | + |
1670 | 1682 | $rv = array(); |
1671 | | - while ( $expressionRecord = $dbr->fetchObject( $queryResult ) ) { |
| 1683 | + foreach ( $queryResult as $expressionRecord ) { |
1672 | 1684 | $rv[] = new Expression( $expressionRecord->expression_id, $expressionRecord->spelling, $expressionRecord->language_id ); |
1673 | 1685 | } |
1674 | 1686 | $dbr->freeResult( $queryResult ) ; |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -502,6 +502,9 @@ |
503 | 503 | return $editor; |
504 | 504 | } |
505 | 505 | |
| 506 | +/** |
| 507 | + * Attribute is $o->expression |
| 508 | + */ |
506 | 509 | function getExpressionTableCellEditor( Attribute $attribute, ViewInformation $viewInformation ) { |
507 | 510 | $o = OmegaWikiAttributes::getInstance(); |
508 | 511 | |
— | — | @@ -751,13 +754,15 @@ |
752 | 755 | |
753 | 756 | $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, true, $viewInformation ); |
754 | 757 | $expressionMeaningsRecordEditor->addEditor( $exactMeaningsEditor ); |
755 | | - $expressionMeaningsRecordEditor->addEditor( getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) ); |
756 | | - |
| 758 | + $approximateMeaningsEditor = getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) ; |
| 759 | + $expressionMeaningsRecordEditor->addEditor( $approximateMeaningsEditor ); |
| 760 | + |
757 | 761 | $expressionMeaningsRecordEditor->expandEditor( $exactMeaningsEditor ); |
758 | | - |
| 762 | + |
759 | 763 | if ( $viewInformation->filterLanguageId == 0 ) { |
| 764 | + // show all languages |
760 | 765 | $expressionEditor = new RecordSpanEditor( $o->expression, ': ', ' - ' ); |
761 | | - $expressionEditor->addEditor( new LanguageEditor( $o->language, new SimplePermissionController( false ), true ) ); |
| 766 | + $expressionEditor->addEditor( new DropdownLanguageEditor( $o->language, new SimplePermissionController( false ), true ) ); |
762 | 767 | |
763 | 768 | $expressionsEditor = new RecordSetListEditor( |
764 | 769 | $o->expressions, |
— | — | @@ -767,13 +772,15 @@ |
768 | 773 | false, |
769 | 774 | false, |
770 | 775 | new ExpressionController( $spelling, $viewInformation->filterLanguageId ), |
771 | | - 2, |
772 | | - true |
| 776 | + 2, // headerLevel |
| 777 | + true // childrenExpanded |
773 | 778 | ); |
| 779 | + $expressionsEditor->setCollapsible( false ); |
774 | 780 | $expressionsEditor->setCaptionEditor( $expressionEditor ); |
775 | 781 | $expressionsEditor->setValueEditor( $expressionMeaningsRecordEditor ); |
776 | 782 | } |
777 | 783 | else { |
| 784 | + // show only one language |
778 | 785 | $expressionEditor = new RecordSubRecordEditor( $o->expression ); |
779 | 786 | $expressionEditor->setSubRecordEditor( $expressionMeaningsRecordEditor ); |
780 | 787 | |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php |
— | — | @@ -3,12 +3,9 @@ |
4 | 4 | require_once( 'OmegaWikiAttributes.php' ); |
5 | 5 | require_once( 'Record.php' ); |
6 | 6 | require_once( 'RecordSet.php' ); |
7 | | -require_once( 'WikiDataAPI.php' ); |
8 | | -require_once( 'Transaction.php' ); |
9 | | -require_once( 'WikiDataTables.php' ); |
10 | 7 | require_once( 'RecordSetQueries.php' ); |
11 | | -require_once( 'DefinedMeaningModel.php' ); |
12 | 8 | require_once( 'ViewInformation.php' ); |
| 9 | +require_once( 'Wikidata.php' ); |
13 | 10 | require_once( 'WikiDataGlobals.php' ); |
14 | 11 | |
15 | 12 | |
— | — | @@ -18,9 +15,9 @@ |
19 | 16 | # Query building |
20 | 17 | $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
21 | 18 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
22 | | - " WHERE " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
23 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
24 | | - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
| 19 | + " WHERE {$dc}_syntrans.remove_transaction_id IS NULL " . |
| 20 | + " AND {$dc}_expression.remove_transaction_id IS NULL " . |
| 21 | + " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " . |
25 | 22 | " AND {$dc}_expression.language_id=" . $languageId . |
26 | 23 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
27 | 24 | " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " . |
— | — | @@ -41,9 +38,9 @@ |
42 | 39 | # Query building |
43 | 40 | $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
44 | 41 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
45 | | - " WHERE " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
46 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
47 | | - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
| 42 | + " WHERE {$dc}_syntrans.remove_transaction_id IS NULL " . |
| 43 | + " AND {$dc}_expression.remove_transaction_id IS NULL " . |
| 44 | + " AND {$dc}_defined_meaning.remove_transaction_id IS NULL" . |
48 | 45 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
49 | 46 | " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " . |
50 | 47 | " AND {$dc}_syntrans.identical_meaning=1 " . |
— | — | @@ -63,9 +60,9 @@ |
64 | 61 | # Query building |
65 | 62 | $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " . |
66 | 63 | " FROM {$dc}_defined_meaning, {$dc}_syntrans, {$dc}_expression " . |
67 | | - " WHERE " . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
68 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
69 | | - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
| 64 | + " WHERE {$dc}_syntrans.remove_transaction_id IS NULL " . |
| 65 | + " AND {$dc}_expression.remove_transaction_id IS NULL " . |
| 66 | + " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " . |
70 | 67 | " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " . |
71 | 68 | " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " . |
72 | 69 | " AND {$dc}_syntrans.identical_meaning=1 " . |
— | — | @@ -101,7 +98,7 @@ |
102 | 99 | $record = new ArrayRecord( $specificStructure ); |
103 | 100 | $record->definedMeaningId = $definedMeaningId; |
104 | 101 | $record->definedMeaningLabel = $row->label; |
105 | | - |
| 102 | + |
106 | 103 | $definedMeaningReferenceRecords[$definedMeaningId] = $record; |
107 | 104 | $foundDefinedMeaningIds[] = $definedMeaningId; |
108 | 105 | } |
— | — | @@ -121,8 +118,8 @@ |
122 | 119 | $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" . |
123 | 120 | " FROM {$dc}_defined_meaning, {$dc}_expression " . |
124 | 121 | " WHERE {$dc}_defined_meaning.expression_id={$dc}_expression.expression_id " . |
125 | | - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . |
126 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 122 | + " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " . |
| 123 | + " AND {$dc}_expression.remove_transaction_id IS NULL " . |
127 | 124 | " AND {$dc}_defined_meaning.defined_meaning_id = "; |
128 | 125 | |
129 | 126 | # Build atomic queries |
— | — | @@ -320,7 +317,7 @@ |
321 | 318 | |
322 | 319 | # Prepare steady components |
323 | 320 | $frontQuery = "SELECT expression_id, spelling FROM {$dc}_expression WHERE expression_id ="; |
324 | | - $queueQuery = " AND " . getLatestTransactionRestriction( "{$dc}_expression" ); |
| 321 | + $queueQuery = " AND {$dc}_expression.remove_transaction_id IS NULL "; |
325 | 322 | # Build atomic queries |
326 | 323 | foreach ( $expressionIds as &$value ) { $value = $frontQuery . $value . $queueQuery; } |
327 | 324 | unset( $value ); |
— | — | @@ -414,7 +411,7 @@ |
415 | 412 | $queryResult = $dbr->query( |
416 | 413 | "SELECT defined_meaning_id FROM {$dc}_syntrans" . |
417 | 414 | " WHERE expression_id=$expressionId AND identical_meaning=" . $identicalMeaning . |
418 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) |
| 415 | + " AND {$dc}_syntrans.remove_transaction_id IS NULL " |
419 | 416 | ); |
420 | 417 | |
421 | 418 | while ( $definedMeaning = $dbr->fetchObject( $queryResult ) ) { |
— | — | @@ -446,27 +443,27 @@ |
447 | 444 | $dc = wdGetDataSetContext( $dc ); |
448 | 445 | $o = OmegaWikiAttributes::getInstance(); |
449 | 446 | |
450 | | - $languageRestriction = $viewInformation->filterLanguageId != 0 ? " AND language_id=" . $viewInformation->filterLanguageId : ""; |
451 | | - |
452 | 447 | $dbr = wfGetDB( DB_SLAVE ); |
453 | 448 | $sql = |
454 | 449 | "SELECT expression_id, language_id " . |
455 | 450 | " FROM {$dc}_expression" . |
456 | 451 | " WHERE spelling=BINARY " . $dbr->addQuotes( $spelling ) . |
457 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
458 | | - $languageRestriction . |
459 | | - " AND EXISTS (" . |
460 | | - "SELECT expression_id " . |
461 | | - " FROM {$dc}_syntrans " . |
462 | | - " WHERE {$dc}_syntrans.expression_id={$dc}_expression.expression_id" . |
463 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) |
464 | | - . ")"; |
| 452 | + " AND {$dc}_expression.remove_transaction_id IS NULL " ; |
| 453 | + |
| 454 | + if ( $viewInformation->expressionLanguageId != 0 ) { |
| 455 | + // display the expression in that language |
| 456 | + $sql .= " AND language_id=" . $viewInformation->expressionLanguageId ; |
| 457 | + } else { |
| 458 | + // no language is given: display in any language that comes first |
| 459 | + $sql .= " LIMIT 1"; |
| 460 | + } |
| 461 | + |
465 | 462 | $queryResult = $dbr->query( $sql ); |
466 | 463 | |
467 | 464 | $result = new ArrayRecordSet( $o->expressionsStructure, new Structure( "expression-id", $o->expressionId ) ); |
468 | 465 | $languageStructure = new Structure( "language", $o->language ); |
469 | 466 | |
470 | | - while ( $expression = $dbr->fetchObject( $queryResult ) ) { |
| 467 | + foreach ( $queryResult as $expression ) { |
471 | 468 | $expressionRecord = new ArrayRecord( $languageStructure ); |
472 | 469 | $expressionRecord->language = $expression->language_id; |
473 | 470 | |
— | — | @@ -488,26 +485,26 @@ |
489 | 486 | "SELECT expression_id, language_id " . |
490 | 487 | " FROM {$dc}_expression" . |
491 | 488 | " WHERE spelling=BINARY " . $dbr->addQuotes( $spelling ) . |
492 | | - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 489 | + " AND {$dc}_expression.remove_transaction_id IS NULL " . |
493 | 490 | " AND language_id=$languageId" . |
494 | 491 | " AND EXISTS (" . |
495 | 492 | "SELECT expression_id " . |
496 | 493 | " FROM {$dc}_syntrans " . |
497 | 494 | " WHERE {$dc}_syntrans.expression_id={$dc}_expression.expression_id" . |
498 | | - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) |
| 495 | + " AND {$dc}_syntrans.remove_transaction_id IS NULL " |
499 | 496 | . ")" |
500 | 497 | ); |
501 | 498 | |
502 | | - if ( $expression = $dbr->fetchObject( $queryResult ) ) |
| 499 | + if ( $expression = $dbr->fetchObject( $queryResult ) ) { |
503 | 500 | return $expression->expression_id; |
504 | | - else |
| 501 | + } else { |
505 | 502 | return 0; |
| 503 | + } |
506 | 504 | } |
507 | 505 | |
508 | 506 | |
509 | 507 | function getClassAttributesRecordSet( $definedMeaningId, ViewInformation $viewInformation ) { |
510 | | - global |
511 | | - $dataSet; |
| 508 | + global $dataSet; |
512 | 509 | |
513 | 510 | $o = OmegaWikiAttributes::getInstance(); |
514 | 511 | |
— | — | @@ -543,8 +540,7 @@ |
544 | 541 | } |
545 | 542 | |
546 | 543 | function getAlternativeDefinitionsRecordSet( $definedMeaningId, ViewInformation $viewInformation ) { |
547 | | - global |
548 | | - $dataSet; |
| 544 | + global $dataSet; |
549 | 545 | |
550 | 546 | $o = OmegaWikiAttributes::getInstance(); |
551 | 547 | |
— | — | @@ -698,8 +694,7 @@ |
699 | 695 | } |
700 | 696 | |
701 | 697 | function getTranslatedContentRecordSet( $translatedContentId, ViewInformation $viewInformation ) { |
702 | | - global |
703 | | - $dataSet; |
| 698 | + global $dataSet; |
704 | 699 | |
705 | 700 | $o = OmegaWikiAttributes::getInstance(); |
706 | 701 | |
— | — | @@ -721,8 +716,7 @@ |
722 | 717 | } |
723 | 718 | |
724 | 719 | function getFilteredTranslatedContentRecordSet( $translatedContentId, ViewInformation $viewInformation ) { |
725 | | - global |
726 | | - $dataSet; |
| 720 | + global $dataSet; |
727 | 721 | |
728 | 722 | $o = OmegaWikiAttributes::getInstance(); |
729 | 723 | |
— | — | @@ -747,8 +741,7 @@ |
748 | 742 | } |
749 | 743 | |
750 | 744 | function getSynonymAndTranslationRecordSet( $definedMeaningId, ViewInformation $viewInformation ) { |
751 | | - global |
752 | | - $dataSet; |
| 745 | + global $dataSet; |
753 | 746 | |
754 | 747 | $o = OmegaWikiAttributes::getInstance(); |
755 | 748 | $dc = wdGetDataSetContext(); |
— | — | @@ -761,7 +754,7 @@ |
762 | 755 | " FROM {$dc}_expression AS expressions" . |
763 | 756 | " WHERE expressions.expression_id=expression_id" . |
764 | 757 | " AND language_id=" . $viewInformation->filterLanguageId . |
765 | | - " AND " . getLatestTransactionRestriction( 'expressions' ) . |
| 758 | + " AND expressions.remove_transaction_id IS NULL " . |
766 | 759 | ")"; |
767 | 760 | |
768 | 761 | $recordSet = queryRecordSet( |
Index: trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php |
— | — | @@ -12,16 +12,33 @@ |
13 | 13 | */ |
14 | 14 | |
15 | 15 | class ViewInformation { |
| 16 | + /** |
| 17 | + * if != 0: shows only translations and definitions in this language |
| 18 | + * if = 0 : display all languages |
| 19 | + */ |
16 | 20 | public $filterLanguageId; |
| 21 | + |
| 22 | + /** |
| 23 | + * The language of the expression being displayed in the Expression: namespace |
| 24 | + * i.e. the word being consulted |
| 25 | + */ |
| 26 | + public $expressionLanguageId; |
| 27 | + |
17 | 28 | public $queryTransactionInformation; |
18 | 29 | public $showRecordLifeSpan; |
19 | | - public $viewOrEdit; |
| 30 | + public $viewOrEdit; ///< either "view" or "edit" |
20 | 31 | |
21 | 32 | protected $propertyToColumnFilters; |
22 | 33 | |
| 34 | + /** |
| 35 | + * Constructor |
| 36 | + */ |
23 | 37 | public function __construct() { |
| 38 | + global $wgRequest ; |
| 39 | + |
24 | 40 | $this->filterLanguageId = 0; |
25 | | - $this->queryTransactionInformation; |
| 41 | + $this->expressionLanguageId = $wgRequest->getVal( 'explang', 0 ); |
| 42 | + $this->queryTransactionInformation = null; |
26 | 43 | $this->showRecordLifeSpan = false; |
27 | 44 | $this->propertyToColumnFilters = array(); |
28 | 45 | $this->viewOrEdit = "view"; |
— | — | @@ -31,6 +48,10 @@ |
32 | 49 | return $this->showRecordLifeSpan; |
33 | 50 | } |
34 | 51 | |
| 52 | + /** |
| 53 | + * @return true if we are filtering according to a language |
| 54 | + * @return false if all languages are displayed |
| 55 | + */ |
35 | 56 | public function filterOnLanguage() { |
36 | 57 | return $this->filterLanguageId != 0; |
37 | 58 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/type.php |
— | — | @@ -43,8 +43,21 @@ |
44 | 44 | return $url; |
45 | 45 | } |
46 | 46 | |
47 | | -function spellingAsURL( $spelling ) { |
48 | | - return pageAsURL( "Expression", $spelling ); |
| 47 | +function spellingAsURL( $spelling, $lang = 0 ) { |
| 48 | + global $wdDefaultViewDataSet; |
| 49 | + |
| 50 | + $title = Title::makeTitle( NS_EXPRESSION, $spelling ); |
| 51 | + $query = array() ; |
| 52 | + |
| 53 | + $dc = wdGetDataSetContext(); |
| 54 | + if ( $dc != $wdDefaultViewDataSet ) { |
| 55 | + $query['dataset'] = $dc ; |
| 56 | + } |
| 57 | + if ( $lang != 0 ) { |
| 58 | + $query['explang'] = $lang ; |
| 59 | + } |
| 60 | + |
| 61 | + return $title->getLocalURL( $query ) ; |
49 | 62 | } |
50 | 63 | |
51 | 64 | function definedMeaningReferenceAsURL( $definedMeaningId, $definingExpression ) { |
— | — | @@ -59,8 +72,8 @@ |
60 | 73 | return '<a href="' . htmlspecialchars( $url ) . '">' . htmlspecialchars( $text ) . '</a>'; |
61 | 74 | } |
62 | 75 | |
63 | | -function spellingAsLink( $spelling ) { |
64 | | - return createLink( spellingAsURL( $spelling ), $spelling ); |
| 76 | +function spellingAsLink( $spelling, $lang = 0 ) { |
| 77 | + return createLink( spellingAsURL( $spelling, $lang ), $spelling ); |
65 | 78 | } |
66 | 79 | |
67 | 80 | function definedMeaningReferenceAsLink( $definedMeaningId, $definingExpression, $label ) { |
Index: trunk/extensions/Wikidata/OmegaWiki/resources/tables.css |
— | — | @@ -102,7 +102,48 @@ |
103 | 103 | width: auto; |
104 | 104 | } |
105 | 105 | |
| 106 | +span.wd-dropdown { |
| 107 | + position: relative; |
| 108 | + border-radius: 5px; |
| 109 | +/* |
| 110 | + * background-color: #ffe0eb; |
| 111 | + */ |
| 112 | +} |
106 | 113 | |
| 114 | +span.wd-dropdown:hover { |
| 115 | + background-color: #fdeeff; |
| 116 | +} |
| 117 | + |
| 118 | +ul.wd-dropdownlist { |
| 119 | + list-style: none; |
| 120 | + position: absolute; |
| 121 | + left: 0; |
| 122 | +/* |
| 123 | + top: 20px; |
| 124 | +*/ |
| 125 | + margin: 0; |
| 126 | + padding-top: 5px; |
| 127 | + padding-left: 5px; |
| 128 | + padding-right: 10px; |
| 129 | + padding-bottom: 2px; |
| 130 | + display: none; |
| 131 | + float: left; |
| 132 | + z-index: 1; |
| 133 | + background-color: #fdeeff; |
| 134 | + border-style:none; |
| 135 | + font-size:90% ; |
| 136 | + box-shadow:5px 5px 20px black; |
| 137 | + border-radius: 5px; |
| 138 | +} |
| 139 | + |
| 140 | +ul.wd-dropdownlist li a{ |
| 141 | + text-decoration: none; |
| 142 | + color: gray; |
| 143 | +} |
| 144 | +ul.wd-dropdownlist li a:hover{ |
| 145 | + color: black; |
| 146 | +} |
| 147 | + |
107 | 148 | .level2 { |
108 | 149 | font-size:150% ; |
109 | 150 | background-color: #ffe0eb; |
— | — | @@ -111,6 +152,8 @@ |
112 | 153 | border-color:grey; |
113 | 154 | margin-top:10px; |
114 | 155 | padding:5px; |
| 156 | + border-radius: 100px; |
| 157 | + -moz-border-radius: 100px; |
115 | 158 | } |
116 | 159 | |
117 | 160 | .level3 { |
Index: trunk/extensions/Wikidata/OmegaWiki/resources/omegawiki-ajax.js |
— | — | @@ -1,6 +1,20 @@ |
2 | 2 | |
3 | | -jQuery(function() { sortAll(); }); |
| 3 | +jQuery(function() { |
| 4 | + |
| 5 | + // sort all tables |
| 6 | + sortAll(); |
4 | 7 | |
| 8 | + // create the dropdown menu (e.g. to select a language in the Expression: namespace) |
| 9 | + $("span.wd-dropdown").hover(function() { |
| 10 | + //Drop down the dropdownmenu |
| 11 | + $(this).parent().find("ul.wd-dropdownlist").show(); |
| 12 | + }, function(){ //On Hover Out |
| 13 | + $(this).parent().find("ul.wd-dropdownlist").hide(); |
| 14 | + } |
| 15 | +}); // jQuery |
| 16 | + |
| 17 | +//TODO: convert the functions below to jQuery... |
| 18 | + |
5 | 19 | window.elementsToSort = new Array(); |
6 | 20 | |
7 | 21 | window.isFormElement = function (node) { |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -240,11 +240,13 @@ |
241 | 241 | protected $editors; |
242 | 242 | protected $attributeEditorMap; |
243 | 243 | protected $attribute; |
| 244 | + protected $isCollapsible; |
244 | 245 | |
245 | 246 | public function __construct( Attribute $attribute = null ) { |
246 | 247 | $this->attribute = $attribute; |
247 | 248 | $this->editors = array(); |
248 | 249 | $this->attributeEditorMap = new AttributeEditorMap(); |
| 250 | + $this->isCollapsible = true; |
249 | 251 | } |
250 | 252 | |
251 | 253 | public function addEditor( Editor $editor ) { |
— | — | @@ -264,8 +266,38 @@ |
265 | 267 | return $this->attributeEditorMap; |
266 | 268 | } |
267 | 269 | |
| 270 | + /** |
| 271 | + * returns true if the editor is collapsible |
| 272 | + * @return boolean |
| 273 | + */ |
| 274 | + public function getCollapsible() { |
| 275 | + return $this->isCollapsible; |
| 276 | + } |
| 277 | + |
| 278 | + /** |
| 279 | + * set the editor as collapsible or not collapsible |
| 280 | + * @param $value boolean |
| 281 | + */ |
| 282 | + public function setCollapsible( $value ) { |
| 283 | + $this->isCollapsible = $value; |
| 284 | + } |
| 285 | + |
268 | 286 | public function getExpansionPrefix( $class, $elementId ) { |
269 | | - return '<span id="prefix-collapsed-' . $elementId . '" class="collapse-' . $class . '">▶</span><span id="prefix-expanded-' . $elementId . '" class="expand-' . $class . '">▼</span>' . EOL; |
| 287 | + if ( ! $this->isCollapsible ) { |
| 288 | + return ''; |
| 289 | + } |
| 290 | + |
| 291 | + // if it is collapsible, continue |
| 292 | + $prefix = HTML::element('span', array( |
| 293 | + 'id' => "prefix-collapsed-$elementId" , |
| 294 | + 'class' => "collapse-$class" |
| 295 | + ) , "▶" ) ; |
| 296 | + $prefix .= HTML::element('span', array( |
| 297 | + 'id' => "prefix-expanded-$elementId" , |
| 298 | + 'class' => "expand-$class" |
| 299 | + ) , "▼" ) ; |
| 300 | + |
| 301 | + return $prefix ; |
270 | 302 | } |
271 | 303 | |
272 | 304 | static private $staticExpansionStyles = array(); |
— | — | @@ -603,10 +635,11 @@ |
604 | 636 | foreach ( $editor->getEditors() as $childEditor ) { |
605 | 637 | $childAttribute = $childEditor->getAttribute(); |
606 | 638 | |
607 | | - if ( $childEditor instanceof RecordTableCellEditor ) |
| 639 | + if ( $childEditor instanceof RecordTableCellEditor ) { |
608 | 640 | $type = $this->getTableStructure( $childEditor ); |
609 | | - else |
| 641 | + } else { |
610 | 642 | $type = 'short-text'; |
| 643 | + } |
611 | 644 | |
612 | 645 | $attributes[] = new Attribute( $childAttribute->id, $childAttribute->name, $type ); |
613 | 646 | } |
— | — | @@ -940,7 +973,10 @@ |
941 | 974 | } |
942 | 975 | } |
943 | 976 | |
944 | | -/* XXX: What is this for? */ |
| 977 | +/** |
| 978 | + * ScalarEditor is an editor that shows one field |
| 979 | + * such as a cell in a table. |
| 980 | + */ |
945 | 981 | abstract class ScalarEditor extends DefaultEditor { |
946 | 982 | protected $permissionController; |
947 | 983 | protected $isAddField; |
— | — | @@ -1043,7 +1079,99 @@ |
1044 | 1080 | } |
1045 | 1081 | } |
1046 | 1082 | |
| 1083 | +/** |
| 1084 | + * Shows one language at a time, but when clicked, it shows |
| 1085 | + * a drop-down menu with other available languages |
| 1086 | + * (for a given expression as defined in IdStack) |
| 1087 | + * the dropdown is generated with jQuery from a list <ul>. |
| 1088 | + * $value is the currently displayed language |
| 1089 | + */ |
| 1090 | +class DropdownLanguageEditor extends ScalarEditor { |
| 1091 | + public function getViewHTML( IdStack $idPath, $value ) { |
| 1092 | + global $wgRequest; |
| 1093 | + $dc = wdGetDataSetContext(); |
| 1094 | + $output = ""; |
| 1095 | + |
| 1096 | + // We must find the spelling and the list of possible languages from $idPath |
| 1097 | + $expressionId = $idPath->getKeyStack()->peek( 0 )->expressionId; |
| 1098 | + $spelling = getExpression( $expressionId, $dc )->spelling; |
| 1099 | + $title = Title::makeTitle( NS_EXPRESSION, $spelling ); |
| 1100 | + $expressionsArray = getExpressions( $spelling, $dc ) ; |
| 1101 | + |
| 1102 | + $languageIdList = array() ; |
| 1103 | + foreach ( $expressionsArray as $expression ) { |
| 1104 | + if ( $expression->languageId != $value ) { |
| 1105 | + // only add languages that are not the current language |
| 1106 | + $languageIdList[] = $expression->languageId ; |
| 1107 | + } |
| 1108 | + } |
| 1109 | + |
| 1110 | + if ( count($languageIdList) > 0 ) { |
| 1111 | + // there are other languages as alternative, prepare the dropdown |
| 1112 | + $output .= Html::openElement('span', array('class' => 'wd-dropdown') ) ; |
| 1113 | + } |
| 1114 | + |
| 1115 | + // displays the name of the current language |
| 1116 | + // this is the only thing that is displayed if there are no other language available |
| 1117 | + $output .= languageIdAsText( $value ) ; |
| 1118 | + |
| 1119 | + if ( count($languageIdList) > 0 ) { |
| 1120 | + // there might be duplicates |
| 1121 | + $languageIdList = array_unique ( $languageIdList ) ; |
| 1122 | + |
| 1123 | + // Now the names |
| 1124 | + $languageNameList = array(); |
| 1125 | + foreach ( $languageIdList as $languageId ) { |
| 1126 | + $languageNameList[$languageId] = languageIdAsText($languageId) ; |
| 1127 | + } |
| 1128 | + asort($languageNameList); |
| 1129 | + |
| 1130 | + // build the list <ul> |
| 1131 | + $output .= ' ▿' ; |
| 1132 | + |
| 1133 | + // now the <li> definining the menu |
| 1134 | + // display: none is also in the .css, but defined here to prevent the list to show |
| 1135 | + // when the .css is not yet loaded. |
| 1136 | + $output .= Html::openElement('ul', array('class' => 'wd-dropdownlist', 'style' => 'display: none;' )); |
| 1137 | + foreach ( $languageNameList as $languageId => $languageName ) { |
| 1138 | + $output .= Html::openElement('li'); |
| 1139 | + |
| 1140 | + $urlOptions = array( 'explang' => $languageId ); |
| 1141 | + if ( $wgRequest->getVal("action") == "edit" ) { |
| 1142 | + $urlOptions['action'] = "edit" ; |
| 1143 | + } |
| 1144 | + $aHref = $title->getLocalURL( $urlOptions ) ; |
| 1145 | + $output .= Html::rawElement('a', array('href' => $aHref), $languageName ); |
| 1146 | + $output .= Html::closeElement('li'); |
| 1147 | + } |
| 1148 | + $output .= Html::closeElement('ul'); |
| 1149 | + $output .= Html::closeElement('span'); |
| 1150 | + } |
| 1151 | + |
| 1152 | + return $output; |
| 1153 | + } |
| 1154 | + |
| 1155 | + public function getEditHTML( IdStack $idPath, $value ) { |
| 1156 | + return getSuggest( $this->updateId( $idPath->getId() ), "language" ); |
| 1157 | + } |
| 1158 | + |
| 1159 | + public function add( IdStack $idPath ) { |
| 1160 | + return getSuggest( $this->addId( $idPath->getId() ), "language" ); |
| 1161 | + } |
| 1162 | + |
| 1163 | + public function getInputValue( $id ) { |
| 1164 | + global $wgRequest; |
| 1165 | + |
| 1166 | + return $wgRequest->getInt( $id ); |
| 1167 | + } |
| 1168 | + |
| 1169 | + public function showsData( $value ) { |
| 1170 | + return ( $value != null ) && ( $value != 0 ); |
| 1171 | + } |
| 1172 | +} |
| 1173 | + |
1047 | 1174 | class SpellingEditor extends ScalarEditor { |
| 1175 | + |
1048 | 1176 | public function getViewHTML( IdStack $idPath, $value ) { |
1049 | 1177 | return spellingAsLink( $value ); |
1050 | 1178 | } |
— | — | @@ -1907,7 +2035,7 @@ |
1908 | 2036 | $recordCount = $value->getRecordCount(); |
1909 | 2037 | |
1910 | 2038 | if ( $recordCount > 0 ) { |
1911 | | - $result = '<ul class="collapsable-items">' . EOL; |
| 2039 | + $result = HTML::openElement ('ul', array( 'class' => 'collapsable-items')) ; |
1912 | 2040 | $key = $value->getKey(); |
1913 | 2041 | $captionAttribute = $this->captionEditor->getAttribute(); |
1914 | 2042 | $valueAttribute = $this->valueEditor->getAttribute(); |
— | — | @@ -1923,19 +2051,37 @@ |
1924 | 2052 | $this->setExpansion( $this->childrenExpanded, $valueClass ); |
1925 | 2053 | |
1926 | 2054 | $idPath->pushAttribute( $captionAttribute ); |
1927 | | - $result .= '<li><div class="level' . $this->headerLevel . '"><span id="collapse-' . $recordId . '" class="toggle ' . addCollapsablePrefixToClass( $captionClass ) . '" onclick="toggle(this, event);">' . $captionExpansionPrefix . ' ' . $this->captionEditor->view( $idPath, $record->getAttributeValue( $captionAttribute ) ) . '</span></div>'; |
| 2055 | + $result .= HTML::openElement ('li') ; |
| 2056 | + $class = 'level' . $this->headerLevel ; |
| 2057 | + $result .= HTML::openElement ('div', array( 'class' => $class )) ; |
| 2058 | + |
| 2059 | + $text = $captionExpansionPrefix . ' ' |
| 2060 | + . $this->captionEditor->view( $idPath, $record->getAttributeValue( $captionAttribute ) ) ; |
| 2061 | + |
| 2062 | + $attribs = array(); // default if not collapsible |
| 2063 | + if ( $this->isCollapsible ) { |
| 2064 | + // collapsible element |
| 2065 | + $class = 'toggle ' . addCollapsablePrefixToClass( $captionClass ) ; |
| 2066 | + $id = 'collapse-' . $recordId ; |
| 2067 | + $attribs = array('class' => $class , 'id' => $id , 'onclick' => 'toggle(this, event);' ); |
| 2068 | + } |
| 2069 | + $result .= HTML::rawElement ('span', $attribs, $text ) ; |
| 2070 | + $result .= HTML::closeElement ('div'); |
| 2071 | + |
1928 | 2072 | $idPath->popAttribute(); |
1929 | | - |
1930 | 2073 | $idPath->pushAttribute( $valueAttribute ); |
1931 | | - $result .= '<div id="collapsable-' . $recordId . '" class="expand-' . $valueClass . '">' . $this->valueEditor->view( $idPath, $record->getAttributeValue( $valueAttribute ) ) . '</div>' . |
1932 | | - '</li>'; |
| 2074 | + |
| 2075 | + $text = $this->valueEditor->view( $idPath, $record->getAttributeValue( $valueAttribute ) ); |
| 2076 | + $class = 'expand-' . $valueClass ; |
| 2077 | + $id = 'collapsable-' . $recordId ; |
| 2078 | + $result .= HTML::rawElement ('div', array('class' => $class , 'id' => $id), $text ) ; |
| 2079 | + $result .= HTML::closeElement ('li') ; |
1933 | 2080 | $idPath->popAttribute(); |
1934 | | - |
1935 | 2081 | $idPath->popKey(); |
1936 | 2082 | } |
| 2083 | + |
| 2084 | + $result .= HTML::closeElement ('ul'); |
1937 | 2085 | |
1938 | | - $result .= '</ul>'; |
1939 | | - |
1940 | 2086 | return $result; |
1941 | 2087 | } |
1942 | 2088 | else |
— | — | @@ -1943,8 +2089,7 @@ |
1944 | 2090 | } |
1945 | 2091 | |
1946 | 2092 | public function edit( IdStack $idPath, $value ) { |
1947 | | - global |
1948 | | - $wgScriptPath; |
| 2093 | + global $wgScriptPath; |
1949 | 2094 | |
1950 | 2095 | $recordCount = $value->getRecordCount(); |
1951 | 2096 | |