Difference between revisions of "Mediawiki RawFile"

From YobiWiki
Jump to navigation Jump to search
Line 31: Line 31:
 
** Select up to the closure tag
 
** Select up to the closure tag
 
* Must provide the filename to the browser
 
* Must provide the filename to the browser
  +
* Tells the browser NOT to cache the raw?

Revision as of 23:35, 30 March 2008

Introduction

The idea is to be able to download directly a portion of code as a file.
I've numerous code examples in my wiki and I wast an easy way to download them, easier than a copy/paste!

  • It must work with pre, nowiki, js, css, code, source, so let's make it general: take the tag that comes after the parser function we'll create and select data up to the closing tag.

2 parts:

  • the parser magic word that will be converted into a "Save it as <filename>"
  • an extended action=raw that will strip the raw output to keep the desired code

Documentation

Syntax

{{#rawsnippet: myscript.sh}}
Do we need a MIME type?
Transformation:
[{{fullurl:{{PAGENAME}}|action=raw&rawsnippet=myscript.sh}} myscript.sh]
Test: save the following code as {{#rawsnippet: myscript.sh}}

#!/bin/bash

echo 'Hello world!'
exit 0

Hook on Raw

  • Must extract the right paragraph
    • Strip all up to the right rawsnippet: filename tag
    • Find the next tag
    • Select up to the closure tag
  • Must provide the filename to the browser
  • Tells the browser NOT to cache the raw?