====== getraw Plugin ====== ---- plugin ---- description: Creates a url to get raw contents of a wiki, with authorization. author : Eli Fenton email : elifenton@this_is_not_a_real_email.fake type : lastupdate : 2021-07-07 compatible : angua, rincewind, hrun, detritus, Frusterick Manners, greebo depends : conflicts : similar : tags : raw, data, text ---- This isn't a standard plugin. Rather, it's a php script that lets you request the source of a wiki page (what you'd see in the editor) with a url. The request is authorized the same way as a normal dokuwiki page. This is a useful utility for plugins that create urls. For example, a syntax plugin might produce an iframe for some other script, which wants to do something with the data of the current page. With this plug-in, you can pass in a url that gives you the data you need. ===== Installation ===== Create the following file in your base DokuWiki directory: str('onlyCode'); $insideTag = $INPUT->str('insideTag'); if (empty($conf['useacl']) || auth_quickaclcheck($ID) >= AUTH_READ) { $file = rawWiki($ID); if ($onlyCode) $file = preg_replace('/[\s\S]*|>)/m', '', preg_replace('/<\/code>[\s\S]*/m', '', $file)); if ($insideTag) $file = preg_replace('/[\s\S]*<' . $insideTag . '[^>]*>/m', '', preg_replace('/<\/' . $insideTag . '>[\s\S]*/m', '', $file)); print $file; } else print "Unauthorized"; ?> ===== Examples/Usage ===== === Simple Case === Let's say you have a wiki page called a:b that looks like this: ==== My Wiki ==== And here's some code! Stuff! and things, too! This url: /doku/getRaw.php?id=a:b will get you all the wiki content. It will not be rendered as HTML. This url: /doku/getRaw.php?onlyCode=true&id=a:b will get you just what's inside the code tags: Stuff! and things, too! === Use to insert JavaScript on your page ==== Create a page called //a:b.js//: alert('hi there!'); If you want the page to be readable, you can wrap it in code tags and use the onlyCode parameter. On another page, you can include your JavaScript like this, if you've enabled html in your settings: ===== Development ===== === Change Log === * **2021-07-07** * With a simple regex added to the code '/[\s\S]*|>)/m' now it accepts tags with languages declared. For example . To make things even more interesting, check the ''.htaccess'' suggestion below. --- [[user>beco|beco]] //2021-07-07 05:40// * **2015-06-19** * Removed some unnecessary code from the script. This plugin is no longer dependent on the version of DokuWiki. Tested with DokuWiki Hrun. * **2011-08-02** * Initial release * **2011-08-03** * Switched from direct file access to the getRaw function. ===== Discussion ===== ====Request for using default plugin structure of DokuWiki ==== You can implement your feature also by creating an action plugin component in your plugin. See also [[devel:action_plugins|development of Action Plugins]] for more details. An useful event for your case is the [[devel:event:ACTION ACT PREPROCESS]]. You handle your do action here, before DokuWiki checks its default do actions. (An quite large example, with error handling, is the dw2pdf plugin. See: https://github.com/splitbrain/dokuwiki-plugin-dw2pdf/blob/master/action.php) If you use the plugin structure, the advantages are: * people can update with the Extension Manager * people can install via the extension manager, without manually copying a file [[user>zioth|zioth]]: Good idea. Next time I revisit this plugin, I might give it a shot. It should be pretty easy. (//2015-07-01//) ==== Usability suggestions ==== For ease of use, you can set up another rewrite rule in your .htaccess so that a user only needs to add .txt to their URL to get the text format. Also, optionally, add .c to the URL to get only the the source inside the code tags. ''RewriteRule ^(.*)\.txt$ getRaw.php?id=$1 [L]''\\ ''RewriteRule ^(.*)\.c$ getRaw.php?id=$1&onlyCode=1 [L]'' Also for readability, throw a ''header('Content-Type: text/plain');'' in line 4, and the browser will know to interpret the newlines instead of eating them like HTML. --- [[user>NReilingh|NReilingh]] //2015-11-29 07:30// --- [[user>beco|beco]] //2021-07-07 05:48//