Index: trunk/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php |
— | — | @@ -23,7 +23,9 @@ |
24 | 24 | |
25 | 25 | $dbr = wfGetDB( DB_MASTER ); |
26 | 26 | |
27 | | - /* Get collection ID for "ISO 639-3 codes" collection. */ |
| 27 | + /* Get collection ID for "ISO 639-3 codes" collection. |
| 28 | + if we want to find $collection_id , we can use the following query */ |
| 29 | + /* |
28 | 30 | $sql = "SELECT collection_id FROM {$dc}_collection" . |
29 | 31 | " JOIN {$dc}_defined_meaning ON defined_meaning_id = collection_mid" . |
30 | 32 | " JOIN {$dc}_expression ON" . |
— | — | @@ -33,6 +35,9 @@ |
34 | 36 | ' LIMIT 1'; |
35 | 37 | $collection_id_res = $dbr->query( $sql ); |
36 | 38 | $collection_id = $this->fetchResult( $dbr->fetchRow( $collection_id_res ) ); |
| 39 | + */ |
| 40 | + // but having "ISO 639-3 codes" hardcoded is the same as having "145264" hardcoded |
| 41 | + $collection_id = 145264 ; |
37 | 42 | |
38 | 43 | /* Get defined meaning IDs and ISO codes for languages in collection. */ |
39 | 44 | $sql = "SELECT member_mid,internal_member_id FROM {$dc}_collection_contents" . |
— | — | @@ -41,20 +46,20 @@ |
42 | 47 | $lang_res = $dbr->query( $sql ); |
43 | 48 | $editable = ''; |
44 | 49 | $first = true; |
| 50 | + |
45 | 51 | while ( $lang_row = $dbr->fetchRow( $lang_res ) ) { |
46 | 52 | $iso_code = $lang_row['internal_member_id']; |
47 | 53 | $dm_id = $lang_row['member_mid']; |
48 | 54 | |
49 | 55 | /* Get the language ID for the current language. */ |
50 | | - $sql = 'SELECT language_id FROM language' . |
51 | | - ' WHERE iso639_3 LIKE ' . $dbr->addQuotes( $iso_code ) . |
52 | | - ' LIMIT 1'; |
53 | | - $lang_id_res = $dbr->query( $sql ); |
54 | | - if ( $dbr->numRows( $lang_id_res ) ) { |
55 | | - if ( !$first ) |
| 56 | + $lang_id = getLanguageIdForIso639_3( $iso_code ) ; |
| 57 | + |
| 58 | + if ( $lang_id ) { |
| 59 | + if ( !$first ) { |
56 | 60 | $wgOut->addHTML( '<br />' . "\n" ); |
57 | | - else |
| 61 | + } else { |
58 | 62 | $first = false; |
| 63 | + } |
59 | 64 | $wgOut->addHTML( wfMsg( 'importlangnames_added', $iso_code ) ); |
60 | 65 | |
61 | 66 | /* Add current language to list of portals/DMs. */ |
— | — | @@ -64,11 +69,33 @@ |
65 | 70 | ' LIMIT 1'; |
66 | 71 | $dm_expr_res = $dbr->query( $sql ); |
67 | 72 | $dm_expr = $this->fetchResult( $dbr->fetchRow( $dm_expr_res ) ); |
68 | | - if ( $editable != '' ) |
69 | | - $editable .= "\n"; |
| 73 | + if ( $editable != '' ) $editable .= "\n"; |
70 | 74 | $editable .= '*[[Portal:' . $iso_code . ']] - [[DefinedMeaning:' . $dm_expr . ' (' . $dm_id . ')]]'; |
71 | | - } |
72 | | - else { |
| 75 | + |
| 76 | + /* Delete all language names that match current language ID. */ |
| 77 | + $sql = 'DELETE FROM language_names' . |
| 78 | + ' WHERE language_id = ' . $lang_id; |
| 79 | + $dbr->query( $sql ); |
| 80 | + |
| 81 | + /* Get syntrans expressions for names of language and IDs for the languages the names are in. */ |
| 82 | + $sql = "SELECT spelling,language_id FROM {$dc}_expression" . |
| 83 | + " JOIN {$dc}_syntrans" . |
| 84 | + " ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
| 85 | + ' WHERE defined_meaning_id = ' . $dm_id . |
| 86 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
| 87 | + ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
| 88 | + ' GROUP BY language_id ORDER BY NULL'; |
| 89 | + $syntrans_res = $dbr->query( $sql ); |
| 90 | + while ( $syntrans_row = $dbr->fetchRow( $syntrans_res ) ) { |
| 91 | + $sql = 'INSERT INTO language_names' . |
| 92 | + ' (`language_id`,`name_language_id`,`language_name`)' . |
| 93 | + ' VALUES(' . $lang_id . ', ' . |
| 94 | + $syntrans_row['language_id'] . ', ' . |
| 95 | + $dbr->addQuotes( $syntrans_row['spelling'] ) . ')'; |
| 96 | + $dbr->query( $sql ); |
| 97 | + } |
| 98 | + |
| 99 | + } else { |
73 | 100 | if ( !$first ) |
74 | 101 | $wgOut->addHTML( '<br />' . "\n" ); |
75 | 102 | else |
— | — | @@ -76,30 +103,6 @@ |
77 | 104 | $wgOut->addHTML( wfMsg( 'importlangnames_not_found', $iso_code ) ); |
78 | 105 | continue; |
79 | 106 | } |
80 | | - $lang_id = $this->fetchResult( $dbr->fetchRow( $lang_id_res ) ); |
81 | | - |
82 | | - /* Delete all language names that match current language ID. */ |
83 | | - $sql = 'DELETE FROM language_names' . |
84 | | - ' WHERE language_id = ' . $lang_id; |
85 | | - $dbr->query( $sql ); |
86 | | - |
87 | | - /* Get syntrans expressions for names of language and IDs for the languages the names are in. */ |
88 | | - $sql = "SELECT spelling,language_id FROM {$dc}_expression" . |
89 | | - " JOIN {$dc}_syntrans" . |
90 | | - " ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" . |
91 | | - ' WHERE defined_meaning_id = ' . $dm_id . |
92 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . |
93 | | - ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) . |
94 | | - ' GROUP BY language_id ORDER BY NULL'; |
95 | | - $syntrans_res = $dbr->query( $sql ); |
96 | | - while ( $syntrans_row = $dbr->fetchRow( $syntrans_res ) ) { |
97 | | - $sql = 'INSERT INTO language_names' . |
98 | | - ' (`language_id`,`name_language_id`,`language_name`)' . |
99 | | - ' VALUES(' . $lang_id . ', ' . |
100 | | - $syntrans_row['language_id'] . ', ' . |
101 | | - $dbr->addQuotes( $syntrans_row['spelling'] ) . ')'; |
102 | | - $dbr->query( $sql ); |
103 | | - } |
104 | 107 | } |
105 | 108 | $this->addDMsListToPage( $editable, 'Editable_languages' ); |
106 | 109 | } |