https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115788

Revision: 115788
Author:   kipcool
Date:     2012-12-19 13:06:45 +0000 (Wed, 19 Dec 2012)
Log Message:
-----------
- English langid (85) replaced by a parameter
- some code formatting and comments

Modified Paths:
--------------
    trunk/extensions/Wikidata/OmegaWiki/Controller.php
    trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
    trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
    trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
    trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php
    trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
    trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
    trunk/extensions/Wikidata/OmegaWiki/forms.php
    trunk/extensions/Wikidata/OmegaWiki/resources/suggest.css

Modified: trunk/extensions/Wikidata/OmegaWiki/Controller.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/Controller.php  2012-11-28 17:33:03 UTC 
(rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/Controller.php  2012-12-19 13:06:45 UTC 
(rev 115788)
@@ -216,7 +216,12 @@
        public function update( $keyPath, $record ) {
                $definedMeaningId = $keyPath->peek( 1 )->definedMeaningId;
                $syntransId = $keyPath->peek( 0 )->syntransId;
-               updateSynonymOrTranslationWithId( $syntransId, 
$record->identicalMeaning );
+               $identicalMeaning = $record->identicalMeaning;
+
+               // check that the needed parameters exist
+               if ( ($syntransId != "") && ($identicalMeaning != "") ) {
+                       updateSynonymOrTranslationWithId( $syntransId, 
$identicalMeaning );
+               }
        }
 }
 

Modified: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php   2012-11-28 17:33:03 UTC 
(rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php   2012-12-19 13:06:45 UTC 
(rev 115788)
@@ -61,20 +61,16 @@
                if ( !$type instanceof Structure ) {
                        $skipRows = count( $rows );
                        $columnIndex = $childNode->column + $columnOffset;
-                       $sort = 'sortTable(this, ' . $skipRows . ', ' . 
$columnIndex . ')';
-
                        $class = ' class="' . $type . ' ' . $attribute->id . 
'"';
                }
                else {
                        $class = ' class="' . $attribute->id . '"';
-                       $sort = '';
-                       $leftsort = '';
                }
 
                $rowSpan = $height - $childNode->height;
                $rows[$currentDepth] .= '<th id="' . $idPath->getId() . '-h" ' 
. $class .
                        ' colspan="' . $childNode->width .  '" rowspan="' . 
$rowSpan .
-                       '">' . $attribute->name . $leftsort . '</th>';
+                       '">' . $attribute->name . '</th>';
                                                                        
                addChildNodesToRows( $childNode, $rows, $currentDepth + 
$rowSpan, $columnOffset, $idPath, $leftmost );
                $idPath->popAttribute();

Modified: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php 2012-11-28 
17:33:03 UTC (rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php 2012-12-19 
13:06:45 UTC (rev 115788)
@@ -121,22 +121,24 @@
                " AND {$dc}_expression.remove_transaction_id IS NULL " .
                " AND {$dc}_defined_meaning.defined_meaning_id = ";
 
-    # Build atomic queries
-       $definedMeaningIdsCopy = $definedMeaningIds;
-    unset( $value );
-    foreach ( $definedMeaningIdsCopy as &$value ) { $value = $frontQuery . 
$value; }
-    unset( $value );
+       // copy the definedMeaningIds array to create one query for each DM id
+       $definedMeaningQueries = $definedMeaningIds;
+       unset( $value );
+       foreach ( $definedMeaningQueries as &$value ) {
+               $value = $frontQuery . $value;
+       }
+       unset( $value );
        # Union of the atoms
-    $finalQuery = implode( ' UNION ', $definedMeaningIdsCopy );
+       $finalQuery = implode( ' UNION ', $definedMeaningQueries );
        
        $queryResult = $dbr->query( $finalQuery );
 
        while ( $row = $dbr->fetchObject( $queryResult ) ) {
-               if ( isset( 
$definedMeaningReferenceRecords[$row->defined_meaning_id] ) )
+               if ( isset( 
$definedMeaningReferenceRecords[$row->defined_meaning_id] ) ) {
                        $definedMeaningReferenceRecord = 
$definedMeaningReferenceRecords[$row->defined_meaning_id];
-               else
+               } else {
                        $definedMeaningReferenceRecord = null;
-               
+               }
                if ( $definedMeaningReferenceRecord == null ) {
                        $definedMeaningReferenceRecord = new ArrayRecord( 
$o->definedMeaningReferenceStructure );
                        $definedMeaningReferenceRecord->definedMeaningId = 
$row->defined_meaning_id;
@@ -174,16 +176,16 @@
                
                if ( $wgRecordSetLanguage > 0 ) {
                        $userLanguage = $wgRecordSetLanguage;
-               }
-               else {
+               } else {
                        $userLanguage = getLanguageIdForCode( 
$wgLang->getCode() );
                }
                
-               if ( $userLanguage > 0 )
+               if ( $userLanguage > 0 ) {
                        $definingLanguage = $userLanguage;
-               else
-                       $definingLanguage = 85;
-                       
+               } else {
+                       $definingLanguage = WD_ENGLISH_LANG_ID;
+               }
+
                fetchDefinedMeaningReferenceRecords(
                        getDefiningSQLForLanguage( $definingLanguage, 
$definedMeaningIds ),
                        $definedMeaningIds,
@@ -203,7 +205,7 @@
        
                        if ( count( $definedMeaningIds ) > 0 ) {
                                fetchDefinedMeaningReferenceRecords(
-                                       getSynonymSQLForLanguage( 85, 
$definedMeaningIds ),
+                                       getSynonymSQLForLanguage( 
WD_ENGLISH_LANG_ID, $definedMeaningIds ),
                                        $definedMeaningIds,
                                        $result,
                                        $usedAs
@@ -222,8 +224,9 @@
                
                fetchDefinedMeaningDefiningExpressions( 
$definedMeaningIdsForExpressions, $result );
                $result[0] = getNullDefinedMeaningReferenceRecord();
-       }
 
+       } // if ( count( $definedMeaningIds ) > 0 )
+
 //     $queriesTime = microtime(true) - $startTime;
 //     echo "<!-- Defined meaning reference queries: " . $queriesTime . " 
-->\n";
 
@@ -262,6 +265,7 @@
 }
 
 function getExpressionReferenceRecords( $expressionIds ) {
+
        $o = OmegaWikiAttributes::getInstance();
        $dc = wdGetDataSetContext();
 
@@ -398,6 +402,9 @@
        }
 }
 
+/*
+* $exactMeaning is a boolean
+*/
 function getExpressionMeaningsRecordSet( $expressionId, $exactMeaning, 
ViewInformation $viewInformation ) {
        $o = OmegaWikiAttributes::getInstance();
 
@@ -432,8 +439,10 @@
        $o = OmegaWikiAttributes::getInstance();
                
        $record = new ArrayRecord( $o->expressionMeaningsStructure );
-       $record->expressionExactMeanings = getExpressionMeaningsRecordSet( 
$expressionId, true, $viewInformation );
-       $record->expressionApproximateMeanings = 
getExpressionMeaningsRecordSet( $expressionId, false, $viewInformation );
+       $exactMeaning = true;
+       $record->expressionExactMeanings = getExpressionMeaningsRecordSet( 
$expressionId, $exactMeaning, $viewInformation );
+       $exactMeaning = false;
+       $record->expressionApproximateMeanings = 
getExpressionMeaningsRecordSet( $expressionId, $exactMeaning, $viewInformation 
);
        
        return $record;
 }
@@ -763,7 +772,7 @@
        $dc = wdGetDataSetContext();
 
        $restrictions = array( "defined_meaning_id=$definedMeaningId" );
-       if ( $viewInformation->filterLanguageId != 0 )
+       if ( $viewInformation->filterLanguageId != 0 ) {
                $restrictions[] =
                        "expression_id IN (" .
                                "SELECT expressions.expression_id" .
@@ -772,6 +781,10 @@
                                " AND language_id=" . 
$viewInformation->filterLanguageId .
                                " AND expressions.remove_transaction_id IS NULL 
" .
                        ")";
+       }
+
+       // order to get exact meanings first
+       $orderBy[] = " identical_meaning DESC " ;
        
        $recordSet = queryRecordSet(
                $o->synonymsTranslationsStructure->getStructureType(),
@@ -783,7 +796,8 @@
                        new TableColumnsToAttribute( array( 'identical_meaning' 
), $o->identicalMeaning )
                ),
                $wgWikidataDataSet->syntrans,
-               $restrictions
+               $restrictions,
+               $orderBy
        );
        
        if ( $viewInformation->filterLanguageId == 0 )

Modified: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/RecordSet.php   2012-11-28 17:33:03 UTC 
(rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/RecordSet.php   2012-12-19 13:06:45 UTC 
(rev 115788)
@@ -207,9 +207,9 @@
 function getRecordKeyName( $record, $key ) {
        $ids = array();
        
-       foreach ( $key->attributes as $attribute )
+       foreach ( $key->attributes as $attribute ) {
                $ids[] = $record->getAttributeValue( $attribute );
-       
+       }
        return implode( "-", $ids );
 }
 

Modified: trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php    2012-11-28 
17:33:03 UTC (rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/RecordSetQueries.php    2012-12-19 
13:06:45 UTC (rev 115788)
@@ -61,6 +61,10 @@
        }
 }
 
+/**
+* generates all the sql queries that are then used
+* to fill the hierarchical structures (html tables etc.)
+*/
 function getTransactedSQL( QueryTransactionInformation 
$transactionInformation, array $selectFields, Table $table, array 
$restrictions, array $orderBy = array(), $count = - 1, $offset = 0 ) {
        $tableNames = array( $table->getIdentifier() );
 
@@ -91,6 +95,7 @@
        if ( $count != - 1 ) {
                $query .= " LIMIT " . $offset . ", " . $count;
        }
+
        return $query;
 }
 
@@ -117,6 +122,7 @@
                $allAttributes = $attributes;
        }
        
+       // create and run the sql query to get the "$selectFields" fields from 
the "$table" table
        $query = getTransactedSQL( $transactionInformation, $selectFields, 
$table, $restrictions, $orderBy, $count, $offset );
        $queryResult = $dbr->query( $query );
        

Modified: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php      2012-11-28 
17:33:03 UTC (rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php      2012-12-19 
13:06:45 UTC (rev 115788)
@@ -243,7 +243,7 @@
                if ( $row = $dbr->fetchObject($lang_res) ) {
                        $userlang = $row->language_id ;
                } else {
-                       $userlang = 85 ;
+                       $userlang = WD_ENGLISH_LANG_ID ;
                }
 
                $classMids = $wgDefaultClassMids ;

Modified: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php     2012-11-28 
17:33:03 UTC (rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php     2012-12-19 
13:06:45 UTC (rev 115788)
@@ -18,6 +18,7 @@
 define ( 'WD_EXPRESSION_APPROX_MEANINGS', "approx" );
 define ( 'WD_EXPRESSION_EXACT_MEANINGS', "exact" );
 define ( 'WD_EXPRESSION_MEANINGS', "meanings" );
+define ( 'WD_IDENTICAL_MEANING', "identMeaning" );
 define ( 'WD_INCOMING_RELATIONS', "incomingRel" );
 define ( 'WD_LINK_ATTRIBUTE', "linkAtt" );
 define ( 'WD_LINK_ATTRIBUTE_VALUES', "linkAttVal" );

Modified: trunk/extensions/Wikidata/OmegaWiki/forms.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/forms.php       2012-11-28 17:33:03 UTC 
(rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/forms.php       2012-12-19 13:06:45 UTC 
(rev 115788)
@@ -26,10 +26,10 @@
 }
 
 function checkBoxCheckAttribute( $isChecked ) {
-       if ( $isChecked )
+       if ( $isChecked ) {
                return ' checked="checked"';
-       else
-               return '';
+       }
+       return '';
 }
  
 function getCheckBox( $name, $isChecked, $disabled = false ) {
@@ -71,10 +71,11 @@
 
 # $options is an array of [value => text] pairs
 function getSelect( $name, $options, $selectedValue = "", $onChangeHandler = 
"" ) {
-       if ( $onChangeHandler != "" )
+       if ( $onChangeHandler != "" ) {
                $onChangeAttribute = ' onchange="' . $onChangeHandler . '"';
-       else
+       } else {
                $onChangeAttribute = '';
+       }
        
        $result = '<select id="' . $name . '" name="' . $name . '"' . 
$onChangeAttribute . '>';
  

Modified: trunk/extensions/Wikidata/OmegaWiki/resources/suggest.css
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/resources/suggest.css   2012-11-28 
17:33:03 UTC (rev 115787)
+++ trunk/extensions/Wikidata/OmegaWiki/resources/suggest.css   2012-12-19 
13:06:45 UTC (rev 115788)
@@ -1,13 +1,3 @@
-/*
-      Copy 
-          @import url("../../extensions/Wikidata/WiktionaryZ/tmp/suggest.css");
-          
-      into the appropriate stylesheets like 
-          skins/monobook/main.css
-          skins/common/common.css
-*/
-
-
 /* Suggestion control */
 
 .suggest-link {


_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to