DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:autostartpage

AutoStartPage Plugin

Compatible with DokuWiki

  • 2018-04-22 "Greebo" unknown
  • 2017-02-19 "Frusterick Manners" yes
  • 2016-06-26 "Elenor Of Tsort" yes
  • 2015-08-10 "Detritus" yes

plugin Automatically create namespace start pages from a template.

Last updated on
2015-01-02
Provides
Action
Repository
Source

Tagged with create, namespace, page, start, template

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Usage

Simply create a template file to use for your start pages. You can place an underscore before the name of the file so that it doesn't show up in the sitemap, but you will have to create the text file on the server manually (see Namespace Templates for more). Whenever a new namespace is created, a new start page for that namespace will be created as well. If you create a start page in a new namespace, the automatic one will be overwritten by yours. Generally this will be useful if you want your start pages to be navigational to other pages in the namespace (in which case, look at dir or pageindex to generate the content dynamically).

This functions a little differently from page templates, as it actually creates the page instead of autofilling the edit window when you go to create the page. Thus, the two features should be compatible.

Note that creating top-level pages doesn't call IO_NAMESPACE_CREATED, even if no other pages exist. You'll have to make the top-level one by hand.

A note about permissions

As of the most recent update, these pages are created by the user who created the first page in the namespace. If the user does not have permissions to create the start page, it will not be created. This can be overridden in the settings, but introduces a security risk.

Syntax

Template files are standard wiki syntax and can use (roughly) the same replacement patterns as namespace templates:

@ID@ full ID of the page
@NS@ namespace of the page
@PAGE@ page name (ID without namespace and underscores replaced by spaces)
@!PAGE@ same as above but with the first character uppercased
@!!PAGE@ same as above but with the first character of all words uppercased
@!PAGE!@ same as above but with all characters uppercased
@FILE@ page name (ID without namespace, underscores kept as is)
@!FILE@ same as above but with the first character uppercased
@!FILE!@ same as above but with all characters uppercased
@USER@ ID of user who is creating the page
@NAME@ name of user who is creating the page
@MAIL@ mail address of user who is creating the page
@DATE@ date and time when edit session started

I've added a few more custom ones:

@!NS@ namespace of the page (with spaces) but with the first character uppercased
@!!NS@ same as above but with the first character of all words uppercased
@!!NS!@ same as above but with all characters uppercased
@PARENT@ the name of the parent namespace. Blank if parent is top
@DATE=STRFTIME@ Where STRFTIME is a strftime() configure string of page creation time, e.g. %a %d-%m-%yThu 06-12-12

Configuration

There are two configuration options:

  1. Ordered List Itemtemplatefile points to the file to use as the template for new start pages.
  2. silent hides alerts when the page is created. Uncheck for error messages if something is not working.

Change Log

  • 2013-07-19
    • Initial release
  • 2015-01-02
    • New shortcut: @DATE=STRFTIME@
    • New shortcut: @PARENT@
    • Pages now are created as user
    • Added force create option
    • Fixed constantly outdated issue
    • Other minor fixes

ToDo/Wish List

  • I plan to add support for strftime dates like namespace templates done
  • I also want to be able to have different templates for different namespaces
  • Could you also add support for the parent namespace? That way you could make a navigation page that automatically links to the previous namespace. done

Discussion

Registers as IO_NAMESPACE_CREATED.

At first: Thanks for your plugin =) It helped me a lot.
I've seen you have written, that we should trigger io_wikipage_write if we can.
How about setting your function “AFTER” IO_NAMESPACE_CREATED instead of “BEFORE”?
Then we could use the function
saveWikiText($id, $wikitext, "autostartpage", $minor = false); 

> which triggers that event…
Greetings — StefanLStefanL

2014/01/21 09:16

Hi Stefan, thanks for the suggestion. I'm not sure why I didn't do that in the first place.
It's been fixed now, and the docs have been updated. Cheers, charlesjuliankcharlesjuliank

2015/01/02 11:27

On “frusterick manners”, you have to create 2 new namespaces for this plugin to work. But after that, it's fine — redge76redge76

2018-01-15 09:53

excellent - very useful plugin I notice you comment that one of the todo's is the ability to have different start page templates for different places.

well - I wanted that too - so made a few minor amendments - code is hopefully self explanatory - happy if you want to include these changes or if others want to do a similar mod - I am just using a local edit of the plugin on my system - works nice! (also removed a couple of &s so that it would work on php 7.1)

.
.
.
.
  public function autostartpage_handle(Doku_Event $event, $param) {
      global $conf;
      global $INFO;
      $ns=$event->data[0];       //namespace that has just been created
      
      $passed_template = $this->getConf('templatefile');   // the template that is set in the configuration
      $templatefile = wikiFN($this->getConf('templatefile'), '', false);   //get the filename for the template
      
      if (substr_count($passed_template, ":") === 0) {        //no namespace specified in configuration so climb the hierarchy        
/*
This if statement checks to see whether the start page template set in the configuration manager includes a ":"
If it does then this is an absolute startpage template to be used for all new namespaces and the logic progresses as per original plugin
If there is no ":" then the stored value is taken to be the startpage template and is sought within the current namespace structure
first the newly created namespace's parent is checked for a template - if found that is used and we break to the next block of code
if the parent doesnt contain a template then the grandparent is checked by moving the current parent to the temp namespace name
and we go round the loop again. Processing continues till we hit the top level folder.
*/
  		$instance = substr_count($ns, ":") ;                 // how many levels of namespace?
	    $ns_sepchar = ":";
		$ns_temp = $ns;
          
          do {
            $parent=implode($ns_sepchar, array_splice(preg_split("/".preg_quote($ns_sepchar, "/")."/", $ns_temp), 0, -1));
  	        $parent_template = $parent .":"  .$passed_template;        
      	    $parent_templatefile = wikiFN($parent_template, '', false);   //get the filename for the parent template       
          	if(@file_exists($parent_templatefile)){
          		$wikitext=io_readFile($parent_templatefile);
          		break;
      		}  else {
      			$ns_temp = $parent ;
      			--$instance;
      		}
      	}
      	while ($instance > 0);
      	
      } else { 
      	if(@file_exists($templatefile)){
          		$wikitext=io_readFile($templatefile);
      	}
	}
/*
    NO FURTHER CHANGES AFTER HERE
*/
      $ns_type=$event->data[1];
      if($ns_type === "pages" && $wikitext){
plugin/autostartpage.txt · Last modified: 2018-09-24 08:23 by alimat