r83165 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83164‎ | r83165 | r83166 >
Date:19:52, 3 March 2011
Author:kipcool
Status:deferred
Tags:
Comment:
Using wgLang instead of wgUser to detect the active language. This permits the uselang=... parameter to work as expected.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/ExpressionPage.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSelect.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/forms.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/languages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSelect.php
@@ -29,13 +29,12 @@
3030 }
3131
3232 function getSelectOptions() {
33 - global $wgUser;
34 - global $wgOptionAttribute;
 33+ global $wgLang, $wgOptionAttribute;
3534
3635 $dc = wdGetDataSetContext();
3736 $optionAttribute = $_GET[$wgOptionAttribute];
3837 $attributeObject = $_GET['attribute-object'];
39 - $lang_code = $wgUser->getOption( 'language' );
 38+ $lang_code = $wgLang->getCode();
4039
4140 $dbr = wfGetDB( DB_SLAVE );
4241 $sql = 'SELECT language_id' .
Index: trunk/extensions/Wikidata/OmegaWiki/forms.php
@@ -194,10 +194,9 @@
195195 }
196196
197197 function getLanguageOptions( $languageIdsToExclude = array() ) {
198 - global
199 - $wgUser;
 198+ global $wgLang ;
200199
201 - $userLanguage = $wgUser->getOption( 'language' );
 200+ $userLanguage = $wgLang->getCode();
202201 $idNameIndex = getLangNames( $userLanguage );
203202
204203 $result = array();
@@ -210,11 +209,8 @@
211210 }
212211
213212 function getLanguageSelect( $name, $languageIdsToExclude = array() ) {
214 - global
215 - $wgUser;
216 -
217 - $userLanguage = $wgUser->getOption( 'language' );
218 - $userLanguageId = getLanguageIdForCode( $userLanguage );
 213+ global $wgLang ;
 214+ $userLanguageId = getLanguageIdForCode( $wgLang->getCode() ) ;
219215
220216 return getSelect( $name, getLanguageOptions( $languageIdsToExclude ), $userLanguageId );
221217 }
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1084,10 +1084,8 @@
10851085 * @param $definedMeaningId
10861086 */
10871087 function getDefinedMeaningDefinition( $definedMeaningId ) {
1088 - global
1089 - $wgUser;
1090 -
1091 - $userLanguageId = getLanguageIdForCode( $wgUser->getOption( 'language' ) );
 1088+ global $wgLang;
 1089+ $userLanguageId = getLanguageIdForCode( $wgLang->getCode() ) ;
10921090
10931091 if ( $userLanguageId > 0 )
10941092 $result = getDefinedMeaningDefinitionForLanguage( $definedMeaningId, $userLanguageId );
@@ -1100,7 +1098,6 @@
11011099 if ( $result == "" )
11021100 $result = getDefinedMeaningDefinitionForAnyLanguage( $definedMeaningId );
11031101 }
1104 -
11051102 return $result;
11061103 }
11071104
@@ -1521,11 +1518,11 @@
15221519 }
15231520 $dbr = wfGetDB( DB_SLAVE );
15241521 $queryResult = $dbr->query( "SELECT spelling " .
1525 - " FROM {$dc}_defined_meaning, {$dc}_expression " .
1526 - " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
1527 - " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" .
1528 - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) .
1529 - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
 1522+ " FROM {$dc}_defined_meaning, {$dc}_expression " .
 1523+ " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
 1524+ " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" .
 1525+ " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) .
 1526+ " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
15301527 $expression = $dbr->fetchObject( $queryResult );
15311528 if ( $expression ) {
15321529 return $expression->spelling;
@@ -1591,17 +1588,17 @@
15921589 * @param $definedMeaningId
15931590 */
15941591 function definedMeaningExpression( $definedMeaningId ) {
1595 - global $wgUser;
 1592+ global $wgLang;
 1593+
 1594+ $userLanguageId = getLanguageIdForCode( $wgLang->getCode() ) ;
15961595
1597 - $userLanguage = getLanguageIdForCode( $wgUser->getOption( 'language' ) );
1598 -
15991596 list( $definingExpressionId, $definingExpression, $definingExpressionLanguage ) = definingExpressionRow( $definedMeaningId );
16001597
1601 - if ( $definingExpressionLanguage == $userLanguage && expressionIsBoundToDefinedMeaning( $definedMeaningId, $definingExpressionId ) )
 1598+ if ( $definingExpressionLanguage == $userLanguageId && expressionIsBoundToDefinedMeaning( $definedMeaningId, $definingExpressionId ) )
16021599 return $definingExpression;
16031600 else {
1604 - if ( $userLanguage > 0 )
1605 - $result = definedMeaningExpressionForLanguage( $definedMeaningId, $userLanguage );
 1601+ if ( $userLanguageId > 0 )
 1602+ $result = definedMeaningExpressionForLanguage( $definedMeaningId, $userLanguageId );
16061603 else
16071604 $result = "";
16081605
Index: trunk/extensions/Wikidata/OmegaWiki/ExpressionPage.php
@@ -1,5 +1,10 @@
22 <?php
33
 4+/**
 5+ * What is this PHP file for?
 6+ * The software seems to work fine even if we delete this file
 7+ */
 8+
49 require_once( 'Wikidata.php' );
510 require_once( 'Transaction.php' );
611 require_once( 'WikiDataAPI.php' );
@@ -19,8 +24,7 @@
2025 */
2126 class ExpressionPage extends DefaultWikidataApplication {
2227 public function view() {
23 - global
24 - $wgOut, $wgTitle;
 28+ global $wgOut, $wgTitle;
2529
2630 parent::view();
2731 $expressionAsPageTitle = $wgTitle->getText();
@@ -83,8 +87,7 @@
8488 }
8589
8690 public function history() {
87 - global
88 - $wgOut, $wgTitle;
 91+ global $wgOut, $wgTitle;
8992
9093 parent::history();
9194
@@ -102,8 +105,7 @@
103106 }
104107
105108 protected function save( $referenceQueryTransactionInformation ) {
106 - global
107 - $wgTitle;
 109+ global $wgTitle;
108110
109111 parent::save( $referenceQueryTransactionInformation );
110112
@@ -116,8 +118,7 @@
117119 }
118120
119121 public function edit() {
120 - global
121 - $wgOut, $wgTitle, $wgUser;
 122+ global $wgOut, $wgTitle, $wgUser;
122123
123124 if ( !parent::edit() ) return false;
124125 $this->outputEditHeader();
@@ -135,8 +136,7 @@
136137 }
137138
138139 public function getTitle() {
139 - global
140 - $wgTitle, $wgUseExpressionPageTitlePrefix;
 140+ global $wgTitle, $wgUseExpressionPageTitlePrefix;
141141
142142 if ( $wgUseExpressionPageTitlePrefix )
143143 $title = wfMsg( 'ow_Multiple_meanings', $wgTitle->getText() );
Index: trunk/extensions/Wikidata/OmegaWiki/languages.php
@@ -5,10 +5,10 @@
66 * @return array of language names for the user's language preference
77 **/
88 function getOwLanguageNames( $purge = false ) {
9 - global $wgUser;
 9+ global $wgLang ;
1010 static $owLanguageNames = null;
1111 if ( is_null( $owLanguageNames ) && !$purge ) {
12 - $owLanguageNames = getLangNames( $wgUser->getOption( 'language' ) );
 12+ $owLanguageNames = getLangNames( $wgLang->getCode() );
1313 }
1414 return $owLanguageNames;
1515
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php
@@ -59,8 +59,8 @@
6060
6161 protected function ui() {
6262
63 - global $wgOut, $wgRequest, $wgUser, $wgDefinedMeaning;
64 - $lang = $wgUser->getOption( "language" );
 63+ global $wgOut, $wgRequest, $wgLang, $wgDefinedMeaning;
 64+ $lang = $wgLang->getCode();
6565 require_once( "forms.php" );
6666 $wgOut->addHTML( wfMsgSc( "conceptmapping_uitext" ) );
6767 $sets = wdGetDataSets();
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -165,9 +165,9 @@
166166 }
167167
168168 function getDefinedMeaningReferenceRecords( array $definedMeaningIds, $usedAs ) {
169 - global
170 - $wgUser;
171 -
 169+ global $wgLang ;
 170+ $userLanguageId = getLanguageIdForCode( $wgLang->getCode() ) ;
 171+
172172 // $startTime = microtime(true);
173173
174174 $result = array();
@@ -180,7 +180,7 @@
181181 $userLanguage = $wgRecordSetLanguage;
182182 }
183183 else {
184 - $userLanguage = getLanguageIdForCode( $wgUser->getOption( 'language' ) );
 184+ $userLanguage = getLanguageIdForCode( $wgLang->getCode() );
185185 }
186186
187187 if ( $userLanguage > 0 )
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
@@ -42,7 +42,7 @@
4343 */
4444 function getSuggestions() {
4545 $o = OmegaWikiAttributes::getInstance();
46 - global $wgUser;
 46+ global $wgLang;
4747 global
4848 $wgDefinedMeaning,
4949 $wgDefinedMeaningAttributes,
@@ -58,6 +58,7 @@
5959 @$attributesLevel = $_GET['attributesLevel'];
6060 @$annotationAttributeId = $_GET['annotationAttributeId'];
6161 $syntransId = $_GET["syntransId"];
 62+ $langCode = $wgLang->getCode();
6263
6364 $sql = '';
6465
@@ -65,14 +66,14 @@
6667 $rowText = 'spelling';
6768 switch ( $query ) {
6869 case 'relation-type':
69 - $sqlActual = getSQLForCollectionOfType( 'RELT', $wgUser->getOption( 'language' ) );
 70+ $sqlActual = getSQLForCollectionOfType( 'RELT', $langCode );
7071 $sqlFallback = getSQLForCollectionOfType( 'RELT', 'en' );
7172 $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "member_mid", "spelling", "collection_mid" ) );
7273 break;
7374 case 'class':
7475 // constructSQLWithFallback is a bit broken in this case, showing several time the same lines
7576 // so : not using it. The English fall back has been included in the SQL query
76 - $sql = getSQLForClasses( $wgUser->getOption( 'language' ) );
 77+ $sql = getSQLForClasses( $langCode );
7778 break;
7879 case "$wgDefinedMeaningAttributes":
7980 $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'DM' );
@@ -91,7 +92,7 @@
9293 break;
9394 case 'language':
9495 require_once( 'languages.php' );
95 - $sql = getSQLForLanguageNames( $wgUser->getOption( 'language' ) );
 96+ $sql = getSQLForLanguageNames( $langCode );
9697 $rowText = 'language_name';
9798 break;
9899 case "$wgDefinedMeaning":
@@ -104,10 +105,10 @@
105106 " AND " . getLatestTransactionRestriction( "{$dc}_expression" );
106107 break;
107108 case 'class-attributes-level':
108 - $sql = getSQLForLevels( $wgUser->getOption( 'language' ) );
 109+ $sql = getSQLForLevels( $langCode );
109110 break;
110111 case 'collection':
111 - $sqlActual = getSQLForCollection( $wgUser->getOption( 'language' ) );
 112+ $sqlActual = getSQLForCollection( $langCode );
112113 $sqlFallback = getSQLForCollection( 'en' );
113114 $sql = constructSQLWithFallback( $sqlActual, $sqlFallback, array( "collection_id", "spelling" ) );
114115 break;
@@ -256,12 +257,12 @@
257258
258259 function getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, $attributesType ) {
259260
260 - global $wgDefaultClassMids, $wgUser;
 261+ global $wgDefaultClassMids, $wgLang;
261262
262263 $dc = wdGetDataSetContext();
263264 $dbr = wfGetDB( DB_SLAVE );
264265
265 - $language = $wgUser->getOption( 'language' ) ;
 266+ $language = $wgLang->getCode() ;
266267 $lng = ' ( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' ) ';
267268
268269 $classMids = $wgDefaultClassMids ;
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -397,9 +397,9 @@
398398
399399 // Fetch!
400400 function fetchName() {
401 - global $wgUser, $wdTermDBDataSet;
 401+ global $wgLang, $wdTermDBDataSet;
402402 if ( $wdTermDBDataSet ) {
403 - $userLanguage = $wgUser->getOption( 'language' );
 403+ $userLanguageId = $wgLang->getCode() ;
404404 $spelling = getSpellingForLanguage( $this->dmId, $userLanguage, 'en', $wdTermDBDataSet );
405405 if ( $spelling ) return $spelling;
406406 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r83171Remove obsolete ExpressionPage.php after comment in r83165....siebrand21:01, 3 March 2011

Status & tagging log