Mediawiki: Difference between revisions

From miki
Jump to navigation Jump to search
(→‎RawFile: Patch to use html class attribute instead of {{#fileanchor}})
Line 101: Line 101:
[http://wiki.yobi.be/wiki/Mediawiki_RawFile RawFile] is an extension made by Philippe Teuwen to allow downloading directly text in <tt>&lt;pre></tt> or <tt>&lt;source></tt> block as a file.
[http://wiki.yobi.be/wiki/Mediawiki_RawFile RawFile] is an extension made by Philippe Teuwen to allow downloading directly text in <tt>&lt;pre></tt> or <tt>&lt;source></tt> block as a file.


'''Patch v0.2 &rarr; v0.3'''
The following page adds an optional parameter to hook <tt><nowiki>{{#filelink}}</nowiki></tt>. With 1 param, the file is fetched from the current page as usual:

The patch below adds an optional parameter to hook <tt><nowiki>{{#filelink}}</nowiki></tt>. With 1 param, the file is fetched from the current page as usual:


<pre>
<pre>
Save [{{#filelink: fstab }} this file] in your <tt>/etc</tt> directory.
Save [{{#filelink: fstab}} this file] in your <tt>/etc</tt> directory.
</pre>
</pre>


Line 113: Line 115:
</pre>
</pre>


<source lang="diff">
{{hiddenSourceFile||RawFile-v0.2.patch|<source lang="diff" class="RawFile-v0.2.patch">
--- original/RawFile.php 2009-09-21 16:20:51.000000000 +0200
--- original/RawFile.php 2009-09-21 16:20:51.000000000 +0200
+++ patched/RawFile.php 2009-09-21 18:07:06.000000000 +0200
+++ patched/RawFile.php 2009-09-21 18:07:06.000000000 +0200
Line 132: Line 134:
return '';
return '';
</source>
</source>
}}

'''Patch v0.3 &rarr; v0.?'''

This patch allows for specifying the file anchor using an html '''class''' attribute instead of using <code><nowiki>{{#fileanchor}}</nowiki></code>. For instance:

<pre>
Save [{{#filelink: example.sh}} this file] in your home directory.
<source lang="bash" class="example.sh">
#! /bin/bash

echo 'Hello, World!'
</source>
</pre>

{{hiddenSourceFile||RawFile-v0.3.patch|<source lang="diff" class="RawFile-v0.3.patch">
--- RawFile.php.original 2009-11-16 22:07:18.000000000 +0100
+++ RawFile.php 2009-11-16 22:28:10.000000000 +0100
@@ -40,16 +40,21 @@
header("Expires: 0");
header("Pragma: no-cache");
header("Cache-Control: no-store");
- $maskedtext=preg_replace_callback('/<nowiki>(.*?)<\/nowiki>/',
+ $maskedtext=preg_replace_callback('/<nowiki>(.*?)<\/nowiki>/s',
create_function(
'$matches',
'return ereg_replace(".","X",$matches[0]);'
),
$text);
+ $classAnchor=false;
if (preg_match_all('/{{#fileanchor: *'.$filename.' *}}/i', $maskedtext, $matches, PREG_OFFSET_CAPTURE))
$offsets=$matches[0];
else if (preg_match_all('/{{#file: *'.$filename.' *}}/i', $maskedtext, $matches, PREG_OFFSET_CAPTURE))
$offsets=array($matches[0][0]);
+ else if (preg_match_all('/<[^>]* class *= *"'.$filename.'"[^>]*>/i', $maskedtext, $matches, PREG_OFFSET_CAPTURE)) {
+ $offsets=$matches[0];
+ $classAnchor=true;
+ }
else
// We didn't find our anchor, let's output all the raw...
return true;
@@ -58,7 +63,8 @@
$text='';
foreach ($offsets as $offset) {
$out = substr($textorig, $offset[1]);
- $out = substr($out, strpos($out, '<'));
+ if (!$classAnchor)
+ $out = substr($out, strpos($out, '<'));
if (!preg_match('/^<([^> ]+)/', $out, $matches))
return true;
$key = $matches[1];
</source>
}}

Revision as of 22:02, 16 November 2009

Hints and Tips

Purge wiki page cache
When changing templates, purge the browser & mediawiki cache. To purge the cache of a single page, add &action=purge to the URL (see [1] for more)

Keyboard shortcuts

  • Reference page in wikipedia
  • Page explaining how to change keyboard shortcut using user custom stylesheet.
  • Most frequently-used HTML access keys (default access-key shortcut is alt+shift for Firefox and shift+Esc for Opera):
Action Key
accesskey-edit e
accesskey-preview p
accesskey-save s
accesskey-search f

Access Restriction

See these pages for implementing access restriction in MediaWiki:

  • A page that implement per-page access restriction [2].
  • Another way to hide pages [3].
  • Yet another extension [4].
  • Security problem with access restriction extension:
  • Some information on how to create custom namespaces [7].

Miscellaneous

  • Page Special:Version produces a complete list of all extensions installed on the wiki.

Extensions

SyntaxHighlight GeSHi

This extension adds the <source> tag to present formatted source code. See official page.

Restoring 1.0.7.# output - solving <pre> formatting problem

  • Since at least version r24298 (July 21, 2007) (with GeSHi version 1.0.8), <source> tag does not match usual formatting applied for <pre> tags. This is because the extension applies by default the new GeSHi header style GESHI_HEADER_PRE_VALID. The following patch allows to restore the old formatting when there is no attribute line. It also introduces a new option valid to attribute enclose to force application of header style GESHI_HEADER_PRE_VALID
--- SyntaxHighlight_GeSHi.class.php.old 2008-09-07 23:24:37.000000000 +0200
+++ SyntaxHighlight_GeSHi.class.php     2008-09-07 23:33:15.000000000 +0200
@@ -39,7 +39,7 @@
                // "Enclose" parameter
                if ( isset( $args['enclose'] ) && $args['enclose'] == 'div' ) {
                        $enclose = GESHI_HEADER_DIV;
-               } elseif ( defined('GESHI_HEADER_PRE_VALID') ) {
+               } elseif ( (isset( $args['line'] ) || isset( $args['enclose'] ) && $args['enclose'] == 'valid' ) && defined('GESHI_HEADER_PRE_VALID') ) {
                        // Since version 1.0.8 geshi can produce valid pre, but we need to check for it
                        $enclose = GESHI_HEADER_PRE_VALID;
                } elseif( isset( $args['line'] ) ) {
  • Example: the following code
After the following command, <source lang="bash" enclose="valid">  % cat ~/hello.c</source> you'll get the following output
<source lang="c">
#include <stdio.h>
int main(int,int)
{
  printf("Hello, World!\n");
  return 0;
}
</source>

gives:

After the following command,
  % cat ~/hello.c
you'll get the following output
#include <stdio.h>
int main(int,int)
{
  printf("Hello, World!\n");
  return 0;
}
  • Another solution is discussed here. The proposed solution is to edit file "SyntaxHighlight_GeSHi.class.php". Go to line 192, which should look like
$css[] = ".source-$lang {line-height: normal;}";

Change this to

$css[] = ".source-$lang {padding: 1em; border: 1px dashed #2f6fab; color: black; background-color: #f9f9f9; line-height: 1.1em;}";

and you have restored the pre css formatting.

RawFile

RawFile is an extension made by Philippe Teuwen to allow downloading directly text in <pre> or <source> block as a file.

Patch v0.2 → v0.3

The patch below adds an optional parameter to hook {{#filelink}}. With 1 param, the file is fetched from the current page as usual:

Save [{{#filelink: fstab}} this file] in your <tt>/etc</tt> directory.

With 2 param, the 2nd param is telling which page to fetch the file from:

Save [{{#filelink: fstab|Config files - fstab}} this file] in your <tt>/etc</tt> directory.

Patch v0.3 → v0.?

This patch allows for specifying the file anchor using an html class attribute instead of using {{#fileanchor}}. For instance:

Save [{{#filelink: example.sh}} this file] in your home directory.
<source lang="bash" class="example.sh">
#! /bin/bash

echo 'Hello, World!'
</source>