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

Add orphan pages statistic

This commit is contained in:
Starbeamrainbowlabs 2018-04-26 23:27:44 +01:00
parent 0c00cf3631
commit c6a3ce16df
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 99 additions and 2 deletions

View file

@ -10,6 +10,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Added the commit hash Pepperminty Wiki was built against to the master settings configuration page, and the debug action - Added the commit hash Pepperminty Wiki was built against to the master settings configuration page, and the debug action
- Added user count statistic - Added user count statistic
- Added redirect page count statistic - Added redirect page count statistic
- Add orphan pages statistic
- [Rest API] Added support for the `mode` parameter to the `random` action - [Rest API] Added support for the `mode` parameter to the `random` action
- [Rest API] Added `format` parameter to `recentchanges` action - [Rest API] Added `format` parameter to `recentchanges` action
- [Rest API] Added `comments-fetch` action to return a page's comments as JSON - [Rest API] Added `comments-fetch` action to return a page's comments as JSON

View file

@ -387,7 +387,7 @@ if($settings->css === "auto")
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/** The version of Pepperminty Wiki currently running. */ /** The version of Pepperminty Wiki currently running. */
$version = "v0.16-dev"; $version = "v0.16-dev";
$commit = "6fc44b7404f98907a9f351b92654a0da7305a92e"; $commit = "0c00cf36316ba33f9acf4013e9ddee02ed4191d4";
/// Environment /// /// Environment ///
/** Holds information about the current request environment. */ /** Holds information about the current request environment. */
$env = new stdClass(); $env = new stdClass();
@ -8026,6 +8026,54 @@ register_module([
return $result; return $result;
} }
]); ]);
// Wanted pages
statistic_add([
"id" => "orphan-pages",
"name" => "Orphan Pages",
"type" => "page",
"update" => function($old_stats) {
global $pageindex, $env;
$result = new stdClass(); // completed, value, state
$pages = [];
foreach($pageindex as $pagename => $pagedata) {
if(!file_exists($env->storage_prefix . $pagedata->filename)) {
continue;
}
$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
$page_links = PeppermintParsedown::extract_page_names($page_content);
foreach($page_links as $linked_page) {
// We're only interested in pages that exist
if(empty($pageindex->$linked_page)) continue;
$pages[$linked_page] = true;
}
}
$orphaned_pages = [];
foreach($pageindex as $pagename => $page_data) {
if(empty($pages[$pagename]))
$orphaned_pages[] = $pagename;
}
rsort($orphaned_pages);
$result->value = $orphaned_pages;
$result->completed = true;
return $result;
},
"render" => function($stats_data) {
$result = "<h2>$stats_data->name</h2>\n";
$result .= "<ul class='orphan-pages'>\n";
foreach($stats_data->value as $pagename) {
$result .= "\t<li>$pagename</li>\n";
}
$result .= "</ul>\n";
return $result;
}
]);
add_help_section("20-parser-default", "Editor Syntax", add_help_section("20-parser-default", "Editor Syntax",
"<p>$settings->sitename's editor uses an extended version of <a href='http://parsedown.org/'>Parsedown</a> to render pages, which is a fantastic open source Github flavoured markdown parser. You can find a quick reference guide on Github flavoured markdown <a href='https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet'>here</a> by <a href='https://github.com/adam-p/'>adam-p</a>, or if you prefer a book <a href='https://www.gitbook.com/book/roachhd/master-markdown/details'>Mastering Markdown</a> by KB is a good read, and free too!</p> "<p>$settings->sitename's editor uses an extended version of <a href='http://parsedown.org/'>Parsedown</a> to render pages, which is a fantastic open source Github flavoured markdown parser. You can find a quick reference guide on Github flavoured markdown <a href='https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet'>here</a> by <a href='https://github.com/adam-p/'>adam-p</a>, or if you prefer a book <a href='https://www.gitbook.com/book/roachhd/master-markdown/details'>Mastering Markdown</a> by KB is a good read, and free too!</p>

View file

@ -266,7 +266,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 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 some weight to your installation, and also *requires* write access to the disk on first load.",
"id": "parser-parsedown", "id": "parser-parsedown",
"lastupdate": 1524780823, "lastupdate": 1524781555,
"optional": false "optional": false
} }
] ]

View file

@ -66,6 +66,54 @@ register_module([
return $result; return $result;
} }
]); ]);
// Wanted pages
statistic_add([
"id" => "orphan-pages",
"name" => "Orphan Pages",
"type" => "page",
"update" => function($old_stats) {
global $pageindex, $env;
$result = new stdClass(); // completed, value, state
$pages = [];
foreach($pageindex as $pagename => $pagedata) {
if(!file_exists($env->storage_prefix . $pagedata->filename)) {
continue;
}
$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
$page_links = PeppermintParsedown::extract_page_names($page_content);
foreach($page_links as $linked_page) {
// We're only interested in pages that exist
if(empty($pageindex->$linked_page)) continue;
$pages[$linked_page] = true;
}
}
$orphaned_pages = [];
foreach($pageindex as $pagename => $page_data) {
if(empty($pages[$pagename]))
$orphaned_pages[] = $pagename;
}
rsort($orphaned_pages);
$result->value = $orphaned_pages;
$result->completed = true;
return $result;
},
"render" => function($stats_data) {
$result = "<h2>$stats_data->name</h2>\n";
$result .= "<ul class='orphan-pages'>\n";
foreach($stats_data->value as $pagename) {
$result .= "\t<li>$pagename</li>\n";
}
$result .= "</ul>\n";
return $result;
}
]);
add_help_section("20-parser-default", "Editor Syntax", add_help_section("20-parser-default", "Editor Syntax",
"<p>$settings->sitename's editor uses an extended version of <a href='http://parsedown.org/'>Parsedown</a> to render pages, which is a fantastic open source Github flavoured markdown parser. You can find a quick reference guide on Github flavoured markdown <a href='https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet'>here</a> by <a href='https://github.com/adam-p/'>adam-p</a>, or if you prefer a book <a href='https://www.gitbook.com/book/roachhd/master-markdown/details'>Mastering Markdown</a> by KB is a good read, and free too!</p> "<p>$settings->sitename's editor uses an extended version of <a href='http://parsedown.org/'>Parsedown</a> to render pages, which is a fantastic open source Github flavoured markdown parser. You can find a quick reference guide on Github flavoured markdown <a href='https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet'>here</a> by <a href='https://github.com/adam-p/'>adam-p</a>, or if you prefer a book <a href='https://www.gitbook.com/book/roachhd/master-markdown/details'>Mastering Markdown</a> by KB is a good read, and free too!</p>