mirror of
git://git.proxmox.com/git/pve-docs.git
synced 2025-03-20 22:50:06 +03:00
mediawiki: transform into new-style add-on
The core 'LanguageGetMagic' hook we used originally was was removed completely in version 1.33.0 (after being deprecated in 1.16.0). So transform into the new style, again adapted from: https://www.mediawiki.org/wiki/Manual:Parser_functions Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
acf6050bdd
commit
fe97856a2a
2
debian/pve-docs-mediawiki.install
vendored
2
debian/pve-docs-mediawiki.install
vendored
@ -1,3 +1,3 @@
|
||||
/usr/bin/pve-docs-mediawiki-import
|
||||
debian/tree/pve-docs-mediawiki/pve-docs.conf /etc/apache2/sites-available/
|
||||
debian/tree/pve-docs-mediawiki/pvedocs-include.php /usr/lib/pve-docs/
|
||||
debian/tree/pve-docs-mediawiki/PVEDocs /usr/lib/pve-docs/
|
||||
|
31
debian/tree/pve-docs-mediawiki/PVEDocs/LICENSE.txt
vendored
Normal file
31
debian/tree/pve-docs-mediawiki/PVEDocs/LICENSE.txt
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
Coryright for all files not covered by a more specific rule below:
|
||||
|
||||
Copyright (C) 2015 - 2021 Proxmox Server Solutions GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU Affero General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public
|
||||
License along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
All documentation files (*.adoc *.png) are release under:
|
||||
|
||||
Copyright (C) 2015 - 2021 Proxmox Server Solutions GmbH
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
A copy of the license is included in the section entitled "GNU
|
||||
Free Documentation License".
|
||||
|
||||
You can find a copy of the license in /usr/share/common-licenses/GFDL.
|
7
debian/tree/pve-docs-mediawiki/PVEDocs/PVEDocs.i18n.magic.php
vendored
Normal file
7
debian/tree/pve-docs-mediawiki/PVEDocs/PVEDocs.i18n.magic.php
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$magicWords = [];
|
||||
|
||||
$magicWords['en'] = [
|
||||
'pvedocs' => [ 0, 'pvedocs' ], # case-insensitive, name
|
||||
];
|
25
debian/tree/pve-docs-mediawiki/PVEDocs/extension.json
vendored
Normal file
25
debian/tree/pve-docs-mediawiki/PVEDocs/extension.json
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "PVEDocs",
|
||||
"author": "Thomas Lamprecht, Dietmar Maurer",
|
||||
"version": "2021.05.1",
|
||||
"url": "https://git.proxmox.com/?p=pve-docs.git;a=summary",
|
||||
"descriptionmsg": "Display PVE Documentation Pages",
|
||||
"license-name": "GPL-3.0-or-later",
|
||||
"type": "parserhook",
|
||||
"AutoloadClasses": {
|
||||
"PVEDocs": "include/PVEDocs.php"
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"PVEDocs": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"ExtensionMessagesFiles": {
|
||||
"PVEDocsMagic": "PVEDocs.i18n.magic.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": "PVEDocs::onParserFirstCallInit",
|
||||
"ParserAfterTidy": "PVEDocs::efPvedocsPostProcessFunction"
|
||||
},
|
||||
"manifest_version": 1
|
||||
}
|
43
debian/tree/pve-docs-mediawiki/PVEDocs/include/PVEDocs.php
vendored
Normal file
43
debian/tree/pve-docs-mediawiki/PVEDocs/include/PVEDocs.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// see http://www.mediawiki.org/wiki/Manual:Parser_functions
|
||||
|
||||
class PVEDocs {
|
||||
public static function onParserFirstCallInit(Parser $parser ) {
|
||||
$parser->setFunctionHook('pvedocs', [ self::class, 'efPvedocsParserFunction_Render' ]);
|
||||
$parser->setHook('pvehide', [ self::class, 'renderTagPveHideContent' ]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// similar code as in <htmlet> tag...
|
||||
public static function efPvedocsPostProcessFunction($parser, &$text) {
|
||||
$text = preg_replace_callback(
|
||||
'/<!--- @PVEDOCS_BASE64@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCS_BASE64@ -->/sm',
|
||||
function ($m) { return base64_decode("$m[1]"); },
|
||||
$text
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// "Render" <pvehide>
|
||||
public static function renderTagPveHideContent($input, array $args, Parser $parser, PPFrame $frame ) {
|
||||
return ''; // simply return nothing
|
||||
}
|
||||
|
||||
|
||||
# Render the output of {{#pvedocs:chapter}}.
|
||||
public static function efPvedocsParserFunction_Render(Parser $parser, $doc = '') {
|
||||
$parser->getOutput()->updateCacheExpiry(0); // disableCache() was dropped in MW 1.34
|
||||
|
||||
// only allow simple names, so that jist files from within "/usr/share/pve-docs/" can be included
|
||||
if (!preg_match("/[a-z0-9.-]+\.html/i", $doc)) {
|
||||
die("no such manual page");
|
||||
}
|
||||
|
||||
$content = file_get_contents("/usr/share/pve-docs/$doc");
|
||||
|
||||
// from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/HTMLets/+/11e5ef1ea2820319458dc67174ca76d6e00b10cc/HTMLets.php#140
|
||||
$output = '<!--- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -->';
|
||||
return array($output, 'noparse' => true, 'isHTML' => true);
|
||||
}
|
||||
}
|
2
debian/tree/pve-docs-mediawiki/README
vendored
2
debian/tree/pve-docs-mediawiki/README
vendored
@ -25,5 +25,5 @@ In the MediaWiki settings PHP file ('/var/www/mediawiki/LocalSettings.php') add:
|
||||
|
||||
# ----8<----
|
||||
# for docs-inclusion plugin:
|
||||
require_once("/usr/lib/pve-docs/pvedocs-include.php");
|
||||
wfLoadExtension( 'PVEDocs' );
|
||||
# ---->8----
|
||||
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
# see http://www.mediawiki.org/wiki/Manual:Parser_functions
|
||||
|
||||
$wgExtensionCredits['parserhook'][] = array(
|
||||
'name' => "PVE Documentation Pages",
|
||||
'description' => "Display PVE Documentation Pages",
|
||||
'author' => "Dietmar Maurer",
|
||||
);
|
||||
|
||||
# Define a setup function
|
||||
$wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup';
|
||||
$wgHooks['ParserAfterTidy'][] = 'efPvedocsPostProcessFunction';
|
||||
|
||||
# Add a hook to initialise the magic word
|
||||
$wgHooks['LanguageGetMagic'][] = 'efPvedocsParserFunction_Magic';
|
||||
|
||||
function efPvedocsParserFunction_Setup(&$parser) {
|
||||
# Set a function hook associating the "pvedocs" magic
|
||||
# word with our function
|
||||
$parser->setFunctionHook('pvedocs', 'efPvedocsParserFunction_Render');
|
||||
|
||||
$parser->setHook('pvehide', 'renderTagPveHideContent');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
# similar code as in <htmlet> tag...
|
||||
function efPvedocsPostProcessFunction($parser, &$text) {
|
||||
$text = preg_replace_callback(
|
||||
'/<!--- @PVEDOCS_BASE64@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCS_BASE64@ -->/sm',
|
||||
function ($m) { return base64_decode("$m[1]"); },
|
||||
$text);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Render <pvehide>
|
||||
function renderTagPveHideContent($input, array $args, Parser $parser,
|
||||
PPFrame $frame ) {
|
||||
// simply return nothing
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function efPvedocsParserFunction_Magic(&$magicWords, $langCode) {
|
||||
# Add the magic word
|
||||
# The first array element is whether to be case sensitive,
|
||||
# in this case (0) it is not case sensitive, 1 would be sensitive
|
||||
# All remaining elements are synonyms for our parser function
|
||||
$magicWords['pvedocs'] = array( 0, 'pvedocs' );
|
||||
|
||||
# unless we return true, other parser functions extensions won't get loaded.
|
||||
return true;
|
||||
}
|
||||
|
||||
function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') {
|
||||
|
||||
$parser->disableCache();
|
||||
|
||||
# only allow simply names, so that users can only include
|
||||
# files from within "/usr/share/pve-docs/"
|
||||
if (!preg_match("/[a-z0-9.-]+\.html/i", $param1)) {
|
||||
die("no such manual page");
|
||||
}
|
||||
|
||||
$content = file_get_contents("/usr/share/pve-docs/$param1");
|
||||
|
||||
# from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/HTMLets/+/11e5ef1ea2820319458dc67174ca76d6e00b10cc/HTMLets.php#140
|
||||
$output = '<!--- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -->';
|
||||
return array($output, 'noparse' => true, 'isHTML' => true);
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user