mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 05:22:59 +00:00
Refactor recent changes display into own method
This commit is contained in:
parent
6a2c0dad5c
commit
22981547cc
4 changed files with 116 additions and 65 deletions
|
@ -2,6 +2,9 @@
|
||||||
# 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.
|
- Unlocked the uploading of any file type. Note that only the file types specified in the settings are allowed to be uploaded.
|
||||||
|
- Enhanced the recent changes page.
|
||||||
|
- New pages show up with an 'N' next to them (as they do in a MediaWiki installation)
|
||||||
|
- Page deletions show up in red with a line though them
|
||||||
|
|
||||||
# Changed
|
# Changed
|
||||||
- Enhanced the dev help page some more
|
- Enhanced the dev help page some more
|
||||||
|
|
|
@ -1596,40 +1596,11 @@ register_module([
|
||||||
|
|
||||||
$content = "\t\t<h1>Recent Changes</h1>\n";
|
$content = "\t\t<h1>Recent Changes</h1>\n";
|
||||||
|
|
||||||
$recentchanges = json_decode(file_get_contents($paths->recentchanges));
|
$recent_changes = json_decode(file_get_contents($paths->recentchanges));
|
||||||
|
|
||||||
if(count($recentchanges) > 0)
|
if(count($recent_changes) > 0)
|
||||||
{
|
{
|
||||||
$content .= "<ul class='page-list'>\n";
|
$content .= render_recent_changes($recent_changes);
|
||||||
foreach($recentchanges as $rchange)
|
|
||||||
{
|
|
||||||
// Render the page's name
|
|
||||||
$pageDisplayName = $rchange->page;
|
|
||||||
if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
|
|
||||||
$pageDisplayName = "<em>$pageDisplayName</em>";
|
|
||||||
|
|
||||||
switch(isset($rchange->type) ? $rchange->type : "edit")
|
|
||||||
{
|
|
||||||
case "edit":
|
|
||||||
// The number (and the sign) of the size difference to display
|
|
||||||
$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
|
|
||||||
$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
|
|
||||||
if($rchange->sizediff > 500 or $rchange->sizediff < -500)
|
|
||||||
$size_display_class .= " significant";
|
|
||||||
|
|
||||||
|
|
||||||
$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " . human_filesize($rchange->newsize);
|
|
||||||
|
|
||||||
|
|
||||||
$content .= "\t\t\t<li" . (!empty($rchange->newpage) ? " class='newpage'" : "") . "><a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> <span class='editor'>✎ $rchange->user</span> <time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time> <span class='$size_display_class' title='$title_display'>($size_display)</span></li>\n";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "deletion":
|
|
||||||
$content .= "<li class='deletion'>$pageDisplayName <span class='editor'>✎ $rchange->user</span> <time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time></li>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
$content .= "\t\t</ul>";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1688,6 +1659,59 @@ function add_recent_change($rchange)
|
||||||
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render_recent_changes($recentchanges)
|
||||||
|
{
|
||||||
|
$content = "<ul class='page-list'>\n";
|
||||||
|
foreach($recentchanges as $rchange)
|
||||||
|
{
|
||||||
|
$content .= render_recent_change($rchange);
|
||||||
|
}
|
||||||
|
$content .= "\t\t</ul>";
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function render_recent_change($rchange)
|
||||||
|
{
|
||||||
|
// Render the page's name
|
||||||
|
$pageDisplayName = $rchange->page;
|
||||||
|
if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
|
||||||
|
$pageDisplayName = "<em>$pageDisplayName</em>";
|
||||||
|
|
||||||
|
$editorDisplayHtml = "<span class='editor'>✎ $rchange->user</span>";
|
||||||
|
$timeDisplayHtml = "<time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time>";
|
||||||
|
|
||||||
|
$result = "";
|
||||||
|
$resultClasses = [];
|
||||||
|
switch(isset($rchange->type) ? $rchange->type : "edit")
|
||||||
|
{
|
||||||
|
case "edit":
|
||||||
|
// The number (and the sign) of the size difference to display
|
||||||
|
$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
|
||||||
|
$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
|
||||||
|
if($rchange->sizediff > 500 or $rchange->sizediff < -500)
|
||||||
|
$size_display_class .= " significant";
|
||||||
|
|
||||||
|
|
||||||
|
$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " . human_filesize($rchange->newsize);
|
||||||
|
|
||||||
|
if(!empty($rchange->newpage))
|
||||||
|
$resultClasses[] = "newpage";
|
||||||
|
|
||||||
|
$result .= "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "deletion":
|
||||||
|
$resultClasses[] = "deletion";
|
||||||
|
$result .= "$pageDisplayName $editorDisplayHtml $timeDisplayHtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultAttributes = " " . (count($resultClasses) > 0 ? "class='" . implode(" ", $resultClasses) . "'" : "");
|
||||||
|
$result = "\t\t\t<li$resultAttributes>$result</li>\n";
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds recent changes. Access through the 'recent-changes' action.",
|
"description": "Adds recent changes. Access through the 'recent-changes' action.",
|
||||||
"id": "feature-recent-changes",
|
"id": "feature-recent-changes",
|
||||||
"lastupdate": 1459694503,
|
"lastupdate": 1459695505,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,40 +31,11 @@ register_module([
|
||||||
|
|
||||||
$content = "\t\t<h1>Recent Changes</h1>\n";
|
$content = "\t\t<h1>Recent Changes</h1>\n";
|
||||||
|
|
||||||
$recentchanges = json_decode(file_get_contents($paths->recentchanges));
|
$recent_changes = json_decode(file_get_contents($paths->recentchanges));
|
||||||
|
|
||||||
if(count($recentchanges) > 0)
|
if(count($recent_changes) > 0)
|
||||||
{
|
{
|
||||||
$content .= "<ul class='page-list'>\n";
|
$content .= render_recent_changes($recent_changes);
|
||||||
foreach($recentchanges as $rchange)
|
|
||||||
{
|
|
||||||
// Render the page's name
|
|
||||||
$pageDisplayName = $rchange->page;
|
|
||||||
if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
|
|
||||||
$pageDisplayName = "<em>$pageDisplayName</em>";
|
|
||||||
|
|
||||||
switch(isset($rchange->type) ? $rchange->type : "edit")
|
|
||||||
{
|
|
||||||
case "edit":
|
|
||||||
// The number (and the sign) of the size difference to display
|
|
||||||
$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
|
|
||||||
$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
|
|
||||||
if($rchange->sizediff > 500 or $rchange->sizediff < -500)
|
|
||||||
$size_display_class .= " significant";
|
|
||||||
|
|
||||||
|
|
||||||
$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " . human_filesize($rchange->newsize);
|
|
||||||
|
|
||||||
|
|
||||||
$content .= "\t\t\t<li" . (!empty($rchange->newpage) ? " class='newpage'" : "") . "><a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> <span class='editor'>✎ $rchange->user</span> <time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time> <span class='$size_display_class' title='$title_display'>($size_display)</span></li>\n";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "deletion":
|
|
||||||
$content .= "<li class='deletion'>$pageDisplayName <span class='editor'>✎ $rchange->user</span> <time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time></li>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
$content .= "\t\t</ul>";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -123,4 +94,57 @@ function add_recent_change($rchange)
|
||||||
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render_recent_changes($recentchanges)
|
||||||
|
{
|
||||||
|
$content = "<ul class='page-list'>\n";
|
||||||
|
foreach($recentchanges as $rchange)
|
||||||
|
{
|
||||||
|
$content .= render_recent_change($rchange);
|
||||||
|
}
|
||||||
|
$content .= "\t\t</ul>";
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function render_recent_change($rchange)
|
||||||
|
{
|
||||||
|
// Render the page's name
|
||||||
|
$pageDisplayName = $rchange->page;
|
||||||
|
if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
|
||||||
|
$pageDisplayName = "<em>$pageDisplayName</em>";
|
||||||
|
|
||||||
|
$editorDisplayHtml = "<span class='editor'>✎ $rchange->user</span>";
|
||||||
|
$timeDisplayHtml = "<time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time>";
|
||||||
|
|
||||||
|
$result = "";
|
||||||
|
$resultClasses = [];
|
||||||
|
switch(isset($rchange->type) ? $rchange->type : "edit")
|
||||||
|
{
|
||||||
|
case "edit":
|
||||||
|
// The number (and the sign) of the size difference to display
|
||||||
|
$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
|
||||||
|
$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
|
||||||
|
if($rchange->sizediff > 500 or $rchange->sizediff < -500)
|
||||||
|
$size_display_class .= " significant";
|
||||||
|
|
||||||
|
|
||||||
|
$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " . human_filesize($rchange->newsize);
|
||||||
|
|
||||||
|
if(!empty($rchange->newpage))
|
||||||
|
$resultClasses[] = "newpage";
|
||||||
|
|
||||||
|
$result .= "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "deletion":
|
||||||
|
$resultClasses[] = "deletion";
|
||||||
|
$result .= "$pageDisplayName $editorDisplayHtml $timeDisplayHtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
$resultAttributes = " " . (count($resultClasses) > 0 ? "class='" . implode(" ", $resultClasses) . "'" : "");
|
||||||
|
$result = "\t\t\t<li$resultAttributes>$result</li>\n";
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue