r22559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22558‎ | r22559 | r22560 >
Date:10:42, 30 May 2007
Author:erik
Status:old
Tags:
Comment:
clean up wikidata prefs dialog
(add support for options prefs to prefs extension)
Modified paths:
  • /trunk/extensions/Wikidata/AddPrefs.php (modified) (history)
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -309,7 +309,7 @@
310310 $datasets=wdGetDataSets();
311311 $groups=$wgUser->getGroups();
312312 $dbs=wfGetDB(DB_SLAVE);
313 - $pref=$wgUser->getOption('ow_uipref_context');
 313+ $pref=$wgUser->getOption('ow_uipref_datasets');
314314
315315 $trydefault='';
316316 foreach($groups as $group) {
Index: trunk/extensions/Wikidata/AddPrefs.php
@@ -21,27 +21,13 @@
2222 define('PREF_TEXT_T', 3);
2323 define('PREF_PASSWORD_T', 4);
2424 define('PREF_INT_T', 5);
 25+define('PREF_OPTIONS_T', 6);
2526
2627 // each element of the following should be an array that can have keys:
2728 // name, section, type, size, validate, load, save, html, min, max, default
2829 if (!isset($wgExtensionPreferences))
2930 $wgExtensionPreferences = array();
3031
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 -
4632 function wfOverridePreferences(&$list)
4733 {
4834 // we 'override' the default preferences special page with our own
@@ -64,33 +50,33 @@
6551 // one for displaying the form and one for saving the values
6652
6753 function savePreferences()
68 - {
 54+ {
6955 // handle extension prefs first
7056 global $wgUser, $wgRequest;
7157 global $wgExtensionPreferences;
7258
73 - foreach ($wgExtensionPreferences as $p)
 59+ foreach ($wgExtensionPreferences as $pref)
7460 {
75 - $name = isset($p['name']) ? $p['name'] : "";
 61+ $name = isset($pref['name']) ? $pref['name'] : "";
7662 if (! $name)
7763 continue;
7864
7965 $value = $wgRequest->getVal($name);
80 - $type = isset($p['type']) ? $p['type'] : PREF_USER_T;
 66+ $type = isset($pref['type']) ? $pref['type'] : PREF_USER_T;
8167 switch ($type)
8268 {
8369 case PREF_TOGGLE_T:
84 - if (isset($p['save']))
85 - $p['save']($name, $value);
 70+ if (isset($pref['save']))
 71+ $pref['save']($name, $value);
8672 else
8773 $wgUser->setOption($name, $wgRequest->getCheck("wpOp{$name}"));
8874 break;
8975
9076 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);
9581 else
9682 $wgUser->setOption($name, $this->validateIntOrNull($value, $min, $max));
9783 break;
@@ -99,10 +85,10 @@
10086 case PREF_TEXT_T:
10187 case PREF_USER_T:
10288 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);
10793 else
10894 $wgUser->setOption($name, $value);
10995 break;
@@ -124,23 +110,23 @@
125111 $wgOut->clearHTML();
126112
127113 $sections = array();
128 - foreach ($wgExtensionPreferences as $p)
 114+ foreach ($wgExtensionPreferences as $pref)
129115 {
130 - if (! isset($p['section']) || ! $p['section'])
 116+ if (! isset($pref['section']) || ! $pref['section'])
131117 continue;
132 - $section = $p['section'];
 118+ $section = $pref['section'];
133119
134 - $name = isset($p['name']) ? $p['name'] : "";
 120+ $name = isset($pref['name']) ? $pref['name'] : "";
135121 $value = "";
136122 if ($name)
137123 {
138 - if (isset($p['load']))
139 - $value = $p['load']($name);
 124+ if (isset($pref['load']))
 125+ $value = $pref['load']($name);
140126 else
141127 $value = $wgUser->getOption($name);
142128 }
143 - if ($value === '' && isset($p['default']))
144 - $value = $p['default'];
 129+ if ($value === '' && isset($pref['default']))
 130+ $value = $pref['default'];
145131
146132 $sectext = htmlspecialchars(wfMsg($section));
147133 $regex = "/(<fieldset>\s*<legend>\s*" . preg_quote($sectext) .
@@ -161,18 +147,18 @@
162148
163149 }
164150
165 - $type = isset($p['type']) ? $p['type'] : PREF_USER_T;
 151+ $type = isset($pref['type']) ? $pref['type'] : PREF_USER_T;
166152 switch ($type)
167153 {
168 - case PREF_TOGGLE_T:
 154+ case PREF_TOGGLE_T:
169155 $addhtml = $this->getToggle($name);
170156 break;
171157
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);
177163 if ($type == PREF_PASSWORD_T)
178164 $type = "password";
179165 else
@@ -180,11 +166,25 @@
181167 $addhtml = "<table>" .
182168 $this->addRow("<label for=\"{$name}\">$caption</label>",
183169 "<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:
187187 default:
188 - $addhtml = preg_replace("/@VALUE@/", $value, isset($p['html']) ? $p['html'] : "");
 188+ $addhtml = preg_replace("/@VALUE@/", $value, isset($pref['html']) ? $pref['html'] : "");
189189 break;
190190 }
191191
Index: trunk/extensions/Wikidata/App.php
@@ -4,7 +4,7 @@
55 $wgHooks['BeforePageDisplay'][]='addWikidataHeader';
66 $wgHooks['GetEditLinkTrail'][]='addWikidataEditLinkTrail';
77 $wgHooks['GetHistoryLinkTrail'][]='addHistoryLinkTrail';
8 -$wgExtensionFunctions[]='initializeWikidataMessages';
 8+$wgExtensionFunctions[]='initializeWikidata';
99
1010 $wgCustomHandlerPath = array('*'=>"{$IP}/extensions/Wikidata/OmegaWiki/");
1111 $wgDefaultClassMids = array(402295);
@@ -22,7 +22,6 @@
2323 # successfully.
2424 $wdDefaultViewDataSet='uw';
2525
26 -
2726 $wdGroupDefaultView=array();
2827 # Here you can set group defaults.
2928 $wdGroupDefaultView['wikidata-omega']='uw';
@@ -42,14 +41,8 @@
4342 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialNeedsTranslation.php");
4443 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialImportLangNames.php");
4544 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialAddCollection.php");
 45+require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php");
4646
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");
5447 function addWikidataHeader() {
5548 global $wgOut,$wgScriptPath;
5649 $wgOut->addScript("<script type='text/javascript' src='{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.js'></script>");
@@ -75,9 +68,9 @@
7669 }
7770 }
7871
79 -function initializeWikidataMessages() {
 72+function initializeWikidata() {
8073 global
81 - $wgMessageCache;
 74+ $wgMessageCache, $wgExtensionPreferences;
8275
8376 $wgMessageCache->addMessages(
8477 array(
@@ -88,11 +81,26 @@
8982 'ow_datasets' => 'Data-set selection',
9083 'ow_noedit' => 'You are not permitted to edit pages in the dataset "$1". Please see [[Project:Permission policy|our editing policy]].',
9184 'ow_noedit_title' => 'No permission to edit',
92 - 'ow_uipref_context' => 'Default dataset prefix (without underscore)',
 85+ 'ow_uipref_datasets' => 'Default view',
9386 'ow_uiprefs' => 'Wikidata',
 87+ 'ow_none_selected' => '&lt;None selected&gt;',
9488 )
9589 );
9690
 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+
97105 }
98106
99107 ?>