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 [2015-07-01 21:05] – [Request for using default plugin structure of DokuWiki] ziothplugin:getraw [2021-07-07 05:54] (current) – [Usability suggestions] dot is not bar-dot beco
Line 6: Line 6:
 email      : elifenton@this_is_not_a_real_email.fake email      : elifenton@this_is_not_a_real_email.fake
 type       :  type       : 
-lastupdate : 2015-06-09 +lastupdate : 2021-07-07 
-compatible : angua, rincewind, hrun+compatible : angua, rincewind, hrun, detritus, Frusterick Manners, greebo
 depends    :  depends    : 
 conflicts  conflicts 
Line 15: Line 15:
 ---- ----
  
-This isn't a standard plug-in. 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 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 39: Line 36:
  $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));
  if ($insideTag)  if ($insideTag)
  $file = preg_replace('/[\s\S]*<' . $insideTag . '[^>]*>/m', '', preg_replace('/<\/' . $insideTag . '>[\s\S]*/m', '', $file));  $file = preg_replace('/[\s\S]*<' . $insideTag . '[^>]*>/m', '', preg_replace('/<\/' . $insideTag . '>[\s\S]*/m', '', $file));
Line 46: Line 43:
 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 71: 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 77: 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**   * **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.     * Removed some unnecessary code from the script. This plugin is no longer dependent on the version of DokuWiki. Tested with DokuWiki Hrun.
Line 99: Line 117:
  
 [[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//) [[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.1435777544.txt.gz · Last modified: 2015-07-01 21:05 by zioth

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