1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Add parser variable to list subpages

This commit is contained in:
Starbeamrainbowlabs 2016-04-09 07:51:29 +01:00
parent b044651dc3
commit 999c1abafd
4 changed files with 53 additions and 15 deletions

View file

@ -1,7 +1,7 @@
# Changelog # Changelog
# v0.11-dev # v0.11-dev
# Added # Added
- Unlocked the uploading of any file type. Note that only the file types specified in the settings are allowed to be uploaded.7 - Unlocked the uploading of any file type. Note that only the file types specified in the settings are allowed to be uploaded.
- Uploaded video and audio files can now be viewed on their respective pages - Uploaded video and audio files can now be viewed on their respective pages
- The file preview tool is now aware that not everything will be an image. - The file preview tool is now aware that not everything will be an image.
- Enhanced the recent changes page. - Enhanced the recent changes page.
@ -10,7 +10,9 @@
- Uploads show with an arrow next to them along with the size of the uploaded file - Uploads show with an arrow next to them along with the size of the uploaded file
- Added mathematical expression parsing between dollar signs. - Added mathematical expression parsing between dollar signs.
- Generated previews now have etags. This should speed up load times of subsequent requests significantly. - Generated previews now have etags. This should speed up load times of subsequent requests significantly.
- Added an extra debug variable that displays the top level page name (i.e. the page that has been requested). It can be used like this: `{{{~}}}` - Added some extra built-in variables to the parser.
- `{{{~}}}`: Displays the top level page name (i.e. the page that has been requested).
- `{{{*}}}`: Displays a comma-separated list of subpages of the requested page.
- Links to non-existent pages are now coloured red by default. - Links to non-existent pages are now coloured red by default.
# Changed # Changed

View file

@ -4234,9 +4234,16 @@ class PeppermintParsedown extends ParsedownExtra
$this->InlineTypes["{"][] = "Template"; $this->InlineTypes["{"][] = "Template";
} }
/*
* ████████ ███████ ███ ███ ██████ ██ █████ ████████ ██ ███ ██ ██████
* ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
* ██ █████ ██ ████ ██ ██████ ██ ███████ ██ ██ ██ ██ ██ ██ ███
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ███████ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ████ ██████
*/
protected function inlineTemplate($fragment) protected function inlineTemplate($fragment)
{ {
global $env; global $env, $pageindex;
// Variable parsing // Variable parsing
if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches)) if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches))
@ -4253,7 +4260,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue = false; $variableValue = false;
switch ($variableKey) switch ($variableKey)
{ {
case "@": case "@": // Lists all subpages
if(!empty($params)) if(!empty($params))
{ {
$variableValue = "<table> $variableValue = "<table>
@ -4265,7 +4272,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue .= "</table>"; $variableValue .= "</table>";
} }
break; break;
case "#": case "#": // Shows a stack trace
$variableValue = "<ol start=\"0\">\n"; $variableValue = "<ol start=\"0\">\n";
$variableValue .= "\t<li>$env->page</li>\n"; $variableValue .= "\t<li>$env->page</li>\n";
foreach($this->paramStack as $curStackEntry) foreach($this->paramStack as $curStackEntry)
@ -4274,10 +4281,21 @@ class PeppermintParsedown extends ParsedownExtra
} }
$variableValue .= "</ol>\n"; $variableValue .= "</ol>\n";
break; break;
case "~": case "~": // Show requested page's name
if(!empty($this->paramStack)) if(!empty($this->paramStack))
$variableValue = $this->escapeText($env->page); $variableValue = $this->escapeText($env->page);
// TODO: Add a option that displays a list of subpages here break;
case "*": // Lists subpages
$subpages = get_subpages($pageindex, $env->page);
$variableValue = [];
foreach($subpages as $pagename => $depth)
{
$variableValue[] = $pagename;
}
$variableValue = implode(", ", $variableValue);
if(strlen($variableValue) === 0)
$variableValue = "<em>(none yet!)</em>";
break;
} }
if(isset($params[$variableKey])) if(isset($params[$variableKey]))
{ {
@ -4285,7 +4303,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue = $this->escapeText($variableValue); $variableValue = $this->escapeText($variableValue);
} }
if($variableValue) if($variableValue !== false)
{ {
return [ return [
"extent" => strlen($matches[0]), "extent" => strlen($matches[0]),

View file

@ -194,7 +194,7 @@
"author": "Emanuil Rusev & Starbeamrainbowlabs", "author": "Emanuil Rusev & Starbeamrainbowlabs",
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds a some weight to your installation, and also *requires* write access to the disk on first load.", "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds a some weight to your installation, and also *requires* write access to the disk on first load.",
"id": "parser-parsedown", "id": "parser-parsedown",
"lastupdate": 1460145045, "lastupdate": 1460184547,
"optional": false "optional": false
} }
] ]

View file

@ -87,9 +87,16 @@ class PeppermintParsedown extends ParsedownExtra
$this->InlineTypes["{"][] = "Template"; $this->InlineTypes["{"][] = "Template";
} }
/*
* ████████ ███████ ███ ███ ██████ ██ █████ ████████ ██ ███ ██ ██████
* ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
* ██ █████ ██ ████ ██ ██████ ██ ███████ ██ ██ ██ ██ ██ ██ ███
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ███████ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ████ ██████
*/
protected function inlineTemplate($fragment) protected function inlineTemplate($fragment)
{ {
global $env; global $env, $pageindex;
// Variable parsing // Variable parsing
if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches)) if(preg_match("/\{\{\{([^}]+)\}\}\}/", $fragment["text"], $matches))
@ -106,7 +113,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue = false; $variableValue = false;
switch ($variableKey) switch ($variableKey)
{ {
case "@": case "@": // Lists all subpages
if(!empty($params)) if(!empty($params))
{ {
$variableValue = "<table> $variableValue = "<table>
@ -118,7 +125,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue .= "</table>"; $variableValue .= "</table>";
} }
break; break;
case "#": case "#": // Shows a stack trace
$variableValue = "<ol start=\"0\">\n"; $variableValue = "<ol start=\"0\">\n";
$variableValue .= "\t<li>$env->page</li>\n"; $variableValue .= "\t<li>$env->page</li>\n";
foreach($this->paramStack as $curStackEntry) foreach($this->paramStack as $curStackEntry)
@ -127,10 +134,21 @@ class PeppermintParsedown extends ParsedownExtra
} }
$variableValue .= "</ol>\n"; $variableValue .= "</ol>\n";
break; break;
case "~": case "~": // Show requested page's name
if(!empty($this->paramStack)) if(!empty($this->paramStack))
$variableValue = $this->escapeText($env->page); $variableValue = $this->escapeText($env->page);
// TODO: Add a option that displays a list of subpages here break;
case "*": // Lists subpages
$subpages = get_subpages($pageindex, $env->page);
$variableValue = [];
foreach($subpages as $pagename => $depth)
{
$variableValue[] = $pagename;
}
$variableValue = implode(", ", $variableValue);
if(strlen($variableValue) === 0)
$variableValue = "<em>(none yet!)</em>";
break;
} }
if(isset($params[$variableKey])) if(isset($params[$variableKey]))
{ {
@ -138,7 +156,7 @@ class PeppermintParsedown extends ParsedownExtra
$variableValue = $this->escapeText($variableValue); $variableValue = $this->escapeText($variableValue);
} }
if($variableValue) if($variableValue !== false)
{ {
return [ return [
"extent" => strlen($matches[0]), "extent" => strlen($matches[0]),