1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-22 13:45:02 +00:00

Refactor code to add a recent change into own method

This commit is contained in:
Starbeamrainbowlabs 2016-04-03 15:31:50 +01:00
parent d5a1fb1a15
commit 8b55263a44
3 changed files with 44 additions and 22 deletions

View file

@ -1565,7 +1565,7 @@ function render_sidebar($pageindex, $root_pagename = "")
register_module([
"name" => "Recent Changes",
"version" => "0.2.1",
"version" => "0.3",
"author" => "Starbeamrainbowlabs",
"description" => "Adds recent changes. Access through the 'recent-changes' action.",
"id" => "feature-recent-changes",
@ -1637,7 +1637,6 @@ register_module([
// Calculate the page length difference
$size_diff = $newsize - $oldsize;
$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
$newchange = [
"type" => "edit",
"timestamp" => time(),
@ -1648,15 +1647,8 @@ register_module([
];
if($oldsize == 0)
$newchange["newpage"] = true;
array_unshift($recentchanges, $newchange);
// Limit the number of entries in the recent changes file if we've
// been asked to.
if(isset($settings->max_recent_changes))
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
// Save the recent changes file back to disk
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
add_recent_change($newchange);
});
add_help_section("800-raw-page-content", "Recent Changes", "<p>The <a href='?action=recent-changes'>recent changes</a> page displays a list of all the most recent changes that have happened around $settings->sitename, arranged in chronological order. It can be found in the \"More...\" menu in the top right by default.</p>
@ -1664,6 +1656,25 @@ register_module([
}
]);
/**
* Adds a new recent change to the recent changes file.
* @param array $rchange The new change to add.
*/
function add_recent_change($rchange)
{
global $settings, $paths;
$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
array_unshift($recentchanges, $rchange);
// Limit the number of entries in the recent changes file if we've
// been asked to.
if(isset($settings->max_recent_changes))
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
// Save the recent changes file back to disk
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
}

View file

@ -37,11 +37,11 @@
},
{
"name": "Recent Changes",
"version": "0.2.1",
"version": "0.3",
"author": "Starbeamrainbowlabs",
"description": "Adds recent changes. Access through the 'recent-changes' action.",
"id": "feature-recent-changes",
"lastupdate": 1459693632,
"lastupdate": 1459693836,
"optional": false
},
{

View file

@ -1,7 +1,7 @@
<?php
register_module([
"name" => "Recent Changes",
"version" => "0.2.1",
"version" => "0.3",
"author" => "Starbeamrainbowlabs",
"description" => "Adds recent changes. Access through the 'recent-changes' action.",
"id" => "feature-recent-changes",
@ -73,7 +73,6 @@ register_module([
// Calculate the page length difference
$size_diff = $newsize - $oldsize;
$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
$newchange = [
"type" => "edit",
"timestamp" => time(),
@ -84,15 +83,8 @@ register_module([
];
if($oldsize == 0)
$newchange["newpage"] = true;
array_unshift($recentchanges, $newchange);
// Limit the number of entries in the recent changes file if we've
// been asked to.
if(isset($settings->max_recent_changes))
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
// Save the recent changes file back to disk
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
add_recent_change($newchange);
});
add_help_section("800-raw-page-content", "Recent Changes", "<p>The <a href='?action=recent-changes'>recent changes</a> page displays a list of all the most recent changes that have happened around $settings->sitename, arranged in chronological order. It can be found in the \"More...\" menu in the top right by default.</p>
@ -100,4 +92,23 @@ register_module([
}
]);
/**
* Adds a new recent change to the recent changes file.
* @param array $rchange The new change to add.
*/
function add_recent_change($rchange)
{
global $settings, $paths;
$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
array_unshift($recentchanges, $rchange);
// Limit the number of entries in the recent changes file if we've
// been asked to.
if(isset($settings->max_recent_changes))
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
// Save the recent changes file back to disk
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
}
?>