From 065d736f6280c15cd80f5c0bfd81139b7134689a Mon Sep 17 00:00:00 2001 From: Claire Davis Date: Thu, 2 Jun 2022 17:14:49 -0700 Subject: [PATCH] Initial commit --- README.md | 55 +++++++- action.php | 156 +++++++++++++++++++++++ conf/default.php | 10 ++ conf/metadata.php | 11 ++ dokuwiki-plugin-autostartpage-master.zip | Bin 0 -> 5753 bytes lang/en/lang.php | 12 ++ lang/en/settings.php | 12 ++ plugin.info.txt | 7 + 8 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 action.php create mode 100644 conf/default.php create mode 100644 conf/metadata.php create mode 100644 dokuwiki-plugin-autostartpage-master.zip create mode 100644 lang/en/lang.php create mode 100644 lang/en/settings.php create mode 100644 plugin.info.txt diff --git a/README.md b/README.md index 4c1a91d..2ddef1d 100644 --- a/README.md +++ b/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 + +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 \ No newline at end of file diff --git a/action.php b/action.php new file mode 100644 index 0000000..762e791 --- /dev/null +++ b/action.php @@ -0,0 +1,156 @@ + + */ + +// 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').' '.noNS($id).'', 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: diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..039cc7b --- /dev/null +++ b/conf/default.php @@ -0,0 +1,10 @@ + + */ + +$conf['templatefile'] = '_autostartpage'; +$conf['silent'] = 1; +$conf['forcecreate'] = 0; \ No newline at end of file diff --git a/conf/metadata.php b/conf/metadata.php new file mode 100644 index 0000000..8f3078e --- /dev/null +++ b/conf/metadata.php @@ -0,0 +1,11 @@ + + */ + + +$meta['templatefile'] = array('string'); +$meta['silent'] = array('onoff'); +$meta['forcecreate'] = array('onoff', '_caution' => 'danger'); \ No newline at end of file diff --git a/dokuwiki-plugin-autostartpage-master.zip b/dokuwiki-plugin-autostartpage-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..82ed89659ff10b0c8e540832b839d783eced1023 GIT binary patch literal 5753 zcmbtYXH-+$)(r$unh-=lq=^X9Tj(MXq=P`{ASIO0YZ3&d$VH@w-bH%vAiejZAiYXa z#DJm{DFOlyF3;;w?;D?vZ)fat@@vkq=2~aZwU?R_5QhM8x*kG$)c*eS-^X$WfLQN$H^b-T6()&&W(8L5pHk|sKdgf;)n3U%Nj#(KaFO!pXp5%Ow7|sOZzH% z{DrC{;uBE3^m89|N}oqXy<3iJ5ZN8K#k`P#GW@)|3;6o)y1CT4`PZVSA~U&Al7;Z5CbbC63leR$@!v@|(@l6KDvR)o8MHxk>`W;ouYiY?@W!=uR-rb~ zR7OXG3%!oxw|s(((rU_l?tgGCdDJ7I^hCHgf`Wq!>X;;{Gs5TEczUvg1ih1r{R-;?8;!>N=x-_E2n=(76tP?$7yt%Y*3R!Gt zI7(9$UnacF)`dtP5vNXxn&N9t;V#bAcI$5eaf#3FI%{hj@oIg=`|;a}j4kh)!2KvFafFDIL$V%s(l z(iGZQwQKsob0?9!@^DS4-mCQvwhn}oe06((pa12Hfz|!xFeZ6Hq5EQDNmojN(zl*B zmtOWw;@Q&Eq_6IE)lBmv_ENu);>EUA)3M#|?s;}mH>x@{_y$=ZN$b)}*!Ps4~B*hk~E$s5|YK<-;sie~;?eX^_UD5bd| zP|ZawT$HNTI8%JIu)p~NuPTltR3eP2VPPy*qEIQ`eU~ zYnBqEfiqnBj-$UNv+e7qe7t%_8cso5;1iRP5_!q&>QdqiSk^Fy7Cr~IXV=GQvRxue z&K_`!_p?HDg_l&@r!pm++L?L@yT-~+G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uN7%;62LEm%&So84)(&t-E~FdspUae1SpS7K2GU1sObzW#fMLOn zHwueGIl5j@K?*CAz!L7s+l$VY<)8bh3h4l)&cz{q_wF{59}?BJh?`7#_{pUUl#<_K zv4P8kCiSVu6zXoicr<;=_1{aTtTW1z>IV`#hqEIL6C zkC7yip1gw9#ing1R{a%^hb;{g!Q<@CR`9{?k`ULuDWfeW6vOCzjgXoW*2%=>f6sGH zWH?!*XRkk=?tH`k_xa8#=t;ewEaj8^Ta%+-r#;^TI3xM_B76#eMiK!0O_G1P7Jp~? z^&md&9?sUOOtmLk{#GbI_Yyy9^>a6IN^lki0pXtz{9AAFJ(x4eezxuJT*O3w!u78v z{+;aqQjV7RH_3i>$ZyL1N^t6tXX`XI4u3@Oqho&KI8*Fr&-|`f+n;j$;-KFJJLCG< z8oqPMk^G5ZC-MBNQT)vJ^9lH!Z}3FK-zx3@bsnlI;hv1B006?1pFIu$FaQDoZU9V$ qErj9bA}}5>KU~Oym!H=R&d(!a&L_xgCS-0VEDYlj5il1p<^2zrmTcDm literal 0 HcmV?d00001 diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..3a6e63c --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,12 @@ + + */ + +$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."; \ No newline at end of file diff --git a/lang/en/settings.php b/lang/en/settings.php new file mode 100644 index 0000000..acb7a68 --- /dev/null +++ b/lang/en/settings.php @@ -0,0 +1,12 @@ + + */ + +$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)"; \ No newline at end of file diff --git a/plugin.info.txt b/plugin.info.txt new file mode 100644 index 0000000..3d3423f --- /dev/null +++ b/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 \ No newline at end of file