Index: trunk/extensions/Wikidata/App.php |
— | — | @@ -1,11 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | $wgDefaultGoPrefix='Expression:'; |
5 | | -# FIXME - get NS ids from DB (need to put this in a loader hook) |
6 | | -$wgNamespaceProtection[ 16 ] = array( 'editwikidata' ); |
7 | | -$wgNamespaceProtection[ 24 ] = array( 'editwikidata' ); |
8 | | -$wgGroupPermissions['wikidata']['editwikidata']=true; |
9 | | -$wgExtensionFunctions[]='setupDataContextPermissions'; |
10 | 5 | $wgHooks['BeforePageDisplay'][]='addWikidataHeader'; |
11 | 6 | $wgHooks['GetEditLinkTrail'][]='addWikidataEditLinkTrail'; |
12 | 7 | $wgHooks['GetHistoryLinkTrail'][]='addHistoryLinkTrail'; |
— | — | @@ -25,6 +20,17 @@ |
26 | 21 | # successfully. |
27 | 22 | $wdDefaultViewDataSet='uw'; |
28 | 23 | |
| 24 | + |
| 25 | +$wdGroupDefaultView=array(); |
| 26 | +# Here you can set group defaults. |
| 27 | +$wdGroupDefaultView['wikidata-omega']='uw'; |
| 28 | +$wdGroupDefaultView['wikidata-test']='tt'; |
| 29 | + |
| 30 | +# These are the user groups |
| 31 | +$wgGroupPermissions['wikidata-omega']['editwikidata-uw']=true; |
| 32 | +$wgGroupPermissions['wikidata-omega']['editwikidata-tt']=false; |
| 33 | +$wgGroupPermissions['wikidata-test']['editwikidata-tt']=true; |
| 34 | + |
29 | 35 | require_once("{$IP}/extensions/Wikidata/SpecialLanguages.php"); |
30 | 36 | require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialSuggest.php"); |
31 | 37 | require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialSelect.php"); |
— | — | @@ -41,25 +47,21 @@ |
42 | 48 | } |
43 | 49 | |
44 | 50 | function addWikidataEditLinkTrail(&$trail) { |
45 | | - $dc=wdGetDatasetContext(); |
46 | | - $trail="&dataset=$dc"; |
| 51 | + global $wgTitle; |
| 52 | + $ns=Namespace::get($wgTitle->getNamespace()); |
| 53 | + if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') { |
| 54 | + $dc=wdGetDatasetContext(); |
| 55 | + $trail="&dataset=$dc"; |
| 56 | + } |
47 | 57 | } |
48 | 58 | |
49 | 59 | function addHistoryLinkTrail(&$trail) { |
50 | | - $dc=wdGetDatasetContext(); |
51 | | - $trail="&dataset=$dc"; |
52 | | -} |
53 | | - |
54 | | -function setupDataContextPermissions() { |
55 | | - global $wgGroupPermissions; |
56 | | - $dc=wdGetDataSetContext(); |
57 | | - if($dc->getPrefix()=='tt') { |
58 | | - $wgGroupPermissions['wikidata']['editwikidata']=false; |
| 60 | + global $wgTitle; |
| 61 | + $ns=Namespace::get($wgTitle->getNamespace()); |
| 62 | + if($ns->getHandlerClass()=='OmegaWiki' || $ns->getHandlerClass()=='DefinedMeaning') { |
| 63 | + $dc=wdGetDatasetContext(); |
| 64 | + $trail="&dataset=$dc"; |
59 | 65 | } |
60 | | - |
61 | 66 | } |
62 | 67 | |
63 | | -# all DMs will be put in this class by default. |
64 | | - |
65 | | - |
66 | 68 | ?> |
Index: trunk/extensions/Wikidata/Database scripts/Incremental/31 - rename fallback column.sql |
— | — | @@ -1 +1,2 @@ |
2 | 2 | ALTER TABLE wikidata_sets CHANGE set_string set_fallback_name VARCHAR(255); |
| 3 | +INSERT INTO `script_log` (`time`, `script_name`, `comment`) VALUES (NOW(), '31 - rename fallback column.sql', 'rename wikidata_sets.set_string to set_fallback_name'); |
Index: trunk/extensions/Wikidata/Database scripts/Incremental/32 - rename user group.sql |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +UPDATE user_groups SET ug_group='wikidata-omega' where ug_group='wikidata'; |
| 3 | +INSERT INTO `script_log` (`time`, `script_name`, `comment`) VALUES (NOW(), '32 - rename user group.sql', 'standardize group names for multiple data sets'); |
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -20,7 +20,10 @@ |
21 | 21 | protected $showClassicPageTitles = true; // Show classic page titles instead of prettier page titles |
22 | 22 | protected $possiblySynonymousRelationTypeId = 0; // Put this relation type in a special section "Possibly synonymous" |
23 | 23 | |
| 24 | + // Show a panel to select expressions from available data-sets |
| 25 | + protected $showDataSetPanel=true; |
24 | 26 | |
| 27 | + |
25 | 28 | public function __construct() { |
26 | 29 | global |
27 | 30 | $wgMessageCache; |
— | — | @@ -31,7 +34,10 @@ |
32 | 35 | 'ow_uilang_set'=>'Set your preferences', |
33 | 36 | 'ow_save' => 'Save', |
34 | 37 | 'ow_history' => 'History', |
35 | | - 'ow_datasets' => 'Available data-sets', |
| 38 | + 'ow_datasets' => 'Data-set selection', |
| 39 | + 'ow_noedit' => 'You are not permitted to edit pages in the dataset "$1". Please see [[Project:Permission policy|our editing policy]].', |
| 40 | + 'ow_noedit_title' => 'No permission to edit', |
| 41 | + |
36 | 42 | ) |
37 | 43 | ); |
38 | 44 | |
— | — | @@ -95,7 +101,9 @@ |
96 | 102 | |
97 | 103 | if ($wgShowAuthoritativeContributionPanelAtTop) |
98 | 104 | $this->outputAuthoritativeContributionPanel(); |
99 | | - $wgOut->addHTML($this->dataSetSelectBegin()); |
| 105 | + if($this->showDataSetPanel) { |
| 106 | + $wgOut->addHTML($this->getDataSetPanel()); |
| 107 | + } |
100 | 108 | } |
101 | 109 | |
102 | 110 | protected function outputViewFooter() { |
— | — | @@ -105,15 +113,14 @@ |
106 | 114 | if ($wgShowAuthoritativeContributionPanelAtBottom) |
107 | 115 | $this->outputAuthoritativeContributionPanel(); |
108 | 116 | |
109 | | - $wgOut->addHTML($this->dataSetSelectEnd()); |
110 | 117 | $wgOut->addHTML(DefaultEditor::getExpansionCss()); |
111 | 118 | $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>"); |
112 | 119 | } |
113 | 120 | |
114 | 121 | public function view() { |
115 | 122 | global |
116 | | - $wgOut, $wgTitle; |
117 | | - |
| 123 | + $wgOut, $wgTitle, $wgUser; |
| 124 | + |
118 | 125 | $wgOut->enableClientCache(false); |
119 | 126 | |
120 | 127 | $title = $wgTitle->getPrefixedText(); |
— | — | @@ -144,18 +151,13 @@ |
145 | 152 | $this->viewQueryTransactionInformation = new QueryLatestTransactionInformation(); |
146 | 153 | } |
147 | 154 | |
148 | | - protected function dataSetSelectBegin() { |
| 155 | + protected function getDataSetPanel() { |
149 | 156 | global $wgTitle, $wgUser; |
150 | | - $html="<table border=\"0\"><tr valign=\"top\"><td width=\"80%\">"; |
151 | | - return $html; |
152 | | - } |
153 | | - |
154 | | - protected function dataSetSelectEnd() { |
155 | | - global $wgTitle, $wgUser; |
156 | 157 | $dc=wdGetDataSetContext(); |
157 | 158 | $ow_datasets=wfMsg('ow_datasets'); |
158 | | - $html="</td><td width=\"80%\">"; |
159 | | - $html.="<table border=\"0\" width=\"100%\"><tr><th class=\"dataset-panel-heading\">$ow_datasets</th></tr>"; |
| 159 | + |
| 160 | + $html="<div class=\"dataset-panel\">";; |
| 161 | + $html.="<table border=\"0\"><tr><th class=\"dataset-panel-heading\">$ow_datasets</th></tr>"; |
160 | 162 | $dataSets=wdGetDataSets(); |
161 | 163 | $sk=$wgUser->getSkin(); |
162 | 164 | foreach ($dataSets as $dataset) { |
— | — | @@ -167,8 +169,10 @@ |
168 | 170 | $slot = $active ? "$name" : $sk->makeLinkObj($wgTitle,$name,"dataset=$prefix"); |
169 | 171 | $html.="<tr><td class=\"$class\">$slot</td></tr>"; |
170 | 172 | } |
171 | | - $html.="</table></td></tr></table>"; |
| 173 | + $html.="</table>"; |
| 174 | + $html.="</div>"; |
172 | 175 | return $html; |
| 176 | + |
173 | 177 | } |
174 | 178 | |
175 | 179 | protected function save($referenceTransaction) { |
— | — | @@ -189,11 +193,21 @@ |
190 | 194 | $now = wfTimestampNow(); |
191 | 195 | RecentChange::notifyEdit($now, $wgTitle, false, $wgUser, $summary, 0, $now, false, '', 0, 0, 0); |
192 | 196 | } |
193 | | - |
| 197 | + |
| 198 | + /** |
| 199 | + * @return true if permission to edit, false if not |
| 200 | + **/ |
194 | 201 | public function edit() { |
195 | 202 | global |
196 | | - $wgOut, $wgRequest; |
| 203 | + $wgOut, $wgRequest, $wgUser; |
197 | 204 | |
| 205 | + $dc=wdGetDataSetContext(); |
| 206 | + if(!$wgUser->isAllowed('editwikidata-'.$dc)) { |
| 207 | + $wgOut->addWikiText(wfMsg('ow_noedit',$dc->fetchName())); |
| 208 | + $wgOut->setPageTitle(wfMsg('ow_noedit_title')); |
| 209 | + return false; |
| 210 | + } |
| 211 | + |
198 | 212 | if ($wgRequest->getText('save') != '') |
199 | 213 | $this->saveWithinTransaction(); |
200 | 214 | |
— | — | @@ -202,6 +216,7 @@ |
203 | 217 | |
204 | 218 | initializeOmegaWikiAttributes($this->filterLanguageId != 0, false); |
205 | 219 | initializeObjectAttributeEditors($this->filterLanguageId, false, false); |
| 220 | + return true; |
206 | 221 | } |
207 | 222 | |
208 | 223 | public function history() { |
— | — | @@ -305,11 +320,22 @@ |
306 | 321 | **/ |
307 | 322 | function wdGetDataSetContext() { |
308 | 323 | |
309 | | - global $wgRequest, $wdDefaultViewDataSet; |
| 324 | + global $wgRequest, $wdDefaultViewDataSet, $wdGroupDefaultView, $wgUser; |
310 | 325 | $datasets=wdGetDataSets(); |
| 326 | + $groups=$wgUser->getGroups(); |
311 | 327 | $dbs=wfGetDB(DB_SLAVE); |
| 328 | + |
| 329 | + $trydefault=''; |
| 330 | + foreach($groups as $group) { |
| 331 | + if(isset($wdGroupDefaultView[$group])) { |
| 332 | + # We don't know yet if this prefix is valid. |
| 333 | + $trydefault=$wdGroupDefaultView[$group]; |
| 334 | + } |
| 335 | + } |
312 | 336 | if( ($ds=$wgRequest->getText('dataset')) && array_key_exists($ds,$datasets) && $dbs->tableExists($ds."_transactions") ) { |
313 | 337 | return $datasets[$ds]; |
| 338 | + } elseif(!empty($trydefault) && array_key_exists($trydefault,$datasets)) { |
| 339 | + return $datasets[$trydefault]; |
314 | 340 | } else { |
315 | 341 | return $datasets[$wdDefaultViewDataSet]; |
316 | 342 | } |
— | — | @@ -323,7 +349,7 @@ |
324 | 350 | **/ |
325 | 351 | function &wdGetDataSets() { |
326 | 352 | |
327 | | - static $datasets; |
| 353 | + static $datasets, $wgGroupPermissions; |
328 | 354 | if(empty($datasets)) { |
329 | 355 | // Load defs from the DB |
330 | 356 | $dbs =& wfGetDB(DB_SLAVE); |
Index: trunk/extensions/Wikidata/OmegaWiki/tables.css |
— | — | @@ -148,6 +148,11 @@ |
149 | 149 | padding-bottom: 1px; |
150 | 150 | } |
151 | 151 | |
| 152 | +.dataset-panel { |
| 153 | + float:right; |
| 154 | + margin-left:0.5em; |
| 155 | +} |
| 156 | + |
152 | 157 | .dataset-panel-heading { |
153 | 158 | vertical-align: top; |
154 | 159 | font-size:100%; |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | global |
93 | 93 | $wgOut, $wgTitle, $wgUser; |
94 | 94 | |
95 | | - parent::edit(); |
| 95 | + if(!parent::edit()) return false; |
96 | 96 | $this->outputEditHeader(); |
97 | 97 | |
98 | 98 | $spelling = $wgTitle->getText(); |
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | global |
11 | 11 | $wgOut, $wgTitle; |
12 | 12 | |
| 13 | + $this->showDataSetPanel=false; |
13 | 14 | parent::view(); |
14 | 15 | |
15 | 16 | $this->outputViewHeader(); |
— | — | @@ -35,7 +36,7 @@ |
36 | 37 | global |
37 | 38 | $wgOut, $wgTitle; |
38 | 39 | |
39 | | - parent::edit(); |
| 40 | + if(!parent::edit()) return false; |
40 | 41 | |
41 | 42 | $definedMeaningId = $this->getDefinedMeaningIdFromTitle($wgTitle->getText()); |
42 | 43 | |