r106600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106599‎ | r106600 | r106601 >
Date:21:28, 18 December 2011
Author:kipcool
Status:deferred
Tags:
Comment:
Only one language displayed at a time.
Added a dropdown to select between available languages.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/resources/omegawiki-ajax.js (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/WikiDataAPI.php
@@ -214,14 +214,14 @@
215215 return 0;
216216 }
217217
218 -function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning ) {
 218+function createSynonymOrTranslation( $definedMeaningId, $expressionId, $identicalMeaning = 1 ) {
219219
220220 $dc = wdGetDataSetContext();
221 -
222221 $synonymId = getSynonymId( $definedMeaningId, $expressionId );
223222
224 - if ( $synonymId == 0 )
 223+ if ( $synonymId == 0 ) {
225224 $synonymId = newObjectId( "{$dc}_syntrans" );
 225+ }
226226
227227 $dbw = wfGetDB( DB_MASTER );
228228 $identicalMeaningInteger = (int) $identicalMeaning;
@@ -1664,10 +1664,22 @@
16651665 $dbr = wfGetDB( DB_SLAVE );
16661666
16671667 $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" ;
16691671
 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+
16701682 $rv = array();
1671 - while ( $expressionRecord = $dbr->fetchObject( $queryResult ) ) {
 1683+ foreach ( $queryResult as $expressionRecord ) {
16721684 $rv[] = new Expression( $expressionRecord->expression_id, $expressionRecord->spelling, $expressionRecord->language_id );
16731685 }
16741686 $dbr->freeResult( $queryResult ) ;
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -502,6 +502,9 @@
503503 return $editor;
504504 }
505505
 506+/**
 507+ * Attribute is $o->expression
 508+ */
506509 function getExpressionTableCellEditor( Attribute $attribute, ViewInformation $viewInformation ) {
507510 $o = OmegaWikiAttributes::getInstance();
508511
@@ -751,13 +754,15 @@
752755
753756 $exactMeaningsEditor = getExpressionMeaningsEditor( $o->expressionExactMeanings, true, $viewInformation );
754757 $expressionMeaningsRecordEditor->addEditor( $exactMeaningsEditor );
755 - $expressionMeaningsRecordEditor->addEditor( getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) );
756 -
 758+ $approximateMeaningsEditor = getExpressionMeaningsEditor( $o->expressionApproximateMeanings, false, $viewInformation ) ;
 759+ $expressionMeaningsRecordEditor->addEditor( $approximateMeaningsEditor );
 760+
757761 $expressionMeaningsRecordEditor->expandEditor( $exactMeaningsEditor );
758 -
 762+
759763 if ( $viewInformation->filterLanguageId == 0 ) {
 764+ // show all languages
760765 $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 ) );
762767
763768 $expressionsEditor = new RecordSetListEditor(
764769 $o->expressions,
@@ -767,13 +772,15 @@
768773 false,
769774 false,
770775 new ExpressionController( $spelling, $viewInformation->filterLanguageId ),
771 - 2,
772 - true
 776+ 2, // headerLevel
 777+ true // childrenExpanded
773778 );
 779+ $expressionsEditor->setCollapsible( false );
774780 $expressionsEditor->setCaptionEditor( $expressionEditor );
775781 $expressionsEditor->setValueEditor( $expressionMeaningsRecordEditor );
776782 }
777783 else {
 784+ // show only one language
778785 $expressionEditor = new RecordSubRecordEditor( $o->expression );
779786 $expressionEditor->setSubRecordEditor( $expressionMeaningsRecordEditor );
780787
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -3,12 +3,9 @@
44 require_once( 'OmegaWikiAttributes.php' );
55 require_once( 'Record.php' );
66 require_once( 'RecordSet.php' );
7 -require_once( 'WikiDataAPI.php' );
8 -require_once( 'Transaction.php' );
9 -require_once( 'WikiDataTables.php' );
107 require_once( 'RecordSetQueries.php' );
11 -require_once( 'DefinedMeaningModel.php' );
128 require_once( 'ViewInformation.php' );
 9+require_once( 'Wikidata.php' );
1310 require_once( 'WikiDataGlobals.php' );
1411
1512
@@ -18,9 +15,9 @@
1916 # Query building
2017 $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
2118 " 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 " .
2522 " AND {$dc}_expression.language_id=" . $languageId .
2623 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
2724 " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " .
@@ -41,9 +38,9 @@
4239 # Query building
4340 $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
4441 " 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" .
4845 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
4946 " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " .
5047 " AND {$dc}_syntrans.identical_meaning=1 " .
@@ -63,9 +60,9 @@
6461 # Query building
6562 $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling AS label " .
6663 " 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 " .
7067 " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
7168 " AND {$dc}_defined_meaning.defined_meaning_id={$dc}_syntrans.defined_meaning_id " .
7269 " AND {$dc}_syntrans.identical_meaning=1 " .
@@ -101,7 +98,7 @@
10299 $record = new ArrayRecord( $specificStructure );
103100 $record->definedMeaningId = $definedMeaningId;
104101 $record->definedMeaningLabel = $row->label;
105 -
 102+
106103 $definedMeaningReferenceRecords[$definedMeaningId] = $record;
107104 $foundDefinedMeaningIds[] = $definedMeaningId;
108105 }
@@ -121,8 +118,8 @@
122119 $frontQuery = "SELECT {$dc}_defined_meaning.defined_meaning_id AS defined_meaning_id, {$dc}_expression.spelling" .
123120 " FROM {$dc}_defined_meaning, {$dc}_expression " .
124121 " 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 " .
127124 " AND {$dc}_defined_meaning.defined_meaning_id = ";
128125
129126 # Build atomic queries
@@ -320,7 +317,7 @@
321318
322319 # Prepare steady components
323320 $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 ";
325322 # Build atomic queries
326323 foreach ( $expressionIds as &$value ) { $value = $frontQuery . $value . $queueQuery; }
327324 unset( $value );
@@ -414,7 +411,7 @@
415412 $queryResult = $dbr->query(
416413 "SELECT defined_meaning_id FROM {$dc}_syntrans" .
417414 " WHERE expression_id=$expressionId AND identical_meaning=" . $identicalMeaning .
418 - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" )
 415+ " AND {$dc}_syntrans.remove_transaction_id IS NULL "
419416 );
420417
421418 while ( $definedMeaning = $dbr->fetchObject( $queryResult ) ) {
@@ -446,27 +443,27 @@
447444 $dc = wdGetDataSetContext( $dc );
448445 $o = OmegaWikiAttributes::getInstance();
449446
450 - $languageRestriction = $viewInformation->filterLanguageId != 0 ? " AND language_id=" . $viewInformation->filterLanguageId : "";
451 -
452447 $dbr = wfGetDB( DB_SLAVE );
453448 $sql =
454449 "SELECT expression_id, language_id " .
455450 " FROM {$dc}_expression" .
456451 " 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+
465462 $queryResult = $dbr->query( $sql );
466463
467464 $result = new ArrayRecordSet( $o->expressionsStructure, new Structure( "expression-id", $o->expressionId ) );
468465 $languageStructure = new Structure( "language", $o->language );
469466
470 - while ( $expression = $dbr->fetchObject( $queryResult ) ) {
 467+ foreach ( $queryResult as $expression ) {
471468 $expressionRecord = new ArrayRecord( $languageStructure );
472469 $expressionRecord->language = $expression->language_id;
473470
@@ -488,26 +485,26 @@
489486 "SELECT expression_id, language_id " .
490487 " FROM {$dc}_expression" .
491488 " WHERE spelling=BINARY " . $dbr->addQuotes( $spelling ) .
492 - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) .
 489+ " AND {$dc}_expression.remove_transaction_id IS NULL " .
493490 " AND language_id=$languageId" .
494491 " AND EXISTS (" .
495492 "SELECT expression_id " .
496493 " FROM {$dc}_syntrans " .
497494 " WHERE {$dc}_syntrans.expression_id={$dc}_expression.expression_id" .
498 - " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" )
 495+ " AND {$dc}_syntrans.remove_transaction_id IS NULL "
499496 . ")"
500497 );
501498
502 - if ( $expression = $dbr->fetchObject( $queryResult ) )
 499+ if ( $expression = $dbr->fetchObject( $queryResult ) ) {
503500 return $expression->expression_id;
504 - else
 501+ } else {
505502 return 0;
 503+ }
506504 }
507505
508506
509507 function getClassAttributesRecordSet( $definedMeaningId, ViewInformation $viewInformation ) {
510 - global
511 - $dataSet;
 508+ global $dataSet;
512509
513510 $o = OmegaWikiAttributes::getInstance();
514511
@@ -543,8 +540,7 @@
544541 }
545542
546543 function getAlternativeDefinitionsRecordSet( $definedMeaningId, ViewInformation $viewInformation ) {
547 - global
548 - $dataSet;
 544+ global $dataSet;
549545
550546 $o = OmegaWikiAttributes::getInstance();
551547
@@ -698,8 +694,7 @@
699695 }
700696
701697 function getTranslatedContentRecordSet( $translatedContentId, ViewInformation $viewInformation ) {
702 - global
703 - $dataSet;
 698+ global $dataSet;
704699
705700 $o = OmegaWikiAttributes::getInstance();
706701
@@ -721,8 +716,7 @@
722717 }
723718
724719 function getFilteredTranslatedContentRecordSet( $translatedContentId, ViewInformation $viewInformation ) {
725 - global
726 - $dataSet;
 720+ global $dataSet;
727721
728722 $o = OmegaWikiAttributes::getInstance();
729723
@@ -747,8 +741,7 @@
748742 }
749743
750744 function getSynonymAndTranslationRecordSet( $definedMeaningId, ViewInformation $viewInformation ) {
751 - global
752 - $dataSet;
 745+ global $dataSet;
753746
754747 $o = OmegaWikiAttributes::getInstance();
755748 $dc = wdGetDataSetContext();
@@ -761,7 +754,7 @@
762755 " FROM {$dc}_expression AS expressions" .
763756 " WHERE expressions.expression_id=expression_id" .
764757 " AND language_id=" . $viewInformation->filterLanguageId .
765 - " AND " . getLatestTransactionRestriction( 'expressions' ) .
 758+ " AND expressions.remove_transaction_id IS NULL " .
766759 ")";
767760
768761 $recordSet = queryRecordSet(
Index: trunk/extensions/Wikidata/OmegaWiki/ViewInformation.php
@@ -12,16 +12,33 @@
1313 */
1414
1515 class ViewInformation {
 16+ /**
 17+ * if != 0: shows only translations and definitions in this language
 18+ * if = 0 : display all languages
 19+ */
1620 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+
1728 public $queryTransactionInformation;
1829 public $showRecordLifeSpan;
19 - public $viewOrEdit;
 30+ public $viewOrEdit; ///< either "view" or "edit"
2031
2132 protected $propertyToColumnFilters;
2233
 34+ /**
 35+ * Constructor
 36+ */
2337 public function __construct() {
 38+ global $wgRequest ;
 39+
2440 $this->filterLanguageId = 0;
25 - $this->queryTransactionInformation;
 41+ $this->expressionLanguageId = $wgRequest->getVal( 'explang', 0 );
 42+ $this->queryTransactionInformation = null;
2643 $this->showRecordLifeSpan = false;
2744 $this->propertyToColumnFilters = array();
2845 $this->viewOrEdit = "view";
@@ -31,6 +48,10 @@
3249 return $this->showRecordLifeSpan;
3350 }
3451
 52+ /**
 53+ * @return true if we are filtering according to a language
 54+ * @return false if all languages are displayed
 55+ */
3556 public function filterOnLanguage() {
3657 return $this->filterLanguageId != 0;
3758 }
Index: trunk/extensions/Wikidata/OmegaWiki/type.php
@@ -43,8 +43,21 @@
4444 return $url;
4545 }
4646
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 ) ;
4962 }
5063
5164 function definedMeaningReferenceAsURL( $definedMeaningId, $definingExpression ) {
@@ -59,8 +72,8 @@
6073 return '<a href="' . htmlspecialchars( $url ) . '">' . htmlspecialchars( $text ) . '</a>';
6174 }
6275
63 -function spellingAsLink( $spelling ) {
64 - return createLink( spellingAsURL( $spelling ), $spelling );
 76+function spellingAsLink( $spelling, $lang = 0 ) {
 77+ return createLink( spellingAsURL( $spelling, $lang ), $spelling );
6578 }
6679
6780 function definedMeaningReferenceAsLink( $definedMeaningId, $definingExpression, $label ) {
Index: trunk/extensions/Wikidata/OmegaWiki/resources/tables.css
@@ -102,7 +102,48 @@
103103 width: auto;
104104 }
105105
 106+span.wd-dropdown {
 107+ position: relative;
 108+ border-radius: 5px;
 109+/*
 110+ * background-color: #ffe0eb;
 111+ */
 112+}
106113
 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+
107148 .level2 {
108149 font-size:150% ;
109150 background-color: #ffe0eb;
@@ -111,6 +152,8 @@
112153 border-color:grey;
113154 margin-top:10px;
114155 padding:5px;
 156+ border-radius: 100px;
 157+ -moz-border-radius: 100px;
115158 }
116159
117160 .level3 {
Index: trunk/extensions/Wikidata/OmegaWiki/resources/omegawiki-ajax.js
@@ -1,6 +1,20 @@
22
3 -jQuery(function() { sortAll(); });
 3+jQuery(function() {
 4+
 5+ // sort all tables
 6+ sortAll();
47
 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+
519 window.elementsToSort = new Array();
620
721 window.isFormElement = function (node) {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -240,11 +240,13 @@
241241 protected $editors;
242242 protected $attributeEditorMap;
243243 protected $attribute;
 244+ protected $isCollapsible;
244245
245246 public function __construct( Attribute $attribute = null ) {
246247 $this->attribute = $attribute;
247248 $this->editors = array();
248249 $this->attributeEditorMap = new AttributeEditorMap();
 250+ $this->isCollapsible = true;
249251 }
250252
251253 public function addEditor( Editor $editor ) {
@@ -264,8 +266,38 @@
265267 return $this->attributeEditorMap;
266268 }
267269
 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+
268286 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 ;
270302 }
271303
272304 static private $staticExpansionStyles = array();
@@ -603,10 +635,11 @@
604636 foreach ( $editor->getEditors() as $childEditor ) {
605637 $childAttribute = $childEditor->getAttribute();
606638
607 - if ( $childEditor instanceof RecordTableCellEditor )
 639+ if ( $childEditor instanceof RecordTableCellEditor ) {
608640 $type = $this->getTableStructure( $childEditor );
609 - else
 641+ } else {
610642 $type = 'short-text';
 643+ }
611644
612645 $attributes[] = new Attribute( $childAttribute->id, $childAttribute->name, $type );
613646 }
@@ -940,7 +973,10 @@
941974 }
942975 }
943976
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+ */
945981 abstract class ScalarEditor extends DefaultEditor {
946982 protected $permissionController;
947983 protected $isAddField;
@@ -1043,7 +1079,99 @@
10441080 }
10451081 }
10461082
 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+
10471174 class SpellingEditor extends ScalarEditor {
 1175+
10481176 public function getViewHTML( IdStack $idPath, $value ) {
10491177 return spellingAsLink( $value );
10501178 }
@@ -1907,7 +2035,7 @@
19082036 $recordCount = $value->getRecordCount();
19092037
19102038 if ( $recordCount > 0 ) {
1911 - $result = '<ul class="collapsable-items">' . EOL;
 2039+ $result = HTML::openElement ('ul', array( 'class' => 'collapsable-items')) ;
19122040 $key = $value->getKey();
19132041 $captionAttribute = $this->captionEditor->getAttribute();
19142042 $valueAttribute = $this->valueEditor->getAttribute();
@@ -1923,19 +2051,37 @@
19242052 $this->setExpansion( $this->childrenExpanded, $valueClass );
19252053
19262054 $idPath->pushAttribute( $captionAttribute );
1927 - $result .= '<li><div class="level' . $this->headerLevel . '"><span id="collapse-' . $recordId . '" class="toggle ' . addCollapsablePrefixToClass( $captionClass ) . '" onclick="toggle(this, event);">' . $captionExpansionPrefix . '&#160;' . $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 . '&#160;'
 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+
19282072 $idPath->popAttribute();
1929 -
19302073 $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') ;
19332080 $idPath->popAttribute();
1934 -
19352081 $idPath->popKey();
19362082 }
 2083+
 2084+ $result .= HTML::closeElement ('ul');
19372085
1938 - $result .= '</ul>';
1939 -
19402086 return $result;
19412087 }
19422088 else
@@ -1943,8 +2089,7 @@
19442090 }
19452091
19462092 public function edit( IdStack $idPath, $value ) {
1947 - global
1948 - $wgScriptPath;
 2093+ global $wgScriptPath;
19492094
19502095 $recordCount = $value->getRecordCount();
19512096

Status & tagging log