1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<?php
/**
* Contains classes for addition of extension specific preference settings.
*
* @file
* @author Siebrand Mazeland
* @author Niklas Laxström
* @copyright Copyright © 2008-2010 Siebrand Mazeland, Niklas Laxström
* @license GPL-2.0+
*/
/**
* Class to add Translate specific preference settings.
*/
class TranslatePreferences {
/**
* Add 'translate-pref-nonewsletter' preference.
* This is most probably specific to translatewiki.net. Can be enabled
* with $wgTranslateNewsletterPreference.
*
* @param $user User
* @param $preferences array
* @return bool true
*/
public static function onGetPreferences( $user, &$preferences ) {
global $wgTranslateNewsletterPreference;
if ( !$wgTranslateNewsletterPreference ) {
return true;
}
global $wgEnableEmail, $wgEnotifRevealEditorAddress;
// Only show if email is enabled and user has a confirmed email address.
if ( $wgEnableEmail && $user->isEmailConfirmed() ) {
// 'translate-pref-nonewsletter' is used as opt-out for
// users with a confirmed email address
$prefs = array(
'translate-nonewsletter' => array(
'type' => 'toggle',
'section' => 'personal/email',
'label-message' => 'translate-pref-nonewsletter'
)
);
// Add setting after 'enotifrevealaddr'.
$preferences = wfArrayInsertAfter( $preferences, $prefs,
$wgEnotifRevealEditorAddress ? 'enotifrevealaddr' : 'enotifminoredits' );
}
return true;
}
/**
* Add 'translate-editlangs' preference.
* These are the languages also shown when translating.
*
* @param User $user
* @param array $preferences
* @return bool true
*/
public static function translationAssistLanguages( User $user, &$preferences ) {
// Get selector.
$select = self::languageSelector();
// Set target ID.
$select->setTargetId( 'mw-input-translate-editlangs' );
// Get available languages.
$languages = Language::fetchLanguageNames();
$preferences['translate-editlangs'] = array(
'class' => 'HTMLJsSelectToInputField',
'section' => 'editing/translate',
'label-message' => 'translate-pref-editassistlang',
'help-message' => 'translate-pref-editassistlang-help',
'select' => $select,
'valid-values' => array_keys( $languages ),
'name' => 'translate-editlangs',
);
return true;
}
/**
* JavsScript selector for language codes.
* @return JsSelectToInput
*/
protected static function languageSelector() {
if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
$lang = RequestContext::getMain()->getLanguage();
$languages = LanguageNames::getNames( $lang->getCode(),
LanguageNames::FALLBACK_NORMAL
);
} else {
$languages = Language::fetchLanguageNames();
}
ksort( $languages );
$selector = new XmlSelect( 'mw-language-selector', 'mw-language-selector' );
foreach ( $languages as $code => $name ) {
$selector->addOption( "$code - $name", $code );
}
$jsSelect = new JsSelectToInput( $selector );
$jsSelect->setSourceId( 'mw-language-selector' );
return $jsSelect;
}
}
|