Add most linked-to pages statistic

This commit is contained in:
Starbeamrainbowlabs 2018-04-28 10:59:08 +01:00
parent 75d6fbaa56
commit de61612b18
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
4 changed files with 107 additions and 6 deletions

View File

@ -11,6 +11,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Added user count statistic
- Added redirect page count statistic
- Add orphan pages statistic
- Add most linked-to pages statistic
- [Rest API] Added support for the `mode` parameter to the `random` action
- [Rest API] Added `format` parameter to `recentchanges` action
- [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. */
$version = "v0.16-dev";
$commit = "c6a3ce16df9886c0135bd8ed36efa3df7cc376a1";
$commit = "75d6fbaa5657495c892ba6c489149013fb57a9ed";
/// Environment ///
/** Holds information about the current request environment. */
$env = new stdClass();
@ -7981,7 +7981,13 @@ register_module([
return $result;
});
// Wanted pages
/*
* ███████ ████████ █████ ████████ ██ ███████ ████████ ██ ██████ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███████ ██ ███████ ██ ██ ███████ ██ ██ ██ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████
*/
statistic_add([
"id" => "wanted-pages",
"name" => "Wanted Pages",
@ -8025,7 +8031,6 @@ register_module([
return $result;
}
]);
// Wanted pages
statistic_add([
"id" => "orphan-pages",
"name" => "Orphan Pages",
@ -8075,6 +8080,51 @@ register_module([
return $result;
}
]);
statistic_add([
"id" => "most-linked-to-pages",
"name" => "Most Linked-To 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;
if(empty($pages[$linked_page]))
$pages[$linked_page] = 0;
$pages[$linked_page]++;
}
}
arsort($pages);
$result->value = $pages;
$result->completed = true;
return $result;
},
"render" => function($stats_data) {
global $pageindex;
$result = "<h2>$stats_data->name</h2>\n";
$result .= "<table class='most-linked-to-pages'>\n";
$result .= "\t<tr><th>Page Name</th><th>Linking Pages</th></tr>\n";
foreach($stats_data->value as $pagename => $link_count) {
$pagename_display = !empty($pageindex->$pagename->redirect) && $pageindex->$pagename->redirect ? "<em>$pagename</em>" : $pagename;
$result .= "\t<tr><td><a href='?page=" . rawurlencode($pagename) . "'>$pagename_display</a></td><td>$link_count</td></tr>\n";
}
$result .= "</table>\n";
return $result;
}
]);
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>

View File

@ -266,7 +266,7 @@
"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.",
"id": "parser-parsedown",
"lastupdate": 1524783071,
"lastupdate": 1524909375,
"optional": false
}
]

View File

@ -21,7 +21,13 @@ register_module([
return $result;
});
// Wanted pages
/*
* ███████ ████████ █████ ████████ ██ ███████ ████████ ██ ██████ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███████ ██ ███████ ██ ██ ███████ ██ ██ ██ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ███████ ██ ██ ██ ██ ██ ███████ ██ ██ ██████ ███████
*/
statistic_add([
"id" => "wanted-pages",
"name" => "Wanted Pages",
@ -65,7 +71,6 @@ register_module([
return $result;
}
]);
// Wanted pages
statistic_add([
"id" => "orphan-pages",
"name" => "Orphan Pages",
@ -115,6 +120,51 @@ register_module([
return $result;
}
]);
statistic_add([
"id" => "most-linked-to-pages",
"name" => "Most Linked-To 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;
if(empty($pages[$linked_page]))
$pages[$linked_page] = 0;
$pages[$linked_page]++;
}
}
arsort($pages);
$result->value = $pages;
$result->completed = true;
return $result;
},
"render" => function($stats_data) {
global $pageindex;
$result = "<h2>$stats_data->name</h2>\n";
$result .= "<table class='most-linked-to-pages'>\n";
$result .= "\t<tr><th>Page Name</th><th>Linking Pages</th></tr>\n";
foreach($stats_data->value as $pagename => $link_count) {
$pagename_display = !empty($pageindex->$pagename->redirect) && $pageindex->$pagename->redirect ? "<em>$pagename</em>" : $pagename;
$result .= "\t<tr><td><a href='?page=" . rawurlencode($pagename) . "'>$pagename_display</a></td><td>$link_count</td></tr>\n";
}
$result .= "</table>\n";
return $result;
}
]);
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>