DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:getraw

getraw Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" yes
  • 2016-06-26 "Elenor Of Tsort" unknown
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

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

Last updated on
2015-06-09

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.

Installation

Create the following file in your base DokuWiki directory:

getRaw.php
<?php
if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
require_once(DOKU_INC.'inc/init.php');
 
$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>/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!
  <code>
     Stuff!
     and things, too!
  </ code>

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:

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

Development

Change Log

  • 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 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: 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

ziothzioth

: 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:

RewriteRule ^(.*).txt$ getRaw.php?id=$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. — NReilinghNReilingh

2015-11-29 07:30

plugin/getraw.txt · Last modified: 2017-11-07 03:43 by 68.186.200.178