DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:getraw

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:getraw [2011-09-12 18:09] 24.61.11.143plugin:getraw [2021-07-07 05:54] (current) – [Usability suggestions] dot is not bar-dot beco
Line 1: Line 1:
 ====== getraw Plugin ====== ====== getraw Plugin ======
- 
----- pluginnews ----- 
-headline:     By the same author 
-style:        sameauthor 
------ 
  
 ---- plugin ---- ---- plugin ----
 description: Creates a url to get raw contents of a wiki, with authorization. description: Creates a url to get raw contents of a wiki, with authorization.
 author     : Eli Fenton author     : Eli Fenton
-email      :  +email      : elifenton@this_is_not_a_real_email.fake 
-type       : non-standard +type       :  
-lastupdate : 2011-08-03 +lastupdate : 2021-07-07 
-compatible : 2011-05-25+compatible : angua, rincewind, hrun, detritus, Frusterick Manners, greebo
 depends    :  depends    : 
 conflicts  conflicts 
Line 20: Line 15:
 ---- ----
  
-This isn't a standard plug-in. Rather, it's a php script that lets you request the data 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 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 plug-ins that create urls. For example, a syntax plug-in 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.+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.
  
-This plug-in allows you to request only what's inside of a code block, so you could have a wiki page that describes a block of code, and that could could easily be imported by another script. 
- 
-Another use is to store arbitrary text files in your wiki. For example, if you call a wiki page a:b.js and use this script to fetch the page, it will act like a javascript file. 
  
 ===== Installation ===== ===== Installation =====
Line 33: Line 25:
  
 <code php getRaw.php> <code php getRaw.php>
-$updateVersion = 34; +<?php 
-if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/'); +if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
- +
-if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])){ +
-    $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO'])); +
-} elseif (!empty($_REQUEST['idx'])) { +
-    $ACT = 'index'; +
-} elseif (isset($_REQUEST['do'])) { +
-    $ACT = $_REQUEST['do']; +
-} else { +
-    $ACT = 'show'; +
-}+
 require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/init.php');
  
-$_REQUEST['id'str_replace("\xC2\xAD",'',$_REQUEST['id']); //soft-hyphen +$ID cleanID(getID()); 
-$QUERY trim($_REQUEST['id']); +$onlyCode $INPUT->str('onlyCode'); 
-$ID    getID(); +$insideTag $INPUT->str('insideTag');
-$onlyCode = $_REQUEST['onlyCode'];+
  
 if (empty($conf['useacl']) || auth_quickaclcheck($ID) >= AUTH_READ) { if (empty($conf['useacl']) || auth_quickaclcheck($ID) >= AUTH_READ) {
-    $file = rawWiki($ID); + $file = rawWiki($ID); 
-    if ($onlyCode) + if ($onlyCode) 
-        $file = preg_replace('/[\s\S]*<code>/m', '', preg_replace('/<\/code>[\s\S]*/m', '', $file)); + $file = preg_replace('/[\s\S]*<code( \w>|>)/m', '', preg_replace('/<\/code>[\s\S]*/m', '', $file)); 
-    print $file;+ if ($insideTag) 
 + $file = preg_replace('/[\s\S]*<' . $insideTag . '[^>]*>/m', '', preg_replace('/<\/' . $insideTag . '>[\s\S]*/m', '', $file)); 
 + print $file;
 } }
 else else
-    print "Unauthorized";+ print "Unauthorized"; 
 +?>
 </code> </code>
  
 ===== Examples/Usage ===== ===== Examples/Usage =====
 +
 +=== Simple Case ===
  
 Let's say you have a wiki page called a:b that looks like this: Let's say you have a wiki page called a:b that looks like this:
Line 85: Line 71:
      and things, too!      and things, too!
 </code> </code>
 +
 +
 +=== Use to insert JavaScript on your page ====
 +
 +Create a page called //a:b.js//:
 +<code>
 +alert('hi there!');
 +</code>
 +
 +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:
 +
 +<code>
 +<html><script src="/doku/getRaw.php?id=a:b.js&onlyCode=1"></script></html>
 +</code>
 +
 +
  
  
Line 91: Line 93:
 === Change Log === === Change Log ===
  
 +  * **2021-07-07**
 +    * With a simple regex added to the code <code>'/[\s\S]*<code( \w>|>)/m'</code> now it accepts tags with languages declared. For example <nowiki><code c></nowiki>. 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**   * **2011-08-02**
     * Initial release     * Initial release
Line 96: Line 102:
     * Switched from direct file access to the getRaw function.     * Switched from direct file access to the getRaw function.
  
-=== Known Bugs and Issues === 
  
-This script steals its first few lines of code directly from doku.php, so it may have to be modified to work with some versions of DokuWiki. On the up side, it's easy to open doku.php and re-steal the code.+===== 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. 
  
-===== Discussion =====+(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//
plugin/getraw.1315843766.txt.gz · Last modified: 2011-09-12 18:09 by 24.61.11.143

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