Extension:LocalFileSystem
From MediaWiki.org
|
LocalFileSystem Release status: experimental |
|
|---|---|
| Implementation | Data extraction, Special page |
| Description | Displays files of one directory of the local file system |
| Author(s) | Florian Konnertz (groovehunter Talk) |
| Version | 0.1 (08/02/20) |
| MediaWiki | 1.8 |
| Download | no link |
| Example | no example public currently |
| Hooks used | |
Contents |
[edit] What can this extension do?
It displays (currently only) restructured text files from a directory of the local file system (rendered to html of course) as a wiki page. It first checks if a page title (called by current request) exists in the wiki/DB and if this is not the case checks if available in the directory (which has to be set in the extension's code). All pages in the dir can be see on Special:LocalFileSystem
Currently this is a simple hack, I aim to extend it to check for different file formats, html, stx, txt, which on as default. I have to dive in further in the parser code and hooks. Anyone wanting to help is welcome.
The idea of the extension is simple and i think it's useful. My motivation was to make my old zwiki pages available in my mediawiki - unfortunately they are not linked internally - because they're CamelCased. Another thing which should be done.
This is my first extension and i am quite new to php so my code and style is not the best, sorry for that.
[edit] Usage
Link pages known to be in the filesystem DIR, as usual.
[edit] Installation
Download and install rst2html.py on your system, if not yet installed. It's part of | docutils
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/LocalFileSystem.php");
and put the code below in your extensions dir, named 'LocalFileSystem.php'.
[edit] User rights
To view the special page i invent the permission 'localfilesystem' which per default everybody has.
[edit] Code
// LocalFileSystem extension // requires rst2html.py installed if (!defined('MEDIAWIKI')) die(); define('FSDIR', 'YOUR/PATH/TO/DIR/IN/LOCALFILESYSTEM/'); $rst2html = '/usr/bin/rst2html.py'; // rst parser executable $wgHooks['ArticleFromTitle'][] = 'LFS_ArticleFromTitle'; $wgHooks['OutputPageBeforeHTML'][] = 'LFS_addContent'; $wgExtensionCredits['other'][] = array( 'name' => 'FS extension', 'description' => 'Displays files of one directory of the local file system', 'author' => 'Florian Konnertz', 'url' => 'http://openspirit.de/mediawiki/' ); $wgExtensionCredits['specialpage'][] = array( 'name' => 'LocalFileSystem extension', 'description' => '' ); $wgExtensionFunctions[] = "wfSetupLocalFileSystem"; $wgAvailableRights[] = 'localfilesystem'; $wgGroupPermissions['*'] ['localfilesystem'] = true; function wfSetupLocalFileSystem() { // FIXME title of specialpage is not rendered correctly require_once( 'SpecialPage.php' ); SpecialPage::addPage( new SpecialPage( 'LocalFileSystem', 'localfilesystem', /*listed*/ true, /*function*/ false, /*file*/ false ) ); } function wfSpecialLocalFileSystem() { global $wgOut; $files = scandir(FSDIR); $files = array_slice($files, 2); // remove . and .. from scandir's list foreach ($files as $k=>$fn) { $line = '<a href="/index.php?title='.$fn.'">'.$fn.'</a><br>'; // FIXME: replace with mw globals $line .= "\n"; $wgOut->addHTML($line); } } $fstitle = ''; function LFS_ArticleFromTitle(&$title, &$article) { if ( $title->exists() ) { return true; } global $fstitle; $fn = FSDIR.$title; if (file_exists($fn)) { $fstitle = $fn; } return true; } function LFS_addContent(&$out, &$text) { global $fstitle; global $wgOut; if ($fstitle) { $t = file_get_contents($fstitle); $html = rstRstRender($t); $text = $html; } return true; } function rstRstRender($input) { // credits: ReStructured text extension // FIXME warnings and errors from rst2html are displayed on the page, not wanted. global $rst2html; if (!is_executable($rst2html)) { return "<strong class='error'>" . "reStructureText extension: No executable at $rst2html" . "</strong>"; } # If pipe errors are reported, enable output to the file. # But make certain the file doesn't already exist or else # the webserver may not have permission to create it. $io_desc = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), /* 2 => array('file', '/tmp/error-output.txt', 'a') */); $res = proc_open($rst2html . " --stylesheet-path='' " . "--initial-header-level=2 --no-doc-title " . "--no-file-insertion --no-raw", $io_desc, $pipes, '/tmp', NULL); if (is_resource($res)) { fwrite($pipes[0], $input); fclose($pipes[0]); $html = stream_get_contents($pipes[1]); fclose($pipes[1]); $html = preg_replace('/.*<body>\n(.*)<\/body>.*/s', '${1}', $html); } else { $html = "<strong class='error'>" . "reStructureText extension: error opening pipe" . "</strong>"; } return $html; }
[edit] See also
Not sure, some extension might be related ie.,
- Extension:PagesOnDemand
- Extension:DirectoryManager found after coding... checking

