[dokuwiki] Re: [patch] allow overriding namespace_templates files

  • From: Robin Getz <rgetz@xxxxxxxxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 11 Oct 2010 10:03:02 -0400

On Sat 2 Oct 2010 13:19, Tom N Harris pondered:
> On 9/30/2010 7:49 PM, Robin Getz wrote:
> >
> > This patch allows local installations to make the namespace template file
> > (normally called _template.txt and __template.txt) whatever they want, and
> > then control who has access to it with the normal ACL mechanisms.
> 
> A while back I started on a plugin to edit templates. It worked well 
> enough, but had some stability and security issues. I'd be happy if 
> someone wants to resurrect it.
> 
> http://whoopdedo.org/doku/wiki#template_manager
> 
> I'm sure it doesn't work in recent versions. 2007? I feel so old...

A small change to common code (15 lines added, 4 lines removed), which uses
the standard ACL mechanisms, seems like a better solution (IMHO).

Here is the final version we deployed, based on end user feedback.


diff --git a/inc/common.php b/inc/common.php
index b944ed7..5ae289f 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -811,21 +811,30 @@ function rawWiki($id,$rev=''){
 function pageTemplate($data){
   $id = $data[0];
   global $conf;
+  global $lang;
   global $INFO;

   $path = dirname(wikiFN($id));

-  if(@file_exists($path.'/_template.txt')){
-    $tpl = io_readFile($path.'/_template.txt');
+  if(isset($conf['nstemplate']) && 
@file_exists($path.'/'.$conf['nstemplate'].'.txt')){
+    if(substr($conf['nstemplate'],0,1) != $conf['sepchar']) {
+      ptln($lang['nstemplate'].'<a href="' . 
wl(getNS($id).'/'.$conf['nstemplate'],'do=edit&rev=',false,'&').'">'.$conf['nstemplate'].'</a>');
+    }
+    $tpl = io_readFile($path.'/'.$conf['nstemplate'].'.txt');
   }else{
     // search upper namespaces for templates
     $len = strlen(rtrim($conf['datadir'],'/'));
+    $ns = getNS($id);
     while (strlen($path) >= $len){
-      if(@file_exists($path.'/__template.txt')){
-        $tpl = io_readFile($path.'/__template.txt');
+      if(isset($conf['inheritednstemplate']) && 
@file_exists($path.'/'.$conf['inheritednstemplate'].'.txt')){
+        if(substr($conf['inheritednstemplate'],0,1) != $conf['sepchar']) {
+          ptln($lang['nstemplate'].'<a href="'. 
wl($ns.'/'.$conf['inheritednstemplate'],'do=edit&rev=',false,'&').'">'.$conf['inheritednstemplate'].'</a>');
+        }
+        $tpl = io_readFile($path.'/'.$conf['inheritednstemplate'].'.txt');
         break;
       }
       $path = substr($path, 0, strrpos($path, '/'));
+      $ns =   substr($ns  , 0, strrpos($ns  , ':'));
     }
   }
   if(!$tpl) return '';


diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index cf5173d..1f424a8 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -132,6 +132,8 @@ $lang['mediaroot']   = 'root';
 $lang['mediaupload'] = 'Upload a file to the current namespace here. To create 
subnamespaces, prepend them to your "Upload as" filename separated by colons.';
 $lang['mediaextchange'] = 'Filextension changed from .%s to .%s!';

+$lang['nstemplate']    = 'Initial content read from template : ';
+
 $lang['reference']   = 'References for';
 $lang['ref_inuse']   = 'The file can\'t be deleted, because it\'s still used 
by the following pages:';
 $lang['ref_hidden']  = 'Some references  are on pages you don\'t have 
permission to read';
-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: