r23799 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23798‎ | r23799 | r23800 >
Date:20:53, 6 July 2007
Author:erik
Status:old
Tags:
Comment:
- consistently add dataset to Special:Suggest selectors
- basic permission check on concept mapping
- doc&code quality tweaking
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/forms.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -48,7 +48,6 @@
4949 global $wgOut,$wgScriptPath;
5050 $dc=wdGetDataSetContext();
5151 $wgOut->addScript("<script type='text/javascript' src='{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.js'></script>");
52 - $wgOut->addScript("<script type='text/javascript'>var dataset='$dc';</script>");
5352 $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/suggest.css"));
5453 $wgOut->addLink(array('rel'=>'stylesheet','type'=>'text/css','media'=>'screen, projection','href'=>"{$wgScriptPath}/extensions/Wikidata/OmegaWiki/tables.css"));
5554 return true;
Index: trunk/extensions/Wikidata/OmegaWiki/forms.php
@@ -52,10 +52,25 @@
5353 return $result . '</select>';
5454 }
5555
56 -function getSuggest($name, $query, $parameters = array(), $value=0, $label='', $displayLabelColumns = array(0)) {
 56+/**
 57+ *
 58+ * Returns HTML for an autocompleted form field.
 59+ *
 60+ * @param String unique identifier for this form field
 61+ * @param String type of query to run
 62+ * @param Integer Default value
 63+ * @param String How default value will be shown
 64+ * @param Array Override column titles
 65+ * @param DataSet Override standard dataset
 66+ *
 67+*/
 68+function getSuggest($name, $query, $parameters = array(), $value=0, $label='', $displayLabelColumns = array(0), DataSet $dc=null) {
5769 global
5870 $wgScriptPath;
5971
 72+ if(is_null($dc)) {
 73+ $dc=wdGetDataSetContext();
 74+ }
6075 if ($label == "")
6176 $label = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
6277
@@ -64,7 +79,8 @@
6580 '<input type="hidden" id="'. $name .'-suggest-query" value="'. $query .'"/>' .
6681 '<input type="hidden" id="'. $name .'-suggest-offset" value="0"/>' .
6782 '<input type="hidden" id="'. $name .'-suggest-label-columns" value="'. implode(', ', $displayLabelColumns) .'"/>' .
68 - '<input type="hidden" id="'. $name .'" name="'. $name .'" value="'. $value .'"/>';
 83+ '<input type="hidden" id="'. $name .'" name="'. $name .'" value="'. $value .'"/>' .
 84+ '<input type="hidden" id="'.$name.'-suggest-dataset" value="'.$dc.'"/>';
6985
7086 foreach ($parameters as $parameter => $parameterValue)
7187 $result .=
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -38,13 +38,13 @@
3939
4040
4141
42 -function updateSuggestions(suggestPrefix, dataSetOverride) {
 42+function updateSuggestions(suggestPrefix) {
4343 var http = getHTTPObject();
4444 var table = document.getElementById(suggestPrefix + "table");
4545 var suggestQuery = document.getElementById(suggestPrefix + "query").value;
4646 var suggestOffset = document.getElementById(suggestPrefix + "offset").value;
47 - var currentDataSet = dataset;
48 -
 47+ var dataSet = document.getElementById(suggestPrefix + "dataset").value;
 48+
4949 suggestText = document.getElementById(suggestPrefix + "text");
5050 suggestText.className = "suggest-loading";
5151
@@ -63,7 +63,7 @@
6464 '&prefix=' + encodeURI(suggestPrefix) +
6565 '&query=' + encodeURI(suggestQuery) +
6666 '&offset=' + encodeURI(suggestOffset) +
67 - '&dataset='+currentDataSet;
 67+ '&dataset='+dataSet;
6868
6969 if((suggestAttributesLevel != null) && (suggestObjectId != null))
7070 URL =
@@ -190,11 +190,10 @@
191191 stopEventHandling(event);
192192 }
193193
194 -function suggestNextClicked(event, suggestNext) {
 194+function suggestNextClicked(event, suggestNext, dataSetOverride) {
195195 var suggestPrefix = getSuggestPrefix(suggestNext, 'next');
196196 var suggestOffset = document.getElementById(suggestPrefix + 'offset');
197197 suggestOffset.value = parseInt(suggestOffset.value) + 10;
198 - updateSuggestions(suggestPrefix);
199198 stopEventHandling(event);
200199 }
201200
@@ -202,7 +201,6 @@
203202 var suggestPrefix = getSuggestPrefix(suggestPrevious, 'previous');
204203 var suggestOffset = document.getElementById(suggestPrefix + 'offset');
205204 suggestOffset.value = Math.max(parseInt(suggestOffset.value) - 10, 0);
206 - updateSuggestions(suggestPrefix);
207205 stopEventHandling(event);
208206 }
209207
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php
@@ -33,8 +33,13 @@
3434 }
3535
3636 function execute( $par ) {
37 - global $wgOut, $wgRequest, $wgTitle, $wgUser;
 37+ global $wgOut, $wgRequest, $wgTitle, $wgUser, $wdTermDBDataSet;
3838 $wgOut->setPageTitle("ConceptMapping");
 39+
 40+ if(!$wgUser->isAllowed('editwikidata-'.$wdTermDBDataSet)) {
 41+ $wgOut->addHTML("Permission denied.");
 42+ return false;
 43+ }
3944 $action=$wgRequest->getText('action');
4045 if(!$action) {
4146 $this->ui();
@@ -74,9 +79,9 @@
7580 if($rq[$set]) {
7681 $dmModel=new DefinedMeaningModel($rq[$set],null,$setObject);
7782 $defaultSel=$dmModel->getSyntransByLanguageCode($lang);
78 - $options[$setObject->fetchName()]=getSuggest("set_$set", 'defined-meaning',array(), $rq[$set], $defaultSel);
 83+ $options[$setObject->fetchName()]=getSuggest("set_$set", 'defined-meaning',array(), $rq[$set], $defaultSel, array(0), $setObject);
7984 } else {
80 - $options[$setObject->fetchName()]=getSuggest("set_$set", 'defined-meaning');
 85+ $options[$setObject->fetchName()]=getSuggest("set_$set", 'defined-meaning', array(), null, null, array(0), $setObject);
8186 }
8287
8388 }

Status & tagging log