r22422 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22421‎ | r22422 | r22423 >
Date:10:31, 25 May 2007
Author:erik
Status:old
Tags:
Comment:
support group-specific dataset permissions
support group-specific default dataset views
rename script for existing wikidata group
change dataset panel layout
add missing script comment
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/Database+scripts/Incremental/31+-+rename+fallback+column.sql (modified) (history)
  • /trunk/extensions/Wikidata/Database+scripts/Incremental/32+-+rename+user+group.sql (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/tables.css (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -1,11 +1,6 @@
22 <?php
33
44 $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';
105 $wgHooks['BeforePageDisplay'][]='addWikidataHeader';
116 $wgHooks['GetEditLinkTrail'][]='addWikidataEditLinkTrail';
127 $wgHooks['GetHistoryLinkTrail'][]='addHistoryLinkTrail';
@@ -25,6 +20,17 @@
2621 # successfully.
2722 $wdDefaultViewDataSet='uw';
2823
 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+
2935 require_once("{$IP}/extensions/Wikidata/SpecialLanguages.php");
3036 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialSuggest.php");
3137 require_once("{$IP}/extensions/Wikidata/OmegaWiki/SpecialSelect.php");
@@ -41,25 +47,21 @@
4248 }
4349
4450 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+ }
4757 }
4858
4959 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";
5965 }
60 -
6166 }
6267
63 -# all DMs will be put in this class by default.
64 -
65 -
6668 ?>
Index: trunk/extensions/Wikidata/Database scripts/Incremental/31 - rename fallback column.sql
@@ -1 +1,2 @@
22 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 @@
2121 protected $showClassicPageTitles = true; // Show classic page titles instead of prettier page titles
2222 protected $possiblySynonymousRelationTypeId = 0; // Put this relation type in a special section "Possibly synonymous"
2323
 24+ // Show a panel to select expressions from available data-sets
 25+ protected $showDataSetPanel=true;
2426
 27+
2528 public function __construct() {
2629 global
2730 $wgMessageCache;
@@ -31,7 +34,10 @@
3235 'ow_uilang_set'=>'Set your preferences',
3336 'ow_save' => 'Save',
3437 '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+
3642 )
3743 );
3844
@@ -95,7 +101,9 @@
96102
97103 if ($wgShowAuthoritativeContributionPanelAtTop)
98104 $this->outputAuthoritativeContributionPanel();
99 - $wgOut->addHTML($this->dataSetSelectBegin());
 105+ if($this->showDataSetPanel) {
 106+ $wgOut->addHTML($this->getDataSetPanel());
 107+ }
100108 }
101109
102110 protected function outputViewFooter() {
@@ -105,15 +113,14 @@
106114 if ($wgShowAuthoritativeContributionPanelAtBottom)
107115 $this->outputAuthoritativeContributionPanel();
108116
109 - $wgOut->addHTML($this->dataSetSelectEnd());
110117 $wgOut->addHTML(DefaultEditor::getExpansionCss());
111118 $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
112119 }
113120
114121 public function view() {
115122 global
116 - $wgOut, $wgTitle;
117 -
 123+ $wgOut, $wgTitle, $wgUser;
 124+
118125 $wgOut->enableClientCache(false);
119126
120127 $title = $wgTitle->getPrefixedText();
@@ -144,18 +151,13 @@
145152 $this->viewQueryTransactionInformation = new QueryLatestTransactionInformation();
146153 }
147154
148 - protected function dataSetSelectBegin() {
 155+ protected function getDataSetPanel() {
149156 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;
156157 $dc=wdGetDataSetContext();
157158 $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>";
160162 $dataSets=wdGetDataSets();
161163 $sk=$wgUser->getSkin();
162164 foreach ($dataSets as $dataset) {
@@ -167,8 +169,10 @@
168170 $slot = $active ? "$name" : $sk->makeLinkObj($wgTitle,$name,"dataset=$prefix");
169171 $html.="<tr><td class=\"$class\">$slot</td></tr>";
170172 }
171 - $html.="</table></td></tr></table>";
 173+ $html.="</table>";
 174+ $html.="</div>";
172175 return $html;
 176+
173177 }
174178
175179 protected function save($referenceTransaction) {
@@ -189,11 +193,21 @@
190194 $now = wfTimestampNow();
191195 RecentChange::notifyEdit($now, $wgTitle, false, $wgUser, $summary, 0, $now, false, '', 0, 0, 0);
192196 }
193 -
 197+
 198+ /**
 199+ * @return true if permission to edit, false if not
 200+ **/
194201 public function edit() {
195202 global
196 - $wgOut, $wgRequest;
 203+ $wgOut, $wgRequest, $wgUser;
197204
 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+
198212 if ($wgRequest->getText('save') != '')
199213 $this->saveWithinTransaction();
200214
@@ -202,6 +216,7 @@
203217
204218 initializeOmegaWikiAttributes($this->filterLanguageId != 0, false);
205219 initializeObjectAttributeEditors($this->filterLanguageId, false, false);
 220+ return true;
206221 }
207222
208223 public function history() {
@@ -305,11 +320,22 @@
306321 **/
307322 function wdGetDataSetContext() {
308323
309 - global $wgRequest, $wdDefaultViewDataSet;
 324+ global $wgRequest, $wdDefaultViewDataSet, $wdGroupDefaultView, $wgUser;
310325 $datasets=wdGetDataSets();
 326+ $groups=$wgUser->getGroups();
311327 $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+ }
312336 if( ($ds=$wgRequest->getText('dataset')) && array_key_exists($ds,$datasets) && $dbs->tableExists($ds."_transactions") ) {
313337 return $datasets[$ds];
 338+ } elseif(!empty($trydefault) && array_key_exists($trydefault,$datasets)) {
 339+ return $datasets[$trydefault];
314340 } else {
315341 return $datasets[$wdDefaultViewDataSet];
316342 }
@@ -323,7 +349,7 @@
324350 **/
325351 function &wdGetDataSets() {
326352
327 - static $datasets;
 353+ static $datasets, $wgGroupPermissions;
328354 if(empty($datasets)) {
329355 // Load defs from the DB
330356 $dbs =& wfGetDB(DB_SLAVE);
Index: trunk/extensions/Wikidata/OmegaWiki/tables.css
@@ -148,6 +148,11 @@
149149 padding-bottom: 1px;
150150 }
151151
 152+.dataset-panel {
 153+ float:right;
 154+ margin-left:0.5em;
 155+}
 156+
152157 .dataset-panel-heading {
153158 vertical-align: top;
154159 font-size:100%;
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php
@@ -91,7 +91,7 @@
9292 global
9393 $wgOut, $wgTitle, $wgUser;
9494
95 - parent::edit();
 95+ if(!parent::edit()) return false;
9696 $this->outputEditHeader();
9797
9898 $spelling = $wgTitle->getText();
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -9,6 +9,7 @@
1010 global
1111 $wgOut, $wgTitle;
1212
 13+ $this->showDataSetPanel=false;
1314 parent::view();
1415
1516 $this->outputViewHeader();
@@ -35,7 +36,7 @@
3637 global
3738 $wgOut, $wgTitle;
3839
39 - parent::edit();
 40+ if(!parent::edit()) return false;
4041
4142 $definedMeaningId = $this->getDefinedMeaningIdFromTitle($wgTitle->getText());
4243