Browse Source

Initial commit

master
Claire 2 years ago
parent
commit
065d736f62
  1. 55
      README.md
  2. 156
      action.php
  3. 10
      conf/default.php
  4. 11
      conf/metadata.php
  5. BIN
      dokuwiki-plugin-autostartpage-master.zip
  6. 12
      lang/en/lang.php
  7. 12
      lang/en/settings.php
  8. 7
      plugin.info.txt

55
README.md

@ -1,2 +1,55 @@
# VSCodeProjects
# autostartpage: now with more variables!
This fork of autostartpage introduces two new features:
## Return part of the page ID
Append an index number to `@ID@` to return that segment of the canonical page ID. This follows standard array indexing; the first segment is index `0`.
For example, let's say your page ID is `house:projects:newroof:start`, and you just want to use `newroof` in your start page template. That's the third segment of the namespace (split by `:`), which means its index is `2`.
To return `newroof`, use `@ID2@`.
## Return a regex match from the namespace
This fork adds a new variable, `@NSREGEX/.../`, where `...` is the regex.
For example, let's look at a page ID with a date in it, such as `house:projects:newroof:2022:07:04`.
To return the portion of the ID before the first occurrence of a number (`house:projects:newroof:`), use `@NSREGEX/[a-z:]+/@`
***Note:** Regex support is currently very basic, and does not support capture groups.*
----
### NOTE: This plugin is unmaintained
Maintenance of this project has stagnated, and the plugin is likely incompatible with PHP7 and the latest versions of DokuWiki in it's current state. The project is seeking a maintainer. See the announcement here: https://github.com/rabidaudio/dokuwiki-plugin-autostartpage/issues/6
### autostartpage Plugin for DokuWiki
---------------------------------
Automatically create start pages for new namespaces. Handy if you
use start pages as indexes.
All documentation for this plugin can be found at
http://dokuwiki.org/plugin:autostartpage
If you install this plugin manually, make sure it is installed in
lib/plugins/autostartpage/ - if the folder is named someting else it
will not work!
Please refer to http://www.dokuwiki.org/plugins for additional info
on how to install plugins in DokuWiki.
----
Copyright (C) Charles Knight <charles@rabidaudio,com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See the COPYING file in your DokuWiki folder for details

156
action.php

@ -0,0 +1,156 @@
<?php
/**
* DokuWiki Plugin autostartpage (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Charles Knight <charles@rabidaudio.com>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_autostartpage extends DokuWiki_Action_Plugin {
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler &$controller) {
$controller->register_hook('IO_NAMESPACE_CREATED', 'AFTER', $this, 'autostartpage_handle');
}
/**
* [Custom event handler which performs action]
*
* @author Charles Knight, charles@rabidaudio.com
* @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
* @return void
*/
public function autostartpage_handle(Doku_Event &$event, $param) {
global $conf;
global $INFO;
$templatefile = wikiFN($this->getConf('templatefile'), '', false);
if(@file_exists($templatefile)){
$wikitext=io_readFile($templatefile);
}
$ns=$event->data[0];
$ns_type=$event->data[1];
if($ns_type === "pages" && $wikitext){
$id=$ns.":".$conf['start'];
$file=wikiFN($id);
$silent=$this->getConf('silent');
$ns_sepchar = ":";
$parent=implode($ns_sepchar, array_splice(preg_split("/".preg_quote($ns_sepchar, "/")."/", $ns), 0, -1));
$goodns=preg_replace("/".$conf['sepchar']."/"," ",noNS($ns));
$page=preg_replace("/".$conf['sepchar']."/"," ",noNS($id));
$f=$conf['start'];
/**THESE ARE THE CODES FOR 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
/**PLUS WE ADDED THESE**/
// @!NS@ namespace of the page (with spaces) but with the first character uppercased
// @!!NS@ namespace of the page (with spaces) but with the first character of all words uppercased
// @!!NS!@ namespace of the page (with spaces) 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-%y => Thu 06-12-12
$wikitext=preg_replace("/@NS@/", $ns, $wikitext);
$wikitext=preg_replace("/@!NS@/", ucfirst($goodns), $wikitext);
$wikitext=preg_replace("/@!!NS@/", ucwords($goodns), $wikitext);
$wikitext=preg_replace("/@!!NS!@/", strtoupper($goodns), $wikitext);
$wikitext=preg_replace("/@ID@/", $id, $wikitext);
$wikitext=preg_replace("/@PAGE@/",$page, $wikitext);
$wikitext=preg_replace("/@!PAGE@/",ucfirst($page), $wikitext);
$wikitext=preg_replace("/@!!PAGE@/",$uupage=ucwords($page), $wikitext);
$wikitext=preg_replace("/@!PAGE!@/",strtoupper($page), $wikitext);
$wikitext=preg_replace("/@FILE@/",$f, $wikitext);
$wikitext=preg_replace("/@!FILE@/",ucfirst($f), $wikitext);
$wikitext=preg_replace("/@!FILE!@/",strtoupper($f), $wikitext);
$wikitext=preg_replace("/@USER@/",$_SERVER['REMOTE_USER'], $wikitext);
$wikitext=preg_replace("/@NAME@/",$INFO['userinfo']['name'], $wikitext);
$wikitext=preg_replace("/@MAIL@/",$INFO['userinfo']['mail'], $wikitext);
$wikitext=preg_replace("/@DATE@/",strftime("%D"), $wikitext);
$wikitext=preg_replace("/@PARENT@/",$parent, $wikitext);
/*
$id is the canonical page name with : separators
look for any match like @ID\d+@
*/
$id_rgx = "/@ID(\d+)@/";
preg_match_all($id_rgx,$wikitext,$id_mts);
if(count($id_mts[0])) {
$id_ns = explode(":",$id);
$id_keys = $id_mts[0];
$id_ids = $id_mts[1];
$id_i = 0;
foreach($id_keys as $id_key) {
$id_new = $id_ns[$id_ids[$id_i]];
$wikitext = str_replace($id_key, $id_new, $wikitext);
$id_i++;
}
}
$ns_rgx = "/@NSREGEX(\/.+?\/)@/";
preg_match($ns_rgx,$wikitext,$ns_mts);
if(count($ns_mts[0])) {
$ns_old = $ns_mts[0];
$ns_pat = $ns_mts[1];
preg_match($ns_pat,$id,$ns_mtx);
$ns_new = $ns_mtx[0];
$ns_new = preg_replace("/start$/","",$ns_mtx[0]);
$wikitext = str_replace($ns_old, $ns_new, $wikitext);
}
if(preg_match("/@DATE=(.*)@/", $wikitext, $matches)){
$wikitext=str_replace($matches[0], strftime($matches[1]), $wikitext);
}
if(auth_quickaclcheck($id) >= AUTH_CREATE || $this->getConf('forcecreate')){
if(!@file_exists($file)){
saveWikiText($id, $wikitext, "autostartpage", $minor = false);
$ok = @file_exists($file);
if ($ok and !$silent){
msg($this->getLang('createmsg').' <a href="'.wl($id).'">'.noNS($id).'</a>', 1);
}elseif (!$silent){
msg($this->getLang('failmsg'), -1);
}
}
}else{
msg($this->getLang('failmsg'), -1);
}
}elseif (!$wikitext and !$silent){
msg($this->getLang('templatemissing'));
}
}
}
// vim:ts=4:sw=4:et:

10
conf/default.php

@ -0,0 +1,10 @@
<?php
/**
* Default settings for the searchrevisions plugin
*
* @author Charles Knight <charles@rabidaudio.com>
*/
$conf['templatefile'] = '_autostartpage';
$conf['silent'] = 1;
$conf['forcecreate'] = 0;

11
conf/metadata.php

@ -0,0 +1,11 @@
<?php
/**
* Options for the searchrevisions plugin
*
* @author Charles Knight <charles@rabidaudio.com>
*/
$meta['templatefile'] = array('string');
$meta['silent'] = array('onoff');
$meta['forcecreate'] = array('onoff', '_caution' => 'danger');

BIN
dokuwiki-plugin-autostartpage-master.zip

diff.bin_not_shown

12
lang/en/lang.php

@ -0,0 +1,12 @@
<?php
/**
* Plugin autostartpage: English language file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Charles Knight <charles@rabidaudio.com>
*/
$lang['createmsg'] = 'Autogenerated start page for this namespace:';
$lang['failmsg'] = 'Autogeneration of start page for this namespace failed. You may not have permission to create this page.';
$lang['templatemissing'] = "Warning: Couldn't create start page, template file doesn't exist or could not be read.";

12
lang/en/settings.php

@ -0,0 +1,12 @@
<?php
/**
* Plugin autostartpage: English language file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Charles Knight <charles@rabidaudio.com>
*/
$lang['templatefile'] = "The page to use as a template for new start pages (include namespaces)";
$lang['silent'] = "Uncheck to show message on page creation";
$lang['forcecreate'] = "Create page even if the user lacks permissions to do so (security risk)";

7
plugin.info.txt

@ -0,0 +1,7 @@
base autostartpage
author Charles Knight
email charles@rabidaudio.com
date 2015-01-02
name Automatic startpage plugin
desc add a start page based on a template
url https://github.com/rabidaudio/dokuwiki-plugin-autostartpage
Loading…
Cancel
Save