UserToggles.php

Go to the documentation of this file.
00001 <?php
00015 class TranslatePreferences {
00025     public static function onGetPreferences( $user, &$preferences ) {
00026         global $wgTranslateNewsletterPreference;
00027 
00028         if ( !$wgTranslateNewsletterPreference ) {
00029             return true;
00030         }
00031 
00032         global $wgEnableEmail, $wgEnotifRevealEditorAddress;
00033 
00034         // Only show if email is enabled and user has a confirmed email address.
00035         if ( $wgEnableEmail && $user->isEmailConfirmed() ) {
00036             // 'translate-pref-nonewsletter' is used as opt-out for
00037             // users with a confirmed email address
00038             $prefs = array(
00039                 'translate-nonewsletter' => array(
00040                     'type' => 'toggle',
00041                     'section' => 'personal/email',
00042                     'label-message' => 'translate-pref-nonewsletter'
00043                 )
00044             );
00045 
00046             // Add setting after 'enotifrevealaddr'.
00047             $preferences = wfArrayInsertAfter( $preferences, $prefs,
00048                 $wgEnotifRevealEditorAddress ? 'enotifrevealaddr' : 'enotifminoredits' );
00049         }
00050 
00051         return true;
00052     }
00053 
00062     public static function translationAssistLanguages( User $user, &$preferences ) {
00063         // Get selector.
00064         $select = self::languageSelector();
00065         // Set target ID.
00066         $select->setTargetId( 'mw-input-translate-editlangs' );
00067         // Get available languages.
00068         $languages = Language::getLanguageNames( false );
00069 
00070         $preferences['translate-editlangs'] = array(
00071             'class' => 'HTMLJsSelectToInputField',
00072             'section' => 'editing/translate',
00073             'label-message' => 'translate-pref-editassistlang',
00074             'help-message' => 'translate-pref-editassistlang-help',
00075             'select' => $select,
00076             'valid-values' => array_keys( $languages ),
00077             'name' => 'translate-editlangs',
00078         );
00079 
00080         return true;
00081     }
00082 
00091     public static function translationJsedit( User $user, &$preferences ) {
00092         $preferences['translate-jsedit'] = array(
00093             'class' => 'HTMLCheckField',
00094             'section' => 'editing/translate',
00095             'label-message' => 'translate-pref-jsedit',
00096         );
00097 
00098         return true;
00099     }
00100 
00105     protected static function languageSelector() {
00106         if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
00107             $lang = RequestContext::getMain()->getLanguage();
00108             $languages = LanguageNames::getNames( $lang->getCode(),
00109                 LanguageNames::FALLBACK_NORMAL
00110             );
00111         } else {
00112             $languages = Language::getLanguageNames( false );
00113         }
00114 
00115         ksort( $languages );
00116 
00117         $selector = new XmlSelect( 'mw-language-selector', 'mw-language-selector' );
00118         foreach ( $languages as $code => $name ) {
00119             $selector->addOption( "$code - $name", $code );
00120         }
00121 
00122         $jsSelect = new JsSelectToInput( $selector );
00123         $jsSelect->setSourceId( 'mw-language-selector' );
00124 
00125         return $jsSelect;
00126     }
00127 }
Generated on Tue Oct 29 00:00:26 2013 for MediaWiki Translate Extension by  doxygen 1.6.3