Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.* export-ignore
/_test export-ignore
8 changes: 0 additions & 8 deletions INFO

This file was deleted.

339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

45 changes: 27 additions & 18 deletions README
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
/**
* remove old Admin Plugin: allows deleting of unnecessary, outdated files from your DokuWiki system
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Taggic <taggic@t-online.de>
*/

Intro
------
This is an admin plugin available via admin manager to delete listed files
, which only consuming space but useless for your version.

Installation
------------
Just download and extract it as folder "removeold" into your "\lib\plugins"
directory.

A complete plugin description is available on http://www.dokuwiki.org/plugin:removeold
removeold plugin for DokuWiki

This is an admin plugin available via admin manager to remove outdated files

All documentation for this plugin can be found at
https://www.dokuwiki.org/plugin:removeold

If you install this plugin manually, make sure it is installed in
lib/plugins/removeold/ - if the folder is called different it
will not work!

Please refer to http://www.dokuwiki.org/extensions for additional info
on how to install extensions in DokuWiki.

----
Copyright (C) Taggic <taggic@t-online.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

See the LICENSING file for details
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

270 changes: 36 additions & 234 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,254 +1,56 @@
<?php

use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Form\Form;

/**
* Remove outdated files after upgrade -> administration function
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Taggic <taggic@t-online.de>
*/
/******************************************************************************/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/******************************************************************************/
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
*/
class admin_plugin_removeold extends DokuWiki_Admin_Plugin {
/**
* return some info
*/
function getInfo(){
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
/******************************************************************************/
class admin_plugin_removeold extends AdminPlugin
{
/**
* return prompt for admin menu
*/
function getMenuText($language) {
return $this->getLang('admin_removeold');
}
/******************************************************************************/
/**
* return sort order for position in admin menu
*/
function getMenuSort() {
return 20;
}
/******************************************************************************/
/**
* handle user request
*
* Initializes internal vars and handles modifications
*
* @author Taggic <taggic@t-online.de>
* @inheritdoc
*/
function handle() {
global $ID;
}
/******************************************************************************/
/**
* removeold Output function
*
* print a table with all found lanuage folders
*
* @author Taggic <taggic@t-online.de>
*/
function html() {
global $ID;
public function html()
{
global $INPUT;

$helper = new helper_plugin_removeold($this);

echo '<div id="removeold__manager">'.NL;
echo '<h1>'.$this->getLang('admin_removeold').'</h1>'.NL;
echo '<div class="level1">'.NL;
echo $this->locale_xhtml('intro');

echo '<div id="removeold__intro">'.NL;
echo $this->locale_xhtml('help');
echo '</div>'.NL;
echo '<div class="log">';
if ($INPUT->bool('exec')) {
echo '<h2>' . $this->getLang('removeold_delmsg') . '</h2>';
} else {
echo '<h2>' . $this->getLang('removeold_willmsg') . '</h2>';

echo '<div id="removeold__detail">'.NL;
$this->_html_uinput();
echo '</div>'.NL;
echo $this->locale_xhtml('precheck');

$filelist = $_REQUEST['removeold_w'];
$dryrun = $_REQUEST['dryrun'];
$summary_option = $_REQUEST['summary_only'];

// language given?
if ($filelist!=false) {
if (($dryrun==true) && ($summary_option==false)) {
echo '<br /><div class="level4"><strong><div class="it__standard_feedback">'.$this->getLang('removeold_willmsg').'</div></strong><br />';
}
elseif ($summary_option==false) {
echo '<br /><div class="level4"><strong><div class="it__standard_feedback">'.$this->getLang('removeold_delmsg').'</div></strong><br />';
}

$this->_list_removeold_files($filelist, $dryrun, $summary_option);
echo '<p>';
$form = new Form();
$form->addButton('exec', $this->getLang('button'));
echo $form->toHTML();
echo '</p>';
}
echo '</div>'.NL;
echo '<div class="footnotes"><div class="fn">'.NL;
echo '<sup><a id="fn__1" class="fn_bot" name="fn__1" href="#fnt__1">1)</a></sup>'.NL;
echo $this->getLang('p_include');
echo '</div></div>'.NL;

echo '</div>'.NL;
$helper->run(!$INPUT->bool('exec'));
echo '</div>';
}
/******************************************************************************/

/**
* Display the form with input control to let the user specify
* the files to be deleted
*
* @author Taggic <taggic@t-online.de>
* Implement the logging interface
*
* @param string $level
* @param string $msg
* @return void
*/
function _html_uinput(){
global $conf;
global $ID;

// load deleted.files from data folder and show it in textarea
if(is_dir($conf["savedir"])=== false) {
$deleted_files = file_get_contents(DOKU_INC."/".$conf["savedir"]."/deleted.files");
}
else $deleted_files = file_get_contents($conf["savedir"]."/deleted.files");

if($deleted_files !== "") {
echo '<div class="level4" id="removeold__input">'.$this->getLang('i_choose').'<br />'.NL;
echo '<div class="no">'.NL;
echo '<fieldset class="removeold__fieldset"><legend class="removeold_i_legend">'.$this->getLang('i_legend').'</legend>'.NL;
echo '<form action="'.wl($ID).'" method="post">';
echo '<input type="hidden" name="do" value="admin" />'.NL;
echo '<input type="hidden" name="page" value="removeold" />'.NL;
echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'.NL;
echo '<div class="removeold__divinput">';
echo '<textarea type="text" name="removeold_w" class="edit removeold_edit" value="'.$_REQUEST['removeold_w'].'" rows="20" cols="50" />'.$deleted_files.'</textarea><br />'.NL;
echo '<input type="checkbox" name="dryrun" checked="checked">&nbsp;'.$this->getLang('i_dryrun').'&nbsp;</input><br />'.NL;
echo '<input type="checkbox" name="summary_only" >&nbsp;'.$this->getLang('summary_option').'&nbsp;</input><br />'.NL;
echo '<div class="removeold__divright">';
echo '<input type="submit" value="'.$this->getLang('btn_start').'" class="button"/>';
echo '</div>'.NL;
echo '</div>'.NL;
echo '</form>'.NL;
echo '</fieldset>';
echo '</div>'.NL;
echo '</div>'.NL;
echo '<div style="clear:both"></div>'.NL;
}
else {
msg("File not found: ".$deleted_files,-1);
}
}

/******************************************************************************/
/**
* This function will loop through the given files.
* It checks if the entry is not empty or comment and if such a file does exist.
* If the file does exist then it will be deleted. The result will be stored
* into the filelist array for user feddback.
*/
function _list_removeold_files($afilelist, $dryrun, $summary_option){
# statistic counters
# $empty = count empty lines
# $comments = count comments
# $files_found = count existing files
# $files_notFound = count missing files
# $files_deleted = count deleted files
# $files_delError = count files impossible to delete

$filelist = explode(chr(10),$afilelist);
echo '<div class="level4" id="removeold__input"><p>'.NL;

foreach($filelist as &$file) {
$file = trim($file);
# check if item is empty => continue, do nothing
if(strlen($file)<1) { $empty++; continue; }
# check if item is comment => continue, do nothing
if(stripos($file,"#")===0) { $comments++; continue; }
# check if file does exist
if(file_exists(DOKU_INC.$file)===true) {
# delete file (except on dryrun)
$files_found++;
$result = $this->getLang('exists');

if(($dryrun==true) && ($this->is__writable(DOKU_INC.$file)==true)) {
$result = $this->getLang('deleted');
$files_deleted++;
}
elseif(($dryrun==true) && ($this->is__writable(DOKU_INC.$file)===false)) {
$result = $this->getLang('delError');
$files_delError++;
}

if($dryrun==false) {
$result = unlink(DOKU_INC.$file);
if($result === true) {
$result = $this->getLang('deleted');
$files_deleted++;
}
else {
$result = $this->getLang('delError');
$files_delError++;
}
}
}
else {
# file not found
$result = $this->getLang('not_found');
}
# echo file and result
if($summary_option==false) {
echo DOKU_INC.$file."<span style=\"float:right;\">".$result."</span><br />".NL;
}
# write log on delete and error if execution mode
if(($result===$this->getLang('delError')) || ($result === $this->getLang('deleted'))) {
if($dryrun==false) $this->__removeold_logging($file, $result);
}
}
echo '</p></div><br />'.NL;
echo '<div class="level4"><strong><div class="it__standard_feedback">'.$this->getLang('removeold_summary').'</div></strong>';
echo '<div class="level2">'.NL;
echo '<table><tr><td>'.$this->getLang('exists').': </td><td>'.$files_found.'</td></tr>'.NL;
echo '<tr><td>'.$this->getLang('deleted').': </td><td>'.$files_deleted.'</td></tr>'.NL;
echo '<tr><td>'.$this->getLang('delError').' </td><td>'.$files_delError.'</td></tr></table>'.NL;

echo '</div><br />'.NL;
public function log($level, $msg)
{
if ($level === 'debug') return; // skip debugging
echo '<div class="' . $level . '">' . hsc($msg) . '</div>';
}
/******************************************************************************/
# Since looks like the Windows ACLs bug "wont fix"
# (see http://bugs.php.net/bug.php?id=27609)
# alternative function proposed on php.net:
function is__writable($path) {
if ($path{strlen($path)-1}=='/')
return is__writable($path.uniqid(mt_rand()).'.tmp');

if (file_exists($path)) {
if (!($f = @fopen($path, 'r+')))
return false;
fclose($f);
return true;
}

if (!($f = @fopen($path, 'w')))
return false;
fclose($f);
unlink($path);
return true;
}
/******************************************************************************/
/* logging of deleted files and deletion errors */
function __removeold_logging($file, $result) {
global $conf;
$timestamp = date('d/M/Y G:i:s');
if(is_dir($conf["savedir"])=== false) {
$log_file = DOKU_INC."/".$conf["savedir"].'/tmp/removeold.log';
}
else $log_file = $conf["savedir"].'/tmp/removeold.log';

$record = "[".$timestamp."]".chr(9).$result.chr(9).chr(9).$file.chr(10);

// Save logging records
$fh = fopen($log_file, 'a+');
if (!fwrite($fh, $record)) {
echo "<span style=\"color:red;\">".$this->getLang('ro_err_msg')."</span><br />".NL;
}
fclose($fh);
}
/******************************************************************************/
}
1 change: 1 addition & 0 deletions admin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use dokuwiki\Extension\CLIPlugin;
use splitbrain\phpcli\Options;

/**
* DokuWiki Plugin removeold (CLI Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
*/
class cli_plugin_removeold extends CLIPlugin
{
/** @inheritDoc */
protected function setup(Options $options)
{
$options->setHelp('Remove outdated files after upgrade');

$options->registerOption('exec', 'Actually execute the deletion, otherwise only print what would be deleted', 'e');
}

/** @inheritDoc */
protected function main(Options $options)
{
$remover = new helper_plugin_removeold($this);
$remover->run(!$options->getOpt('exec'));
}
}
Loading