@@ -19,8 +19,31 @@ class action_plugin_newnamespacepermissions extends DokuWiki_Action_Plugin {
1919 */
2020 public function register (Doku_Event_Handler $ controller ) {
2121
22- $ controller ->register_hook ('ACTION_ACT_PREPROCESS ' , 'FIXME ' , $ this , 'handle_action_act_preprocess ' );
23-
22+ $ controller ->register_hook ('ACTION_ACT_PREPROCESS ' , 'BEFORE ' , $ this , 'handleActionActPreprocess ' );
23+ $ controller ->register_hook ('COMMON_WIKIPAGE_SAVE ' , 'BEFORE ' , $ this , 'checkPagesave ' );
24+
25+ }
26+
27+ /**
28+ * [Custom event handler which performs action]
29+ *
30+ * @param Doku_Event $event event object by reference
31+ * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
32+ * handler was registered]
33+ * @return void
34+ */
35+ public function handleActionActPreprocess (Doku_Event $ event , $ param ) {
36+ if (act_clean ($ event ->data ) !== 'edit ' ) {
37+ return ;
38+ }
39+
40+ if ($ this ->isSaveAllowed ()) {
41+ return ;
42+ }
43+
44+ // user tries to create namespace but isn't allowed to do so
45+ $ event ->data = 'show ' ;
46+ msg ($ this ->getLang ('namespace creation not allowed ' ),-1 );
2447 }
2548
2649 /**
@@ -31,8 +54,35 @@ public function register(Doku_Event_Handler $controller) {
3154 * handler was registered]
3255 * @return void
3356 */
57+ public function checkPagesave (Doku_Event $ event , $ param ) {
58+ if ($ this ->isSaveAllowed ()) {
59+ return ;
60+ }
61+
62+ $ event ->preventDefault ();
63+ msg ($ this ->getLang ('namespace creation not allowed ' ), -1 );
64+ msg ($ this ->getLang ('you tried to save ' ) . '<pre> ' . hsc ($ event ->data ['newContent ' ]) . '</pre> ' , 0 );
65+ }
66+
67+ /**
68+ * Check if we're creating a new page in a new namespace and if we're allowed to do so
69+ */
70+ protected function isSaveAllowed () {
71+ global $ ID , $ INPUT , $ USERINFO ;
72+ $ namespaceDir = dirname (wikiFN ($ ID ));
73+ if (file_exists ($ namespaceDir ) && is_dir ($ namespaceDir )) {
74+ return true ;
75+ }
76+
77+ $ allowedToCreateNamespaces = $ this ->getConf ('allow_namespace_creation ' );
78+ $ user = $ INPUT ->server ->str ('REMOTE_USER ' );
79+ $ groups = $ USERINFO ['grps ' ] ?: ['ALL ' ];
80+
81+ if (auth_isMember ($ allowedToCreateNamespaces , $ user , $ groups ) || auth_ismanager (null , null , true )) {
82+ return true ;
83+ }
3484
35- public function handle_action_act_preprocess ( Doku_Event & $ event , $ param ) {
85+ return false ;
3686 }
3787
3888}
0 commit comments