diff --git a/build/index.php b/build/index.php index 5971e4a..435c8e1 100644 --- a/build/index.php +++ b/build/index.php @@ -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", "

The recent changes 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.

@@ -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)); +} + diff --git a/module_index.json b/module_index.json index 63da429..cb939b9 100644 --- a/module_index.json +++ b/module_index.json @@ -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 }, { diff --git a/modules/feature-recent-changes.php b/modules/feature-recent-changes.php index 9c2162c..f98a25f 100644 --- a/modules/feature-recent-changes.php +++ b/modules/feature-recent-changes.php @@ -1,7 +1,7 @@ "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", "

The recent changes 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.

@@ -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)); +} + ?>