It's better when it's simple

User Tools

Site Tools


getraw Plugin

Compatible with DokuWiki

angua, rincewind, hrun, detritus, Frusterick Manners, greebo

plugin Creates a url to get raw contents of a wiki, with authorization.

Last updated on

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with data, raw, 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.


Create the following file in your base DokuWiki directory:

if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
$ID = cleanID(getID());
$onlyCode = $INPUT->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]*<code( \w>|>)/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;
	print "Unauthorized";


Simple Case

Let's say you have a wiki page called a:b that looks like this:

  ==== My Wiki ====
  And here's some code!
     and things, too!
  </ code>

This url:


will get you all the wiki content. It will not be rendered as HTML.

This url:


will get you just what's inside the code tags:

     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:

<html><script src="/doku/getRaw.php?id=a:b.js&onlyCode=1"></script></html>


Change Log

  • 2021-07-07
    • With a simple regex added to the code
      '/[\s\S]*<code( \w>|>)/m'

      now it accepts tags with languages declared. For example <code c>. To make things even more interesting, check the .htaccess suggestion below. — 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.


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 development of Action Plugins for more details.

An useful event for your case is the 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:

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

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. — NReilingh 2015-11-29 07:30beco 2021-07-07 05:48

plugin/getraw.txt · Last modified: 2021-07-07 05:54 by beco

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki