Index: trunk/extensions/Wikidata/OmegaWiki/languages.php |
— | — | @@ -88,19 +88,39 @@ |
89 | 89 | /* Return SQL query string for fetching language names. */ |
90 | 90 | function getSQLForLanguageNames( $lang_code ) { |
91 | 91 | /* Use a simpler query if the user's language is English. */ |
92 | | - /* Use a simpler query if the user's language is English. */ |
| 92 | + /* getLanguageIdForCode( 'en' ) = 85 */ |
| 93 | + |
| 94 | +// alternative query, slower? |
| 95 | +// if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) ) |
| 96 | +// return 'SELECT language.language_id AS row_id,language_names.language_name' . |
| 97 | +// ' FROM language' . |
| 98 | +// ' JOIN language_names ON language.language_id = language_names.language_id' . |
| 99 | +// ' WHERE language_names.name_language_id = 85' ; |
| 100 | +// /* Fall back on English in cases where a language name is not present in the |
| 101 | +// user's preferred language. */ |
| 102 | +// else |
| 103 | +// return 'SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name' . |
| 104 | +// ' FROM language' . |
| 105 | +// ' LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = ' . $lang_id . |
| 106 | +// ' JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = 85' ; |
| 107 | + |
93 | 108 | if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) ) |
94 | 109 | return 'SELECT language.language_id AS row_id,language_names.language_name' . |
95 | 110 | ' FROM language' . |
96 | 111 | ' JOIN language_names ON language.language_id = language_names.language_id' . |
97 | | - ' WHERE language_names.name_language_id = ' . getLanguageIdForCode( 'en' ); |
| 112 | + ' WHERE language_names.name_language_id = 85' ; |
98 | 113 | /* Fall back on English in cases where a language name is not present in the |
99 | 114 | user's preferred language. */ |
100 | 115 | else |
101 | | - return 'SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name' . |
| 116 | + return 'SELECT language.language_id AS row_id, language_names.language_name AS language_name' . |
102 | 117 | ' FROM language' . |
103 | | - ' LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = ' . $lang_id . |
104 | | - ' JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = ' . getLanguageIdForCode( 'en' ); |
| 118 | + ' JOIN language_names ON language.language_id = language_names.language_id' . |
| 119 | + ' WHERE language_names.name_language_id = ' . $lang_id . |
| 120 | + ' OR ( language_names.name_language_id = 85 ' . |
| 121 | + ' AND language.language_id NOT IN ( SELECT language_id FROM language_names WHERE language_names.name_language_id = ' . $lang_id . |
| 122 | + ' ) ) ' ; |
| 123 | + |
| 124 | + |
105 | 125 | } |
106 | 126 | |
107 | 127 | function getLanguageIdForName( $name ) { |