Kipcool has submitted this change and it was merged.

Change subject: server-side table sorting, instead of client-side
......................................................................


server-side table sorting, instead of client-side

Change-Id: If9cbdfa61ed5bde5bb4437886a8b2d76e0ea19c8
---
M OmegaWiki/OmegaWikiRecordSets.php
M OmegaWiki/resources/omegawiki-ajax.js
2 files changed, 31 insertions(+), 34 deletions(-)

Approvals:
  Kipcool: Verified; Looks good to me, approved



diff --git a/OmegaWiki/OmegaWikiRecordSets.php 
b/OmegaWiki/OmegaWikiRecordSets.php
index ecee55b..cd65588 100644
--- a/OmegaWiki/OmegaWikiRecordSets.php
+++ b/OmegaWiki/OmegaWikiRecordSets.php
@@ -696,6 +696,19 @@
                __METHOD__
        );
 
+       // putting the sql result first in an array for sorting
+       // at the same time, an array of language names, used for sorting, is 
created.
+       $queryResultArray = array();
+       $sortOrderArray = array();
+       $languageNames = getOwLanguageNames();
+       foreach ( $queryResult as $row ) {
+               $queryResultArray[] = $row;
+               $sortOrderArray[] = $languageNames[$row->language_id];
+       }
+       // magic sort $queryResultArray on language names
+       array_multisort( $sortOrderArray, $queryResultArray );
+
+
        $structure = $o->translatedTextStructure ;
        if ( $viewInformation->showRecordLifeSpan ) {
                // additional attributes for history view
@@ -705,7 +718,7 @@
        $keyAttribute = $o->language ;
        $recordSet = new ArrayRecordSet( $structure, new Structure( 
$keyAttribute ) );
 
-       foreach ( $queryResult as $row ) {
+       foreach ( $queryResultArray as $row ) {
                $record = new ArrayRecord( $structure );
                $record->language = $row->language_id;
                $record->text = $row->text_id; // expanded below
@@ -767,6 +780,22 @@
                array( 'ORDER BY' => 'identical_meaning DESC' )
        );
 
+       // putting the sql result first in an array for sorting
+       // at the same time, an array of language names, used for sorting, is 
created.
+       $queryResultArray = array();
+       $sortOrderArray = array();
+       $languageNames = getOwLanguageNames();
+       foreach ( $queryResult as $row ) {
+               $queryResultArray[] = $row;
+               // since we want the inexact translations below the exact ones
+               // we add a "0" for exact trans, "1" for inexact trans (this is 
reverse compared to the value of the db)
+               $sortSuffix = ( $row->identical_meaning == 1 ) ? "0" : "1";
+               $sortOrderArray[] = $languageNames[$row->language_id] . 
$sortSuffix . $row->spelling;
+       }
+       // magic sort $queryResultArray on language names - then inexact flag - 
then orthography
+       array_multisort( $sortOrderArray, $queryResultArray );
+
+
        // TODO; try with synTransExpressionStructure instead of 
synonymsTranslationsStructure
        // so that expression is not a sublevel of the hierarchy, but on the 
same level
        //      $structure = $o->synTransExpressionStructure ;
@@ -781,7 +810,7 @@
        $keyAttribute = $o->syntransId ;
        $recordSet = new ArrayRecordSet( $structure, new Structure( 
$keyAttribute ) );
 
-       foreach ( $queryResult as $row ) {
+       foreach ( $queryResultArray as $row ) {
                $syntransId = $row->syntrans_sid;
                if ( $syntransId == $excludeSyntransId ) {
                        continue;
diff --git a/OmegaWiki/resources/omegawiki-ajax.js 
b/OmegaWiki/resources/omegawiki-ajax.js
index 1b6674a..58025c7 100644
--- a/OmegaWiki/resources/omegawiki-ajax.js
+++ b/OmegaWiki/resources/omegawiki-ajax.js
@@ -3,13 +3,6 @@
         * Some javascript that is run when the page finished loading
         */
 
-       // document.OWnosort can be set in the user .js to disable
-       // sorting for faster page loads
-       if ( ! document.OWnosort ) {
-               // sort the tables on language
-               sortTablesOnLanguages();
-       }
-
        // add and manage arrows to navigate the tabs
        if ( $(".wd-tablist").length ) {
                initializeTabs();
@@ -50,31 +43,6 @@
                $(this).children("span").toggle();
                $(this).next(".popupToggleable").toggle(100);
        });
-       
-       /*
-        * sortTablesOnLanguages sorts the wiki tables according to the 
language column
-        * using the jquery tablesorter plugin
-        */
-       function sortTablesOnLanguages() {
-               // optimally, different tableSorterCollation should be used 
according to the interface language
-               mw.config.set('tableSorterCollation', {
-                       'é':'e', 'è':'e', // French characters
-                       'ä':'ae', 'ö' : 'oe', 'ß': 'ss', 'ü':'ue' // German 
characters
-               });
-
-               // sort the definitions
-               $("div.expand-transl").children(".wiki-data-table")
-                       .tablesorter().find("th.headerSort.language").click();
-
-               // sort the translations
-               $("div.expand-syntrans").children(".wiki-data-table")
-                       .tablesorter().find("th.headerSort.exp:first").click();
-
-               // now disable sorting for users
-               $(".jquery-tablesorter").find("th").off("click");
-               $(".jquery-tablesorter").removeClass("jquery-tablesorter");
-       }
-
 
        /*
         * initializeTabs adds tabs on the top of a page to navigate between 
languages

-- 
To view, visit https://gerrit.wikimedia.org/r/65140
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If9cbdfa61ed5bde5bb4437886a8b2d76e0ea19c8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiLexicalData
Gerrit-Branch: master
Gerrit-Owner: Kipcool <[email protected]>
Gerrit-Reviewer: Kipcool <[email protected]>

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

Reply via email to