r93424 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93423‎ | r93424 | r93425 >
Date:20:00, 28 July 2011
Author:kipcool
Status:deferred
Tags:
Comment:
several optimizations
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php
@@ -23,7 +23,9 @@
2424
2525 $dbr = wfGetDB( DB_MASTER );
2626
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+ /*
2830 $sql = "SELECT collection_id FROM {$dc}_collection" .
2931 " JOIN {$dc}_defined_meaning ON defined_meaning_id = collection_mid" .
3032 " JOIN {$dc}_expression ON" .
@@ -33,6 +35,9 @@
3436 ' LIMIT 1';
3537 $collection_id_res = $dbr->query( $sql );
3638 $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 ;
3742
3843 /* Get defined meaning IDs and ISO codes for languages in collection. */
3944 $sql = "SELECT member_mid,internal_member_id FROM {$dc}_collection_contents" .
@@ -41,20 +46,20 @@
4247 $lang_res = $dbr->query( $sql );
4348 $editable = '';
4449 $first = true;
 50+
4551 while ( $lang_row = $dbr->fetchRow( $lang_res ) ) {
4652 $iso_code = $lang_row['internal_member_id'];
4753 $dm_id = $lang_row['member_mid'];
4854
4955 /* 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 ) {
5660 $wgOut->addHTML( '<br />' . "\n" );
57 - else
 61+ } else {
5862 $first = false;
 63+ }
5964 $wgOut->addHTML( wfMsg( 'importlangnames_added', $iso_code ) );
6065
6166 /* Add current language to list of portals/DMs. */
@@ -64,11 +69,33 @@
6570 ' LIMIT 1';
6671 $dm_expr_res = $dbr->query( $sql );
6772 $dm_expr = $this->fetchResult( $dbr->fetchRow( $dm_expr_res ) );
68 - if ( $editable != '' )
69 - $editable .= "\n";
 73+ if ( $editable != '' ) $editable .= "\n";
7074 $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 {
73100 if ( !$first )
74101 $wgOut->addHTML( '<br />' . "\n" );
75102 else
@@ -76,30 +103,6 @@
77104 $wgOut->addHTML( wfMsg( 'importlangnames_not_found', $iso_code ) );
78105 continue;
79106 }
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 - }
104107 }
105108 $this->addDMsListToPage( $editable, 'Editable_languages' );
106109 }

Status & tagging log