r17918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17917‎ | r17918 | r17919 >
Date:06:56, 25 November 2006
Author:sburke
Status:old
Tags:
Comment:
* Add language name fallback on definition and expression lists.
* Move language name SQL to languages.php and include where needed.
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/languages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/SpecialSuggest.php
@@ -1,365 +1,349 @@
2 -<?php
3 -
4 -if (!defined('MEDIAWIKI')) die();
5 -
6 -$wgExtensionFunctions[] = 'wfSpecialSuggest';
7 -
8 -function wfSpecialSuggest() {
9 - class SpecialSuggest extends SpecialPage {
10 - function SpecialSuggest() {
11 - SpecialPage::SpecialPage('Suggest');
12 - }
13 -
14 - function execute( $par ) {
15 - global
16 - $wgOut, $IP;
17 -
18 - $wgOut->disable();
19 -
20 - require_once("$IP/includes/Setup.php");
21 - require_once("Attribute.php");
22 - require_once("RecordSet.php");
23 - require_once("Editor.php");
24 - require_once("HTMLtable.php");
25 - require_once("Expression.php");
26 - require_once("Transaction.php");
27 - require_once("WiktionaryZEditors.php");
28 -
29 - echo getSuggestions();
30 - }
31 - }
32 -
33 - SpecialPage::addPage(new SpecialSuggest());
34 -}
35 -
36 -function getSuggestions() {
37 - global
38 - $idAttribute;
39 -
40 - $search = ltrim($_GET['search-text']);
41 - $prefix = $_GET['prefix'];
42 - $query = $_GET['query'];
43 -
44 - $dbr =& wfGetDB( DB_SLAVE );
45 - $rowText = 'spelling';
46 -
47 - switch ($query) {
48 - case 'relation-type':
49 - $sql = getSQLForCollectionOfType('RELT');
50 - break;
51 - case 'class':
52 - $sql = getSQLForCollectionOfType('CLAS');
53 - break;
54 - case 'translated-text-attribute':
55 - case 'text-attribute':
56 - $sql = getSQLForCollectionOfType('TATT');
57 - break;
58 - case 'language':
59 - $sql = getSQLForLanguage();
60 - $rowText = 'language_name';
61 - break;
62 - case 'defined-meaning':
63 - $sql = "SELECT syntrans.defined_meaning_id AS defined_meaning_id, expression.spelling AS spelling, expression.language_id AS language_id ".
64 - "FROM uw_expression_ns expression, uw_syntrans syntrans ".
65 - "WHERE expression.expression_id=syntrans.expression_id AND syntrans.identical_meaning=1 " .
66 - " AND " . getLatestTransactionRestriction('syntrans').
67 - " AND " . getLatestTransactionRestriction('expression');
68 - break;
69 - case 'class-attributes-level':
70 - $sql = getSQLForCollectionOfType('LEVL');
71 - break;
72 - case 'collection':
73 - $sql = "SELECT collection_id, spelling ".
74 - "FROM uw_expression_ns expression, uw_collection_ns collection, uw_syntrans syntrans ".
75 - "WHERE expression.expression_id=syntrans.expression_id AND syntrans.defined_meaning_id=collection.collection_mid ".
76 - "AND syntrans.identical_meaning=1" .
77 - " AND " . getLatestTransactionRestriction('syntrans') .
78 - " AND " . getLatestTransactionRestriction('expression') .
79 - " AND " . getLatestTransactionRestriction('collection');
80 - break;
81 - case 'transaction':
82 - $sql = "SELECT transaction_id, user_id, user_ip, " .
83 - " CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," .
84 - " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2)) AS time, comment" .
85 - " FROM transactions WHERE 1";
86 - $rowText = "CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," .
87 - " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))";
88 - break;
89 - }
90 -
91 - if ($search != '') {
92 - if ($query == 'transaction')
93 - $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes("%$search%");
94 - else if ($query == 'language')
95 - $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes("$search%");
96 - else
97 - $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes("$search%");
98 - }
99 - else
100 - $searchCondition = "";
101 -
102 - if ($query == 'transaction')
103 - $orderBy = 'transaction_id DESC';
104 - else
105 - $orderBy = $rowText;
106 -
107 - $sql .= $searchCondition . " ORDER BY $orderBy LIMIT 10";
108 - $queryResult = $dbr->query($sql);
109 - $idAttribute = new Attribute("id", "ID", "id");
110 -
111 - switch($query) {
112 - case 'relation-type':
113 - list($recordSet, $editor) = getRelationTypeAsRecordSet($queryResult);
114 - break;
115 - case 'class':
116 - list($recordSet, $editor) = getClassAsRecordSet($queryResult);
117 - break;
118 - case 'text-attribute':
119 - list($recordSet, $editor) = getTextAttributeAsRecordSet($queryResult);
120 - break;
121 - case 'translated-text-attribute':
122 - list($recordSet, $editor) = getTranslatedTextAttributeAsRecordSet($queryResult);
123 - break;
124 - case 'defined-meaning':
125 - list($recordSet, $editor) = getDefinedMeaningAsRecordSet($queryResult);
126 - break;
127 - case 'class-attributes-level':
128 - list($recordSet, $editor) = getClassAttributeLevelAsRecordSet($queryResult);
129 - break;
130 - case 'collection':
131 - list($recordSet, $editor) = getCollectionAsRecordSet($queryResult);
132 - break;
133 - case 'language':
134 - list($recordSet, $editor) = getLanguageAsRecordSet($queryResult);
135 - break;
136 - case 'transaction':
137 - list($recordSet, $editor) = getTransactionAsRecordSet($queryResult);
138 - break;
139 - }
140 -
141 - return $editor->view(new IdStack($prefix . 'table'), $recordSet);
142 -}
143 -
144 -function getSQLForCollectionOfType($collectionType) {
145 - return "SELECT member_mid, spelling, collection_mid " .
146 - "FROM uw_collection_contents, uw_collection_ns, uw_syntrans syntrans, uw_expression_ns expression " .
147 - "WHERE uw_collection_contents.collection_id=uw_collection_ns.collection_id and uw_collection_ns.collection_type='$collectionType' " .
148 -
149 - "AND syntrans.defined_meaning_id=uw_collection_contents.member_mid " .
150 - "AND expression.expression_id=syntrans.expression_id AND syntrans.identical_meaning=1 ".
151 - "AND " . getLatestTransactionRestriction('syntrans') .
152 - "AND " . getLatestTransactionRestriction('expression') .
153 - "AND " . getLatestTransactionRestriction('uw_collection_contents');
154 -}
155 -
156 -function getSQLForLanguage() {
157 - global
158 - $wgUser;
159 -
160 - $userLanguage = $wgUser->getOption('language');
161 -
162 - if ($userLanguage == 'en')
163 - return "SELECT language.language_id AS row_id,language_names.language_name " .
164 - "FROM language " .
165 - "JOIN language_names ON language.language_id = language_names.language_id " .
166 - "WHERE language_names.name_language_id = " . getLanguageIdForCode('en');
167 - else
168 - return "SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name " .
169 - "FROM language " .
170 - "LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = " . getLanguageIdForCode($userLanguage) . " " .
171 - "JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = " . getLanguageIdForCode('en');
172 -}
173 -
174 -function getRelationTypeAsRecordSet($queryResult) {
175 - global
176 - $idAttribute;
177 -
178 - $dbr =& wfGetDB(DB_SLAVE);
179 -
180 - $relationTypeAttribute = new Attribute("relation-type", "Relation type", "short-text");
181 - $collectionAttribute = new Attribute("collection", "Collection", "short-text");
182 -
183 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $relationTypeAttribute, $collectionAttribute), new Structure($idAttribute));
184 -
185 - while ($row = $dbr->fetchObject($queryResult))
186 - $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
187 -
188 - $editor = createSuggestionsTableViewer(null);
189 - $editor->addEditor(createShortTextViewer($relationTypeAttribute));
190 - $editor->addEditor(createShortTextViewer($collectionAttribute));
191 -
192 - return array($recordSet, $editor);
193 -}
194 -
195 -function getClassAsRecordSet($queryResult) {
196 - global
197 - $idAttribute;
198 -
199 - $dbr =& wfGetDB(DB_SLAVE);
200 - $classAttribute = new Attribute("class", "Class", "short-text");
201 - $collectionAttribute = new Attribute("collection", "Collection", "short-text");
202 -
203 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $classAttribute, $collectionAttribute), new Structure($idAttribute));
204 -
205 - while ($row = $dbr->fetchObject($queryResult))
206 - $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
207 -
208 - $editor = createSuggestionsTableViewer(null);
209 - $editor->addEditor(createShortTextViewer($classAttribute));
210 - $editor->addEditor(createShortTextViewer($collectionAttribute));
211 -
212 - return array($recordSet, $editor);
213 -}
214 -
215 -function getTextAttributeAsRecordSet($queryResult) {
216 - global
217 - $idAttribute, $textAttributeAttribute, $collectionAttribute;
218 -
219 - $dbr =& wfGetDB(DB_SLAVE);
220 -
221 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $textAttributeAttribute, $collectionAttribute), new Structure($idAttribute));
222 -
223 - while ($row = $dbr->fetchObject($queryResult))
224 - $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
225 -
226 - $editor = createSuggestionsTableViewer(null);
227 - $editor->addEditor(createShortTextViewer($textAttributeAttribute));
228 - $editor->addEditor(createShortTextViewer($collectionAttribute));
229 -
230 - return array($recordSet, $editor);
231 -}
232 -
233 -function getTranslatedTextAttributeAsRecordSet($queryResult) {
234 - global
235 - $idAttribute, $translatedTextAttributeAttribute, $collectionAttribute;
236 -
237 - $dbr =& wfGetDB(DB_SLAVE);
238 -// $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", "Translated text attribute", "short-text");
239 -// $collectionAttribute = new Attribute("collection", "Collection", "short-text");
240 -
241 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $translatedTextAttributeAttribute, $collectionAttribute), new Structure($idAttribute));
242 -
243 - while ($row = $dbr->fetchObject($queryResult))
244 - $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
245 -
246 - $editor = createSuggestionsTableViewer(null);
247 - $editor->addEditor(createShortTextViewer($translatedTextAttributeAttribute));
248 - $editor->addEditor(createShortTextViewer($collectionAttribute));
249 -
250 - return array($recordSet, $editor);
251 -}
252 -
253 -function getDefinedMeaningAsRecordSet($queryResult) {
254 - global
255 - $idAttribute;
256 -
257 - $dbr =& wfGetDB(DB_SLAVE);
258 - $spellingAttribute = new Attribute("spelling", "Spelling", "short-text");
259 - $languageAttribute = new Attribute("language", "Language", "language");
260 -
261 - $expressionStructure = new Structure($spellingAttribute, $languageAttribute);
262 - $definedMeaningAttribute = new Attribute("defined-meaning", "Defined meaning", new RecordType($expressionStructure));
263 - $definitionAttribute = new Attribute("definition", "Definition", "definition");
264 -
265 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $definedMeaningAttribute, $definitionAttribute), new Structure($idAttribute));
266 -
267 - while ($row = $dbr->fetchObject($queryResult)) {
268 - $definedMeaningRecord = new ArrayRecord($expressionStructure);
269 - $definedMeaningRecord->setAttributeValue($spellingAttribute, $row->spelling);
270 - $definedMeaningRecord->setAttributeValue($languageAttribute, $row->language_id);
271 -
272 - $recordSet->addRecord(array($row->defined_meaning_id, $definedMeaningRecord, getDefinedMeaningDefinition($row->defined_meaning_id)));
273 - }
274 -
275 - $expressionEditor = new RecordTableCellEditor($definedMeaningAttribute);
276 - $expressionEditor->addEditor(createShortTextViewer($spellingAttribute));
277 - $expressionEditor->addEditor(createLanguageViewer($languageAttribute));
278 -
279 - $editor = createSuggestionsTableViewer(null);
280 - $editor->addEditor($expressionEditor);
281 - $editor->addEditor(new TextEditor($definitionAttribute, new SimplePermissionController(false), false, true, 75));
282 -
283 - return array($recordSet, $editor);
284 -}
285 -
286 -function getClassAttributeLevelAsRecordSet($queryResult) {
287 - global
288 - $idAttribute;
289 -
290 - $dbr =& wfGetDB(DB_SLAVE);
291 -
292 - $classAttributeLevelAttribute = new Attribute("class-attribute-level", "Level", "short-text");
293 - $collectionAttribute = new Attribute("collection", "Collection", "short-text");
294 -
295 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $classAttributeLevelAttribute, $collectionAttribute), new Structure($idAttribute));
296 -
297 - while ($row = $dbr->fetchObject($queryResult))
298 - $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
299 -
300 - $editor = createSuggestionsTableViewer(null);
301 - $editor->addEditor(createShortTextViewer($classAttributeLevelAttribute));
302 - $editor->addEditor(createShortTextViewer($collectionAttribute));
303 -
304 - return array($recordSet, $editor);
305 -}
306 -
307 -function getCollectionAsRecordSet($queryResult) {
308 - global
309 - $idAttribute;
310 -
311 - $dbr =& wfGetDB(DB_SLAVE);
312 - $collectionAttribute = new Attribute("collection", "Collection", "short-text");
313 -
314 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $collectionAttribute), new Structure($idAttribute));
315 -
316 - while ($row = $dbr->fetchObject($queryResult))
317 - $recordSet->addRecord(array($row->collection_id, $row->spelling));
318 -
319 - $editor = createSuggestionsTableViewer(null);
320 - $editor->addEditor(createShortTextViewer($collectionAttribute));
321 -
322 - return array($recordSet, $editor);
323 -}
324 -
325 -function getLanguageAsRecordSet($queryResult) {
326 - global
327 - $idAttribute;
328 -
329 - $dbr =& wfGetDB(DB_SLAVE);
330 - $languageAttribute = new Attribute("language", "Language", "short-text");
331 -
332 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $languageAttribute), new Structure($idAttribute));
333 -
334 - while ($row = $dbr->fetchObject($queryResult))
335 - $recordSet->addRecord(array($row->row_id, $row->language_name));
336 -
337 - $editor = createSuggestionsTableViewer(null);
338 - $editor->addEditor(createShortTextViewer($languageAttribute));
339 -
340 - return array($recordSet, $editor);
341 -}
342 -
343 -function getTransactionAsRecordSet($queryResult) {
344 - global
345 - $idAttribute, $userAttribute;
346 -
347 - $dbr =& wfGetDB(DB_SLAVE);
348 -
349 - $timestampAttribute = new Attribute("timestamp", "Time", "timestamp");
350 - $summaryAttribute = new Attribute("summary", "Summary", "short-text");
351 -
352 - $recordSet = new ArrayRecordSet(new Structure($idAttribute, $userAttribute, $timestampAttribute, $summaryAttribute), new Structure($idAttribute));
353 -
354 - while ($row = $dbr->fetchObject($queryResult))
355 - $recordSet->addRecord(array($row->transaction_id, getUserLabel($row->user_id, $row->user_ip), $row->time, $row->comment));
356 -
357 - $editor = createSuggestionsTableViewer(null);
358 - $editor->addEditor(createShortTextViewer($timestampAttribute));
359 - $editor->addEditor(createShortTextViewer($idAttribute));
360 - $editor->addEditor(createShortTextViewer($userAttribute));
361 - $editor->addEditor(createShortTextViewer($summaryAttribute));
362 -
363 - return array($recordSet, $editor);
364 -}
365 -
366 -?>
\ No newline at end of file
 2+<?php
 3+
 4+if (!defined('MEDIAWIKI')) die();
 5+
 6+$wgExtensionFunctions[] = 'wfSpecialSuggest';
 7+
 8+function wfSpecialSuggest() {
 9+ class SpecialSuggest extends SpecialPage {
 10+ function SpecialSuggest() {
 11+ SpecialPage::SpecialPage('Suggest');
 12+ }
 13+
 14+ function execute( $par ) {
 15+ global
 16+ $wgOut, $IP;
 17+
 18+ $wgOut->disable();
 19+
 20+ require_once("$IP/includes/Setup.php");
 21+ require_once("Attribute.php");
 22+ require_once("RecordSet.php");
 23+ require_once("Editor.php");
 24+ require_once("HTMLtable.php");
 25+ require_once("Expression.php");
 26+ require_once("Transaction.php");
 27+ require_once("WiktionaryZEditors.php");
 28+
 29+ echo getSuggestions();
 30+ }
 31+ }
 32+
 33+ SpecialPage::addPage(new SpecialSuggest());
 34+}
 35+
 36+function getSuggestions() {
 37+ global
 38+ $idAttribute;
 39+
 40+ $search = ltrim($_GET['search-text']);
 41+ $prefix = $_GET['prefix'];
 42+ $query = $_GET['query'];
 43+
 44+ $dbr =& wfGetDB( DB_SLAVE );
 45+ $rowText = 'spelling';
 46+
 47+ switch ($query) {
 48+ case 'relation-type':
 49+ $sql = getSQLForCollectionOfType('RELT');
 50+ break;
 51+ case 'class':
 52+ $sql = getSQLForCollectionOfType('CLAS');
 53+ break;
 54+ case 'translated-text-attribute':
 55+ case 'text-attribute':
 56+ $sql = getSQLForCollectionOfType('TATT');
 57+ break;
 58+ case 'language':
 59+ require_once('languages.php');
 60+ global $wgUser;
 61+ $sql = getSQLForLanguageNames($wgUser->getOption('language'));
 62+ $rowText = 'language_name';
 63+ break;
 64+ case 'defined-meaning':
 65+ $sql = "SELECT syntrans.defined_meaning_id AS defined_meaning_id, expression.spelling AS spelling, expression.language_id AS language_id ".
 66+ "FROM uw_expression_ns expression, uw_syntrans syntrans ".
 67+ "WHERE expression.expression_id=syntrans.expression_id AND syntrans.identical_meaning=1 " .
 68+ " AND " . getLatestTransactionRestriction('syntrans').
 69+ " AND " . getLatestTransactionRestriction('expression');
 70+ break;
 71+ case 'class-attributes-level':
 72+ $sql = getSQLForCollectionOfType('LEVL');
 73+ break;
 74+ case 'collection':
 75+ $sql = "SELECT collection_id, spelling ".
 76+ "FROM uw_expression_ns expression, uw_collection_ns collection, uw_syntrans syntrans ".
 77+ "WHERE expression.expression_id=syntrans.expression_id AND syntrans.defined_meaning_id=collection.collection_mid ".
 78+ "AND syntrans.identical_meaning=1" .
 79+ " AND " . getLatestTransactionRestriction('syntrans') .
 80+ " AND " . getLatestTransactionRestriction('expression') .
 81+ " AND " . getLatestTransactionRestriction('collection');
 82+ break;
 83+ case 'transaction':
 84+ $sql = "SELECT transaction_id, user_id, user_ip, " .
 85+ " CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," .
 86+ " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2)) AS time, comment" .
 87+ " FROM transactions WHERE 1";
 88+ $rowText = "CONCAT(SUBSTRING(timestamp, 1, 4), '-', SUBSTRING(timestamp, 5, 2), '-', SUBSTRING(timestamp, 7, 2), ' '," .
 89+ " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))";
 90+ break;
 91+ }
 92+
 93+ if ($search != '') {
 94+ if ($query == 'transaction')
 95+ $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes("%$search%");
 96+ else if ($query == 'language')
 97+ $searchCondition = " HAVING $rowText LIKE " . $dbr->addQuotes("$search%");
 98+ else
 99+ $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes("$search%");
 100+ }
 101+ else
 102+ $searchCondition = "";
 103+
 104+ if ($query == 'transaction')
 105+ $orderBy = 'transaction_id DESC';
 106+ else
 107+ $orderBy = $rowText;
 108+
 109+ $sql .= $searchCondition . " ORDER BY $orderBy LIMIT 10";
 110+ $queryResult = $dbr->query($sql);
 111+ $idAttribute = new Attribute("id", "ID", "id");
 112+
 113+ switch($query) {
 114+ case 'relation-type':
 115+ list($recordSet, $editor) = getRelationTypeAsRecordSet($queryResult);
 116+ break;
 117+ case 'class':
 118+ list($recordSet, $editor) = getClassAsRecordSet($queryResult);
 119+ break;
 120+ case 'text-attribute':
 121+ list($recordSet, $editor) = getTextAttributeAsRecordSet($queryResult);
 122+ break;
 123+ case 'translated-text-attribute':
 124+ list($recordSet, $editor) = getTranslatedTextAttributeAsRecordSet($queryResult);
 125+ break;
 126+ case 'defined-meaning':
 127+ list($recordSet, $editor) = getDefinedMeaningAsRecordSet($queryResult);
 128+ break;
 129+ case 'class-attributes-level':
 130+ list($recordSet, $editor) = getClassAttributeLevelAsRecordSet($queryResult);
 131+ break;
 132+ case 'collection':
 133+ list($recordSet, $editor) = getCollectionAsRecordSet($queryResult);
 134+ break;
 135+ case 'language':
 136+ list($recordSet, $editor) = getLanguageAsRecordSet($queryResult);
 137+ break;
 138+ case 'transaction':
 139+ list($recordSet, $editor) = getTransactionAsRecordSet($queryResult);
 140+ break;
 141+ }
 142+
 143+ return $editor->view(new IdStack($prefix . 'table'), $recordSet);
 144+}
 145+
 146+function getSQLForCollectionOfType($collectionType) {
 147+ return "SELECT member_mid, spelling, collection_mid " .
 148+ "FROM uw_collection_contents, uw_collection_ns, uw_syntrans syntrans, uw_expression_ns expression " .
 149+ "WHERE uw_collection_contents.collection_id=uw_collection_ns.collection_id and uw_collection_ns.collection_type='$collectionType' " .
 150+
 151+ "AND syntrans.defined_meaning_id=uw_collection_contents.member_mid " .
 152+ "AND expression.expression_id=syntrans.expression_id AND syntrans.identical_meaning=1 ".
 153+ "AND " . getLatestTransactionRestriction('syntrans') .
 154+ "AND " . getLatestTransactionRestriction('expression') .
 155+ "AND " . getLatestTransactionRestriction('uw_collection_contents');
 156+}
 157+
 158+function getRelationTypeAsRecordSet($queryResult) {
 159+ global
 160+ $idAttribute;
 161+
 162+ $dbr =& wfGetDB(DB_SLAVE);
 163+
 164+ $relationTypeAttribute = new Attribute("relation-type", "Relation type", "short-text");
 165+ $collectionAttribute = new Attribute("collection", "Collection", "short-text");
 166+
 167+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $relationTypeAttribute, $collectionAttribute), new Structure($idAttribute));
 168+
 169+ while ($row = $dbr->fetchObject($queryResult))
 170+ $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
 171+
 172+ $editor = createSuggestionsTableViewer(null);
 173+ $editor->addEditor(createShortTextViewer($relationTypeAttribute));
 174+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 175+
 176+ return array($recordSet, $editor);
 177+}
 178+
 179+function getClassAsRecordSet($queryResult) {
 180+ global
 181+ $idAttribute;
 182+
 183+ $dbr =& wfGetDB(DB_SLAVE);
 184+ $classAttribute = new Attribute("class", "Class", "short-text");
 185+ $collectionAttribute = new Attribute("collection", "Collection", "short-text");
 186+
 187+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $classAttribute, $collectionAttribute), new Structure($idAttribute));
 188+
 189+ while ($row = $dbr->fetchObject($queryResult))
 190+ $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
 191+
 192+ $editor = createSuggestionsTableViewer(null);
 193+ $editor->addEditor(createShortTextViewer($classAttribute));
 194+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 195+
 196+ return array($recordSet, $editor);
 197+}
 198+
 199+function getTextAttributeAsRecordSet($queryResult) {
 200+ global
 201+ $idAttribute, $textAttributeAttribute, $collectionAttribute;
 202+
 203+ $dbr =& wfGetDB(DB_SLAVE);
 204+
 205+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $textAttributeAttribute, $collectionAttribute), new Structure($idAttribute));
 206+
 207+ while ($row = $dbr->fetchObject($queryResult))
 208+ $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
 209+
 210+ $editor = createSuggestionsTableViewer(null);
 211+ $editor->addEditor(createShortTextViewer($textAttributeAttribute));
 212+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 213+
 214+ return array($recordSet, $editor);
 215+}
 216+
 217+function getTranslatedTextAttributeAsRecordSet($queryResult) {
 218+ global
 219+ $idAttribute, $translatedTextAttributeAttribute, $collectionAttribute;
 220+
 221+ $dbr =& wfGetDB(DB_SLAVE);
 222+// $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", "Translated text attribute", "short-text");
 223+// $collectionAttribute = new Attribute("collection", "Collection", "short-text");
 224+
 225+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $translatedTextAttributeAttribute, $collectionAttribute), new Structure($idAttribute));
 226+
 227+ while ($row = $dbr->fetchObject($queryResult))
 228+ $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
 229+
 230+ $editor = createSuggestionsTableViewer(null);
 231+ $editor->addEditor(createShortTextViewer($translatedTextAttributeAttribute));
 232+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 233+
 234+ return array($recordSet, $editor);
 235+}
 236+
 237+function getDefinedMeaningAsRecordSet($queryResult) {
 238+ global
 239+ $idAttribute;
 240+
 241+ $dbr =& wfGetDB(DB_SLAVE);
 242+ $spellingAttribute = new Attribute("spelling", "Spelling", "short-text");
 243+ $languageAttribute = new Attribute("language", "Language", "language");
 244+
 245+ $expressionStructure = new Structure($spellingAttribute, $languageAttribute);
 246+ $definedMeaningAttribute = new Attribute("defined-meaning", "Defined meaning", new RecordType($expressionStructure));
 247+ $definitionAttribute = new Attribute("definition", "Definition", "definition");
 248+
 249+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $definedMeaningAttribute, $definitionAttribute), new Structure($idAttribute));
 250+
 251+ while ($row = $dbr->fetchObject($queryResult)) {
 252+ $definedMeaningRecord = new ArrayRecord($expressionStructure);
 253+ $definedMeaningRecord->setAttributeValue($spellingAttribute, $row->spelling);
 254+ $definedMeaningRecord->setAttributeValue($languageAttribute, $row->language_id);
 255+
 256+ $recordSet->addRecord(array($row->defined_meaning_id, $definedMeaningRecord, getDefinedMeaningDefinition($row->defined_meaning_id)));
 257+ }
 258+
 259+ $expressionEditor = new RecordTableCellEditor($definedMeaningAttribute);
 260+ $expressionEditor->addEditor(createShortTextViewer($spellingAttribute));
 261+ $expressionEditor->addEditor(createLanguageViewer($languageAttribute));
 262+
 263+ $editor = createSuggestionsTableViewer(null);
 264+ $editor->addEditor($expressionEditor);
 265+ $editor->addEditor(new TextEditor($definitionAttribute, new SimplePermissionController(false), false, true, 75));
 266+
 267+ return array($recordSet, $editor);
 268+}
 269+
 270+function getClassAttributeLevelAsRecordSet($queryResult) {
 271+ global
 272+ $idAttribute;
 273+
 274+ $dbr =& wfGetDB(DB_SLAVE);
 275+
 276+ $classAttributeLevelAttribute = new Attribute("class-attribute-level", "Level", "short-text");
 277+ $collectionAttribute = new Attribute("collection", "Collection", "short-text");
 278+
 279+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $classAttributeLevelAttribute, $collectionAttribute), new Structure($idAttribute));
 280+
 281+ while ($row = $dbr->fetchObject($queryResult))
 282+ $recordSet->addRecord(array($row->member_mid, $row->spelling, definedMeaningExpression($row->collection_mid)));
 283+
 284+ $editor = createSuggestionsTableViewer(null);
 285+ $editor->addEditor(createShortTextViewer($classAttributeLevelAttribute));
 286+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 287+
 288+ return array($recordSet, $editor);
 289+}
 290+
 291+function getCollectionAsRecordSet($queryResult) {
 292+ global
 293+ $idAttribute;
 294+
 295+ $dbr =& wfGetDB(DB_SLAVE);
 296+ $collectionAttribute = new Attribute("collection", "Collection", "short-text");
 297+
 298+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $collectionAttribute), new Structure($idAttribute));
 299+
 300+ while ($row = $dbr->fetchObject($queryResult))
 301+ $recordSet->addRecord(array($row->collection_id, $row->spelling));
 302+
 303+ $editor = createSuggestionsTableViewer(null);
 304+ $editor->addEditor(createShortTextViewer($collectionAttribute));
 305+
 306+ return array($recordSet, $editor);
 307+}
 308+
 309+function getLanguageAsRecordSet($queryResult) {
 310+ global
 311+ $idAttribute;
 312+
 313+ $dbr =& wfGetDB(DB_SLAVE);
 314+ $languageAttribute = new Attribute("language", "Language", "short-text");
 315+
 316+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $languageAttribute), new Structure($idAttribute));
 317+
 318+ while ($row = $dbr->fetchObject($queryResult))
 319+ $recordSet->addRecord(array($row->row_id, $row->language_name));
 320+
 321+ $editor = createSuggestionsTableViewer(null);
 322+ $editor->addEditor(createShortTextViewer($languageAttribute));
 323+
 324+ return array($recordSet, $editor);
 325+}
 326+
 327+function getTransactionAsRecordSet($queryResult) {
 328+ global
 329+ $idAttribute, $userAttribute;
 330+
 331+ $dbr =& wfGetDB(DB_SLAVE);
 332+
 333+ $timestampAttribute = new Attribute("timestamp", "Time", "timestamp");
 334+ $summaryAttribute = new Attribute("summary", "Summary", "short-text");
 335+
 336+ $recordSet = new ArrayRecordSet(new Structure($idAttribute, $userAttribute, $timestampAttribute, $summaryAttribute), new Structure($idAttribute));
 337+
 338+ while ($row = $dbr->fetchObject($queryResult))
 339+ $recordSet->addRecord(array($row->transaction_id, getUserLabel($row->user_id, $row->user_ip), $row->time, $row->comment));
 340+
 341+ $editor = createSuggestionsTableViewer(null);
 342+ $editor->addEditor(createShortTextViewer($timestampAttribute));
 343+ $editor->addEditor(createShortTextViewer($idAttribute));
 344+ $editor->addEditor(createShortTextViewer($userAttribute));
 345+ $editor->addEditor(createShortTextViewer($summaryAttribute));
 346+
 347+ return array($recordSet, $editor);
 348+}
 349+
 350+?>
Property changes on: trunk/extensions/Wikidata/WiktionaryZ/SpecialSuggest.php
___________________________________________________________________
Added: svn:eol-style
367351 + native
Index: trunk/extensions/Wikidata/WiktionaryZ/languages.php
@@ -5,20 +5,16 @@
66
77 $wgLanguageNames = getLangNames($wgUser->getOption('language'));
88
9 -# Falls back to English if no language name translations available for chosen languages
 9+/* Return an array containing all language names translated into the language
 10+ indicated by $code, with fallbacks in English where the language names
 11+ aren't present in that language. */
1012 function getLangNames($code) {
11 - $id = getLanguageIdForCode($code);
12 -
13 - if(!$id)
14 - $id = getLanguageIdForCode('en');
15 -
16 - $names = getLanguageNamesForId($id);
17 -
18 - if (empty($names)) {
19 - $id = getLanguageIdForCode('en');
20 - $names = getLanguageNamesForId($id);
21 - }
22 -
 13+ $dbr = &wfGetDB(DB_SLAVE);
 14+ $names = array();
 15+ $sql = getSQLForLanguageNames($code);
 16+ $lang_res = $dbr->query($sql);
 17+ while ($lang_row = $dbr->fetchObject($lang_res))
 18+ $names[$lang_row->row_id] = $lang_row->language_name;
2319 return $names;
2420 }
2521
@@ -29,14 +25,21 @@
3026 return $id_row->language_id;
3127 }
3228
33 -function getLanguageNamesForId($id) {
34 - $dbr = &wfGetDB(DB_SLAVE);
35 - $langs = array();
36 - $lang_res = $dbr->query("select language_names.language_id,language_names.language_name,language.wikimedia_key from language,language_names where language_names.name_language_id=".$id." and language.language_id=language_names.name_language_id");
37 - while($lang_row=$dbr->fetchObject($lang_res)) {
38 - $langs[$lang_row->language_id]=$lang_row->language_name;
39 - }
40 - return $langs;
 29+/* Return SQL query string for fetching language names. */
 30+function getSQLForLanguageNames($lang_code) {
 31+ /* Use a simpler query if the user's language is English. */
 32+ if ($lang_code == 'en')
 33+ return "SELECT language.language_id AS row_id,language_names.language_name" .
 34+ " FROM language" .
 35+ " JOIN language_names ON language.language_id = language_names.language_id" .
 36+ " WHERE language_names.name_language_id = " . getLanguageIdForCode('en');
 37+ /* Fall back on English in cases where a language name is not present in the
 38+ user's preferred language. */
 39+ else
 40+ return "SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name" .
 41+ " FROM language" .
 42+ " LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = " . getLanguageIdForCode($lang_code) .
 43+ " JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = " . getLanguageIdForCode('en');
4144 }
4245
4346 function getLanguageIdForName($name) {
Property changes on: trunk/extensions/Wikidata/WiktionaryZ/languages.php
___________________________________________________________________
Added: svn:eol-style
4447 + native

Status & tagging log