Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -309,7 +309,7 @@ |
310 | 310 | $datasets=wdGetDataSets(); |
311 | 311 | $groups=$wgUser->getGroups(); |
312 | 312 | $dbs=wfGetDB(DB_SLAVE); |
313 | | - $pref=$wgUser->getOption('ow_uipref_context'); |
| 313 | + $pref=$wgUser->getOption('ow_uipref_datasets'); |
314 | 314 | |
315 | 315 | $trydefault=''; |
316 | 316 | foreach($groups as $group) { |
Index: trunk/extensions/Wikidata/AddPrefs.php |
— | — | @@ -21,27 +21,13 @@ |
22 | 22 | define('PREF_TEXT_T', 3); |
23 | 23 | define('PREF_PASSWORD_T', 4); |
24 | 24 | define('PREF_INT_T', 5); |
| 25 | +define('PREF_OPTIONS_T', 6); |
25 | 26 | |
26 | 27 | // each element of the following should be an array that can have keys: |
27 | 28 | // name, section, type, size, validate, load, save, html, min, max, default |
28 | 29 | if (!isset($wgExtensionPreferences)) |
29 | 30 | $wgExtensionPreferences = array(); |
30 | 31 | |
31 | | -/** |
32 | | - * Adds an array of prefs to be displayed in the user preferences |
33 | | - * |
34 | | - * @param array $prefs |
35 | | - */ |
36 | | -function wfAddPreferences($prefs) |
37 | | -{ |
38 | | - global $wgExtensionPreferences; |
39 | | - |
40 | | - foreach ($prefs as $pref) |
41 | | - { |
42 | | - $wgExtensionPreferences[] = $pref; |
43 | | - } |
44 | | -} |
45 | | - |
46 | 32 | function wfOverridePreferences(&$list) |
47 | 33 | { |
48 | 34 | // we 'override' the default preferences special page with our own |
— | — | @@ -64,33 +50,33 @@ |
65 | 51 | // one for displaying the form and one for saving the values |
66 | 52 | |
67 | 53 | function savePreferences() |
68 | | - { |
| 54 | + { |
69 | 55 | // handle extension prefs first |
70 | 56 | global $wgUser, $wgRequest; |
71 | 57 | global $wgExtensionPreferences; |
72 | 58 | |
73 | | - foreach ($wgExtensionPreferences as $p) |
| 59 | + foreach ($wgExtensionPreferences as $pref) |
74 | 60 | { |
75 | | - $name = isset($p['name']) ? $p['name'] : ""; |
| 61 | + $name = isset($pref['name']) ? $pref['name'] : ""; |
76 | 62 | if (! $name) |
77 | 63 | continue; |
78 | 64 | |
79 | 65 | $value = $wgRequest->getVal($name); |
80 | | - $type = isset($p['type']) ? $p['type'] : PREF_USER_T; |
| 66 | + $type = isset($pref['type']) ? $pref['type'] : PREF_USER_T; |
81 | 67 | switch ($type) |
82 | 68 | { |
83 | 69 | case PREF_TOGGLE_T: |
84 | | - if (isset($p['save'])) |
85 | | - $p['save']($name, $value); |
| 70 | + if (isset($pref['save'])) |
| 71 | + $pref['save']($name, $value); |
86 | 72 | else |
87 | 73 | $wgUser->setOption($name, $wgRequest->getCheck("wpOp{$name}")); |
88 | 74 | break; |
89 | 75 | |
90 | 76 | case PREF_INT_T: |
91 | | - $min = isset($p['min']) ? $p['min'] : 0; |
92 | | - $max = isset($p['max']) ? $p['max'] : 0x7fffffff; |
93 | | - if (isset($p['save'])) |
94 | | - $p['save']($name, $value); |
| 77 | + $min = isset($pref['min']) ? $pref['min'] : 0; |
| 78 | + $max = isset($pref['max']) ? $pref['max'] : 0x7fffffff; |
| 79 | + if (isset($pref['save'])) |
| 80 | + $pref['save']($name, $value); |
95 | 81 | else |
96 | 82 | $wgUser->setOption($name, $this->validateIntOrNull($value, $min, $max)); |
97 | 83 | break; |
— | — | @@ -99,10 +85,10 @@ |
100 | 86 | case PREF_TEXT_T: |
101 | 87 | case PREF_USER_T: |
102 | 88 | default: |
103 | | - if (isset($p['validate'])) |
104 | | - $value = $p['validate']($value); |
105 | | - if (isset($p['save'])) |
106 | | - $p['save']($name, $value); |
| 89 | + if (isset($pref['validate'])) |
| 90 | + $value = $pref['validate']($value); |
| 91 | + if (isset($pref['save'])) |
| 92 | + $pref['save']($name, $value); |
107 | 93 | else |
108 | 94 | $wgUser->setOption($name, $value); |
109 | 95 | break; |
— | — | @@ -124,23 +110,23 @@ |
125 | 111 | $wgOut->clearHTML(); |
126 | 112 | |
127 | 113 | $sections = array(); |
128 | | - foreach ($wgExtensionPreferences as $p) |
| 114 | + foreach ($wgExtensionPreferences as $pref) |
129 | 115 | { |
130 | | - if (! isset($p['section']) || ! $p['section']) |
| 116 | + if (! isset($pref['section']) || ! $pref['section']) |
131 | 117 | continue; |
132 | | - $section = $p['section']; |
| 118 | + $section = $pref['section']; |
133 | 119 | |
134 | | - $name = isset($p['name']) ? $p['name'] : ""; |
| 120 | + $name = isset($pref['name']) ? $pref['name'] : ""; |
135 | 121 | $value = ""; |
136 | 122 | if ($name) |
137 | 123 | { |
138 | | - if (isset($p['load'])) |
139 | | - $value = $p['load']($name); |
| 124 | + if (isset($pref['load'])) |
| 125 | + $value = $pref['load']($name); |
140 | 126 | else |
141 | 127 | $value = $wgUser->getOption($name); |
142 | 128 | } |
143 | | - if ($value === '' && isset($p['default'])) |
144 | | - $value = $p['default']; |
| 129 | + if ($value === '' && isset($pref['default'])) |
| 130 | + $value = $pref['default']; |
145 | 131 | |
146 | 132 | $sectext = htmlspecialchars(wfMsg($section)); |
147 | 133 | $regex = "/(<fieldset>\s*<legend>\s*" . preg_quote($sectext) . |
— | — | @@ -161,18 +147,18 @@ |
162 | 148 | |
163 | 149 | } |
164 | 150 | |
165 | | - $type = isset($p['type']) ? $p['type'] : PREF_USER_T; |
| 151 | + $type = isset($pref['type']) ? $pref['type'] : PREF_USER_T; |
166 | 152 | switch ($type) |
167 | 153 | { |
168 | | - case PREF_TOGGLE_T: |
| 154 | + case PREF_TOGGLE_T: |
169 | 155 | $addhtml = $this->getToggle($name); |
170 | 156 | break; |
171 | 157 | |
172 | | - case PREF_INT_T: |
173 | | - case PREF_TEXT_T: |
174 | | - case PREF_PASSWORD_T: |
175 | | - $size = isset($p['size']) && $p['size'] ? "size=\"{$p['size']}\"" : ""; |
176 | | - $caption = isset($p['caption']) && $p['caption'] ? $p['caption'] : wfMsg($name); |
| 158 | + case PREF_INT_T: |
| 159 | + case PREF_TEXT_T: |
| 160 | + case PREF_PASSWORD_T: |
| 161 | + $size = isset($pref['size']) && $pref['size'] ? "size=\"{$pref['size']}\"" : ""; |
| 162 | + $caption = isset($pref['caption']) && $pref['caption'] ? $pref['caption'] : wfMsg($name); |
177 | 163 | if ($type == PREF_PASSWORD_T) |
178 | 164 | $type = "password"; |
179 | 165 | else |
— | — | @@ -180,11 +166,25 @@ |
181 | 167 | $addhtml = "<table>" . |
182 | 168 | $this->addRow("<label for=\"{$name}\">$caption</label>", |
183 | 169 | "<input type=\"$type\" name=\"{$name}\" value=\"{$value}\" $size />") . "</table>" ; |
184 | | - break; |
185 | | - |
186 | | - case PREF_USER_T: |
| 170 | + break; |
| 171 | + case PREF_OPTIONS_T: |
| 172 | + $caption = isset($pref['caption']) && $pref['caption'] ? $pref['caption'] : wfMsg($name); |
| 173 | + $addhtml="$caption <select name=\"$name\" id=\"$name\">"; |
| 174 | + if(isset($pref['options'])) { |
| 175 | + $optval=$wgUser->getOption($name); |
| 176 | + $defaultSet=!empty($optval); |
| 177 | + foreach($pref['options'] as $option=>$optionlabel) { |
| 178 | + $sel=''; |
| 179 | + if(!$defaultSet && !$option) $sel="SELECTED"; |
| 180 | + if($defaultSet && $optval==$option) $sel="SELECTED"; |
| 181 | + $addhtml.="<option value=\"$option\" $sel>$optionlabel</option>"; |
| 182 | + } |
| 183 | + } |
| 184 | + $addhtml.="</select>"; |
| 185 | + break; |
| 186 | + case PREF_USER_T: |
187 | 187 | default: |
188 | | - $addhtml = preg_replace("/@VALUE@/", $value, isset($p['html']) ? $p['html'] : ""); |
| 188 | + $addhtml = preg_replace("/@VALUE@/", $value, isset($pref['html']) ? $pref['html'] : ""); |
189 | 189 | break; |
190 | 190 | } |
191 | 191 | |
Index: trunk/extensions/Wikidata/App.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | $wgHooks['BeforePageDisplay'][]='addWikidataHeader'; |
6 | 6 | $wgHooks['GetEditLinkTrail'][]='addWikidataEditLinkTrail'; |
7 | 7 | $wgHooks['GetHistoryLinkTrail'][]='addHistoryLinkTrail'; |
8 | | -$wgExtensionFunctions[]='initializeWikidataMessages'; |
| 8 | +$wgExtensionFunctions[]='initializeWikidata'; |
9 | 9 | |
10 | 10 | $wgCustomHandlerPath = array('*'=>"{$IP}/extensions/Wikidata/OmegaWiki/"); |
11 | 11 | $wgDefaultClassMids = array(402295); |
— | — | @@ -22,7 +22,6 @@ |
23 | 23 | # successfully. |
24 | 24 | $wdDefaultViewDataSet='uw'; |
25 | 25 | |
26 | | - |
27 | 26 | $wdGroupDefaultView=array(); |
28 | 27 | # Here you can set group defaults. |
29 | 28 | $wdGroupDefaultView['wikidata-omega']='uw'; |
— | — | @@ -42,14 +41,8 @@ |
43 | 42 | require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php"); |
44 | 43 | require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php"); |
45 | 44 | require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialAddCollection.php"); |
| 45 | +require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php"); |
46 | 46 | |
47 | | -$wgExtensionPreferences[]=array( |
48 | | - 'name'=>'ow_uipref_context', |
49 | | - 'section'=>'ow_uiprefs', |
50 | | - 'type'=>PREF_TEXT_T, |
51 | | - 'size'=>10); |
52 | | - |
53 | | -require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php"); |
54 | 47 | function addWikidataHeader() { |
55 | 48 | global $wgOut,$wgScriptPath; |
56 | 49 | $wgOut->addScript("<script type='text/javascript' src='{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.js'></script>"); |
— | — | @@ -75,9 +68,9 @@ |
76 | 69 | } |
77 | 70 | } |
78 | 71 | |
79 | | -function initializeWikidataMessages() { |
| 72 | +function initializeWikidata() { |
80 | 73 | global |
81 | | - $wgMessageCache; |
| 74 | + $wgMessageCache, $wgExtensionPreferences; |
82 | 75 | |
83 | 76 | $wgMessageCache->addMessages( |
84 | 77 | array( |
— | — | @@ -88,11 +81,26 @@ |
89 | 82 | 'ow_datasets' => 'Data-set selection', |
90 | 83 | 'ow_noedit' => 'You are not permitted to edit pages in the dataset "$1". Please see [[Project:Permission policy|our editing policy]].', |
91 | 84 | 'ow_noedit_title' => 'No permission to edit', |
92 | | - 'ow_uipref_context' => 'Default dataset prefix (without underscore)', |
| 85 | + 'ow_uipref_datasets' => 'Default view', |
93 | 86 | 'ow_uiprefs' => 'Wikidata', |
| 87 | + 'ow_none_selected' => '<None selected>', |
94 | 88 | ) |
95 | 89 | ); |
96 | 90 | |
| 91 | + $datasets=wdGetDatasets(); |
| 92 | + $datasetarray['']=wfMsg('ow_none_selected'); |
| 93 | + foreach($datasets as $datasetid=>$dataset) { |
| 94 | + $datasetarray[$datasetid]=$dataset->fetchName(); |
| 95 | + } |
| 96 | + $wgExtensionPreferences[]=array( |
| 97 | + 'name'=>'ow_uipref_datasets', |
| 98 | + 'section'=>'ow_uiprefs', |
| 99 | + 'type'=>PREF_OPTIONS_T, |
| 100 | + 'size'=>10, |
| 101 | + 'options'=>$datasetarray |
| 102 | + ); |
| 103 | + |
| 104 | + |
97 | 105 | } |
98 | 106 | |
99 | 107 | ?> |