Permalink
Browse files

code style enhances

  • Loading branch information...
1 parent d30494f commit bd94655195a7d2631c78b567397e646ec9ff082a dominik committed Jan 20, 2010
Showing with 76 additions and 28 deletions.
  1. +27 −9 action.php
  2. +49 −19 admin.php
View
36 action.php
@@ -1,48 +1,66 @@
<?php
-/**
- * Cleanup Action Plugin: Clean up the history once per day
- *
- * @author Dominik Eckelmann <eckelmann@cosmocode.de>
- */
-
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
if(!defined('DOKU_DATA')) define('DOKU_DATA',DOKU_INC.'data/');
-
require_once(DOKU_PLUGIN.'action.php');
require_once(DOKU_PLUGIN.'clearhistory/admin.php');
+/**
+ * Cleanup Action Plugin: Clean up the history once per day
+ *
+ * @author Dominik Eckelmann <eckelmann@cosmocode.de>
+ */
class action_plugin_clearhistory extends DokuWiki_Action_Plugin {
+ /**
+ * if true a cleanup process is already running
+ * or done in the last 24h
+ */
var $run = false;
+ /**
+ * Constructor - get some config details and check if a check runs in the last 24h
+ */
function action_plugin_clearhistory() {
global $conf;
+
+ // check if the autocleaner is enabled
if ($this->getConf('autoclearenabled') == 0) $this->run = true;
+
+ // check if a runfile exists - if not -> there is no last run
if (!is_file($conf['cachedir'].'/lastclean')) return;
+
+ // check last run
$get = fileatime($conf['cachedir'].'/lastclean');
$get = intval($get);
if ($get+(60*60*24) > time()) $this->run = true;
}
/**
- * return some info
+ * return some in
+ * @return array
*/
function getInfo(){
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
/**
* Register its handlers with the dokuwiki's event controller
+ *
+ * we need hook the indexer to trigger the cleanup
*/
function register(&$controller) {
$controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'cleanup', array());
}
+ /**
+ * start the scan
+ *
+ * scans the recent changes
+ */
function cleanup(&$event, $param) {
global $conf;
-
$onlySmall = $this->getConf('autoclearonlysmall');
$onlyNoComment = $this->getConf('autoclearonlynocomment');
if ($this->run) return;
View
68 admin.php
@@ -7,9 +7,12 @@
require_once(DOKU_INC.'inc/changelog.php');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/common.php');
+
/**
- * All DokuWiki plugins to extend the admin function
- * need to inherit from this class
+ * This plugin is used to cleanup the history
+ *
+ * @see http://dokuwiki.org/plugin:clearhistory
+ * @author Dominik Eckelmann <deckelmann@gmail.com>
*/
class admin_plugin_clearhistory extends DokuWiki_Admin_Plugin {
@@ -21,27 +24,35 @@ class admin_plugin_clearhistory extends DokuWiki_Admin_Plugin {
*/
var $pages = array();
+ /**
+ * counts deleted pages for a run
+ */
var $delcounter = 0;
/**
- * return some info
+ * return some information about the plugin
+ *
+ * @return array
*/
function getInfo(){
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
/**
* return sort order for position in admin menu
+ *
+ * @return integer
*/
function getMenuSort() {
return 999;
}
/**
- * handle user request
+ * handle the request befor html output
+ *
+ * @see html()
*/
function handle() {
-
$onlySmall = false;
$onlsNoComment = false;
if (isset($_REQUEST['onlysmall']) && $_REQUEST['onlysmall'] == 'on' ) $onlySmall = true;
@@ -59,14 +70,9 @@ function handle() {
}
/**
- * output appropriate html
+ * output html for the admin page
*/
function html() {
- //$this->_scanRecents();
- //$this->_scan();
-
-
-
echo '<h1>'.$this->getLang('name').'</h1>';
echo '<form action="doku.php" method="GET"><fieldset class="clearhistory">';
echo '<input type="hidden" name="do" value="admin" />';
@@ -89,6 +95,13 @@ function html() {
echo '<p class="clearhistory">'.$this->getLang('desctext').'</p>';
}
+ /**
+ * Scans throu a namespace and count the deleted pages in $this->delcounter
+ *
+ * @param string $ns the namespace to search in
+ * @param boolean $onlySmall only delete small changes on true
+ * @param boolean $onlyNoComment don't delete changes with a comment on true
+ */
function _scanNamespace($ns, $onlySmall = false, $onlyNoComment = false) {
$this->delcounter = 0;
$this->_scan($ns, $onlySmall, $onlyNoComment);
@@ -97,7 +110,10 @@ function _scanNamespace($ns, $onlySmall = false, $onlyNoComment = false) {
/**
* Scans namespaces for deletable revisions
- * @param string ns the namespace to search in
+ *
+ * @param string $ns the namespace to search in
+ * @param boolean $onlySmall only delete small changes on true
+ * @param boolean $onlyNoComment don't delete changes with a comment on true
*/
function _scan($ns = '', $onlySmall = false, $onlyNoComment = false) {
$dir = preg_replace('/\.txt(\.gz)?/i','', wikiFN($ns));
@@ -125,11 +141,14 @@ function _scan($ns = '', $onlySmall = false, $onlyNoComment = false) {
/**
* Scans the recent changed files for changes
- * @param int $num number of last changed files
+ *
+ * @param int $num number of last changed files to scan
+ * @param boolean $onlySmall only delete small changes on true
+ * @param boolean $onlyNoComment don't delete changes with a comment on true
*/
function _scanRecents( $num = 30, $onlySmall = false , $onlyNoComment = false ) {
$recents = getRecents(0,$num);
-
+
$this->delcounter = 0;
foreach ($recents as $recent) {
$this->_parseChangesFile(metaFN($recent['id'],'.changes'),$recent['id'], $onlySmall, $onlyNoComment);
@@ -138,10 +157,11 @@ function _scanRecents( $num = 30, $onlySmall = false , $onlyNoComment = false )
/**
* Parses a .changes file for deletable pages and deletes them.
- * @param string $file the path to the change file
- * @param string $page wiki pagename
- * @param boolean $onlySmall deletes only small changes
- * @param boolean $onlyNoComment deletes only entrys without a comment
+ *
+ * @param string $file the path to the change file
+ * @param string $page wiki pagename
+ * @param boolean $onlySmall deletes only small changes
+ * @param boolean $onlyNoComment deletes only entrys without a comment
*/
function _parseChangesFile( $file , $page , $onlySmall = false , $onlyNoComment = false ) {
if (!is_file($file)) return;
@@ -180,7 +200,7 @@ function _parseChangesFile( $file , $page , $onlySmall = false , $onlyNoComment
$newcontent = $this->_addLine($match,$i) . $newcontent;
continue;
}
-
+
// if onlyNoComment is set we pass all lines with a comment
if ($onlyNoComment && trim($match[6][$i]) != '') {
$cmpuser = $user;
@@ -206,10 +226,20 @@ function _addLine($match,$i) {
return $match[0][$i]."\n";
}
+ /**
+ * shows that this function is accessible only by admins
+ *
+ * @return true
+ */
function forAdminOnly() {
return true;
}
+ /**
+ * returns the name in the menu
+ *
+ * @return Menu name for the plugin
+ */
function getMenuText($lang) {
return $this->getLang('menu');
}

0 comments on commit bd94655

Please sign in to comment.