r55784 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55783‎ | r55784 | r55785 >
Date:19:26, 3 September 2009
Author:roberthl
Status:deferred
Tags:
Comment:
OmegaWiki: Commit two patches by Christophe Millet.
- Adjust the links on Special:NeedsTranslationTo to point to the DefinedMeaning rather than the Expression.
- Add some code documentation.
- When adding a class to an element the second column now shows the class definition rather than the collection name.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php
@@ -22,7 +22,7 @@
2323 initializeOmegaWikiAttributes( new ViewInformation() );
2424 $wgOut->setPageTitle( wfMsg( 'ow_needs_xlation_title' ) );
2525
26 - $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:'';
 26+ $destinationLanguageId = array_key_exists( 'to-lang', $_GET ) ? $_GET['to-lang']:'';
2727 $collectionId = array_key_exists( 'collection', $_GET ) ? $_GET['collection'] : '';
2828 $sourceLanguageId = array_key_exists( 'from-lang', $_GET ) ? $_GET['from-lang'] : '';
2929
@@ -43,7 +43,6 @@
4444 protected function showExpressionsNeedingTranslation( $sourceLanguageId, $destinationLanguageId, $collectionId ) {
4545
4646 $o = OmegaWikiAttributes::getInstance();
47 - $o = OmegaWikiAttributes::getInstance();
4847
4948 $dc = wdGetDataSetContext();
5049 require_once( "Transaction.php" );
@@ -113,24 +112,31 @@
114113
115114
116115 $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 ) );
118116
 117+ $recordSet = new ArrayRecordSet( new Structure( $o->definedMeaningId, $o->expressionId, $o->definedMeaningReference, $definitionAttribute ), new Structure( $o->definedMeaningId, $o->expressionId ) );
 118+
119119 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;
123125
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 ) ) );
125127 }
126128
127 - $expressionEditor = new RecordTableCellEditor( $o->expression );
 129+ $expressionEditor = new RecordTableCellEditor( $o->definedMeaningReference );
128130 $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 ) );
130132
131133 $editor = new RecordSetTableEditor( null, new SimplePermissionController( false ), new ShowEditFieldChecker( true ), new AllowAddController( false ), false, false, null );
132134 $editor->addEditor( $expressionEditor );
133135 $editor->addEditor( new TextEditor( $definitionAttribute, new SimplePermissionController( false ), false, true, 75 ) );
134136
 137+ // cosmetics : changing the titles of the columns
 138+ $o->definedMeaningReference->name = wfMsgSc( "Expression" ) ;
 139+ $o->definedMeaningId->name = wfMsgSc( "Spelling" ) ;
 140+
135141 global $wgOut;
136142
137143 $wgOut->addHTML( "Showing $nbshown out of $queryResultCount" ) ;
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
@@ -35,7 +35,10 @@
3636 SpecialPage::addPage( new SpecialSuggest() );
3737 }
3838
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+ */
4043 function getSuggestions() {
4144 $o = OmegaWikiAttributes::getInstance();
4245 global $wgUser;
@@ -59,9 +62,9 @@
6063 $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) );
6164 break;
6265 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' ) );
6669 break;
6770 case 'defined-meaning-attribute':
6871 $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'DM' );
@@ -142,6 +145,7 @@
143146 if ( $offset > 0 )
144147 $sql .= " $offset, ";
145148
 149+ // print only 10 results
146150 $sql .= "10";
147151
148152 # == Actual query here
@@ -364,6 +368,43 @@
365369 return $sql;
366370 }
367371
 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+
368409 function getSQLForCollectionOfType( $collectionType, $language = "<ANY>" ) {
369410 $dc = wdGetDataSetContext();
370411 $sql = "SELECT member_mid, spelling, collection_mid " .
@@ -453,22 +494,30 @@
454495 return array( $recordSet, $editor );
455496 }
456497
 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+ */
457504 function getClassAsRecordSet( $queryResult ) {
458505
459506 $o = OmegaWikiAttributes::getInstance();
460507
461508 $dbr =& wfGetDB( DB_SLAVE );
 509+ // Setting the two column, with titles
462510 $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" );
469512
 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+
470519 $editor = createSuggestionsTableViewer( null );
471520 $editor->addEditor( createShortTextViewer( $classAttribute ) );
472 - $editor->addEditor( createShortTextViewer( $collectionAttribute ) );
 521+ $editor->addEditor( createShortTextViewer( $definitionAttribute ) );
473522
474523 return array( $recordSet, $editor );
475524 }
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1006,6 +1006,12 @@
10071007 $dbr->query( $sql );
10081008 }
10091009
 1010+/**
 1011+ * Returns the definition of a definedMeaning in a given language
 1012+ * @param $definedMeaningId
 1013+ * @param $languageId
 1014+ * @param $dc
 1015+ */
10101016 function getDefinedMeaningDefinitionForLanguage( $definedMeaningId, $languageId, $dc = null ) {
10111017 if ( is_null( $dc ) ) {
10121018 $dc = wdGetDataSetContext();
@@ -1025,6 +1031,11 @@
10261032 return "";
10271033 }
10281034
 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+ */
10291040 function getDefinedMeaningDefinitionForAnyLanguage( $definedMeaningId ) {
10301041 $dc = wdGetDataSetContext();
10311042 $dbr =& wfGetDB( DB_SLAVE );
@@ -1041,6 +1052,11 @@
10421053 return "";
10431054 }
10441055
 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+ */
10451061 function getDefinedMeaningDefinition( $definedMeaningId ) {
10461062 global
10471063 $wgUser;
@@ -1493,6 +1509,11 @@
14941510 }
14951511 }
14961512
 1513+/**
 1514+ * Returns one spelling of an expression corresponding to a given DM in a given language
 1515+ * @param $definedMeaningId
 1516+ * @param $languageId
 1517+ */
14971518 function definedMeaningExpressionForLanguage( $definedMeaningId, $languageId ) {
14981519 $dc = wdGetDataSetContext();
14991520 $dbr =& wfGetDB( DB_SLAVE );
@@ -1514,6 +1535,10 @@
15151536 return "";
15161537 }
15171538
 1539+/**
 1540+ * Returns one spelling of an expression corresponding to a given DM in any language
 1541+ * @param $definedMeaningId
 1542+ */
15181543 function definedMeaningExpressionForAnyLanguage( $definedMeaningId ) {
15191544 $dc = wdGetDataSetContext();
15201545 $dbr =& wfGetDB( DB_SLAVE );
@@ -1533,6 +1558,13 @@
15341559 return "";
15351560 }
15361561
 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+ */
15371569 function definedMeaningExpression( $definedMeaningId ) {
15381570 global
15391571 $wgUser;
@@ -1550,6 +1582,7 @@
15511583 $result = "";
15521584
15531585 if ( $result == "" ) {
 1586+ // if no expression exists for the specified language : look for an expression in English
15541587 $result = definedMeaningExpressionForLanguage( $definedMeaningId, 85 );
15551588
15561589 if ( $result == "" ) {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -1015,6 +1015,30 @@
10161016 }
10171017 }
10181018
 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+
10191043 class DefinedMeaningHeaderEditor extends ScalarEditor {
10201044 protected $truncate;
10211045 protected $truncateAt;

Status & tagging log