From d038d001032b8d51102f5506e7d3c33d59774b7d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2024 11:19:56 +0100 Subject: [PATCH 1/5] initial cleanup --- .gitattributes | 2 + INFO | 8 -- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++ README | 45 ++++--- admin.php | 81 ++++++------ plugin.info.txt | 4 +- 6 files changed, 407 insertions(+), 72 deletions(-) create mode 100644 .gitattributes delete mode 100644 INFO create mode 100644 LICENSE diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..050b5e0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/.* export-ignore +/_test export-ignore diff --git a/INFO b/INFO deleted file mode 100644 index f4daec8..0000000 --- a/INFO +++ /dev/null @@ -1,8 +0,0 @@ -# PLUGIN INFO - DO NOT EDIT! - -author Taggic -email taggic@t-online.de -date 2016-07-07 -name removeold -desc to remove outdated files (https://raw.githubusercontent.com/splitbrain/dokuwiki/stable/data/deleted.files) -url https://www.dokuwiki.org/plugin:removeold diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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; either version 2 of the License, or + (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README b/README index 361e635..2a4c8e0 100644 --- a/README +++ b/README @@ -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 -*/ - -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 \ No newline at end of file +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 + +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 diff --git a/admin.php b/admin.php index 8e2160d..591548a 100644 --- a/admin.php +++ b/admin.php @@ -5,15 +5,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Taggic */ -/******************************************************************************/ -// 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 @@ -21,21 +13,21 @@ class admin_plugin_removeold extends DokuWiki_Admin_Plugin { function getInfo(){ return confToHash(dirname(__FILE__).'/plugin.info.txt'); } -/******************************************************************************/ + /** * 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 * @@ -46,7 +38,7 @@ function getMenuSort() { function handle() { global $ID; } -/******************************************************************************/ + /** * removeold Output function * @@ -72,17 +64,17 @@ function html() { $filelist = $_REQUEST['removeold_w']; $dryrun = $_REQUEST['dryrun']; $summary_option = $_REQUEST['summary_only']; - + // language given? if ($filelist!=false) { if (($dryrun==true) && ($summary_option==false)) { - echo '
'.$this->getLang('removeold_willmsg').'

'; + echo '
'.$this->getLang('removeold_willmsg').'

'; } elseif ($summary_option==false) { echo '
'.$this->getLang('removeold_delmsg').'

'; } - - $this->_list_removeold_files($filelist, $dryrun, $summary_option); + + $this->_list_removeold_files($filelist, $dryrun, $summary_option); } echo '
'.NL; echo '
'.NL; @@ -92,11 +84,11 @@ function html() { echo '
'.NL; } -/******************************************************************************/ + /** * Display the form with input control to let the user specify * the files to be deleted - * + * * @author Taggic */ function _html_uinput(){ @@ -135,15 +127,14 @@ function _html_uinput(){ 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. + * 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){ + function _list_removeold_files($afilelist, $dryrun, $summary_option){ # statistic counters # $empty = count empty lines # $comments = count comments @@ -151,10 +142,10 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ # $files_notFound = count missing files # $files_deleted = count deleted files # $files_delError = count files impossible to delete - + $filelist = explode(chr(10),$afilelist); echo '

'.NL; - + foreach($filelist as &$file) { $file = trim($file); # check if item is empty => continue, do nothing @@ -162,11 +153,11 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ # 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) { + 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++; @@ -175,7 +166,7 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ $result = $this->getLang('delError'); $files_delError++; } - + if($dryrun==false) { $result = unlink(DOKU_INC.$file); if($result === true) { @@ -206,33 +197,37 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ echo '

'.NL; echo ''.NL; echo ''.NL; - echo '
'.$this->getLang('exists').': '.$files_found.'
'.$this->getLang('deleted').': '.$files_deleted.'
'.$this->getLang('delError').' '.$files_delError.'
'.NL; - - echo '

'.NL; + echo ''.$this->getLang('delError').' '.$files_delError.''.NL; + + echo '

'.NL; } -/******************************************************************************/ -# Since looks like the Windows ACLs bug "wont fix" -# (see http://bugs.php.net/bug.php?id=27609) -# alternative function proposed on php.net: + + /** + * 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 */ + + /** + * logging of deleted files and deletion errors + */ function __removeold_logging($file, $result) { global $conf; $timestamp = date('d/M/Y G:i:s'); @@ -240,15 +235,15 @@ function __removeold_logging($file, $result) { $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 "".$this->getLang('ro_err_msg')."
".NL; } fclose($fh); - } -/******************************************************************************/ + } + } diff --git a/plugin.info.txt b/plugin.info.txt index 99f93bf..2c5fd9b 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,9 +1,7 @@ -# PLUGIN INFO - DO NOT EDIT! - base removeold author Taggic email taggic@t-online.de date 2016-07-07 name removeold -desc to remove outdated files (https://raw.githubusercontent.com/splitbrain/dokuwiki/stable/data/deleted.files) +desc This is an admin plugin to remove outdated files url https://www.dokuwiki.org/plugin:removeold From 5fe5f8d11e006d8c8aabe504ad4289abbc0cfd6c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2024 11:20:52 +0100 Subject: [PATCH 2/5] autofixing --- admin.php | 264 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 137 insertions(+), 127 deletions(-) diff --git a/admin.php b/admin.php index 591548a..27cae70 100644 --- a/admin.php +++ b/admin.php @@ -1,30 +1,36 @@ administration function * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Taggic */ - -class admin_plugin_removeold extends DokuWiki_Admin_Plugin { +class admin_plugin_removeold extends AdminPlugin +{ /** * return some info */ - function getInfo(){ - return confToHash(dirname(__FILE__).'/plugin.info.txt'); + public function getInfo() + { + return confToHash(__DIR__ . '/plugin.info.txt'); } /** * return prompt for admin menu */ - function getMenuText($language) { + public function getMenuText($language) + { return $this->getLang('admin_removeold'); } /** * return sort order for position in admin menu */ - function getMenuSort() { + public function getMenuSort() + { return 20; } @@ -35,7 +41,8 @@ function getMenuSort() { * * @author Taggic */ - function handle() { + public function handle() + { global $ID; } @@ -46,43 +53,43 @@ function handle() { * * @author Taggic */ - function html() { + public function html() + { global $ID; - echo '
'.NL; - echo '

'.$this->getLang('admin_removeold').'

'.NL; - echo '
'.NL; + echo '
' . NL; + echo '

' . $this->getLang('admin_removeold') . '

' . NL; + echo '
' . NL; - echo '
'.NL; + echo '
' . NL; echo $this->locale_xhtml('help'); - echo '
'.NL; + echo '
' . NL; - echo '
'.NL; + echo '
' . NL; $this->_html_uinput(); - echo '
'.NL; + echo '
' . NL; - $filelist = $_REQUEST['removeold_w']; - $dryrun = $_REQUEST['dryrun']; + $filelist = $_REQUEST['removeold_w']; + $dryrun = $_REQUEST['dryrun']; $summary_option = $_REQUEST['summary_only']; // language given? - if ($filelist!=false) { - if (($dryrun==true) && ($summary_option==false)) { - echo '
'.$this->getLang('removeold_willmsg').'

'; - } - elseif ($summary_option==false) { - echo '
'.$this->getLang('removeold_delmsg').'

'; + if ($filelist != false) { + if (($dryrun == true) && ($summary_option == false)) { + echo '
' . $this->getLang('removeold_willmsg') . '

'; + } elseif ($summary_option == false) { + echo '
' . $this->getLang('removeold_delmsg') . '

'; } $this->_list_removeold_files($filelist, $dryrun, $summary_option); } - echo '
'.NL; - echo '
'.NL; - echo '1)'.NL; + echo '
' . NL; + echo '
' . NL; + echo '1)' . NL; echo $this->getLang('p_include'); - echo '
'.NL; + echo '
' . NL; - echo '
'.NL; + echo '
' . NL; } /** @@ -91,50 +98,50 @@ function html() { * * @author Taggic */ - function _html_uinput(){ + public 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 '
'.$this->getLang('i_choose').'
'.NL; - echo '
'.NL; - echo '
'.$this->getLang('i_legend').''.NL; - echo '
'; - echo ''.NL; - echo ''.NL; - echo ''.NL; - echo '
'; - echo '
'.NL; - echo ' '.$this->getLang('i_dryrun').' 
'.NL; - echo ' '.$this->getLang('summary_option').' 
'.NL; - echo '
'; - echo ''; - echo '
'.NL; - echo '
'.NL; - echo '
'.NL; - echo '
'; - echo '
'.NL; - echo '
'.NL; - echo '
'.NL; - } - else { - msg("File not found: ".$deleted_files,-1); + 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 '
' . $this->getLang('i_choose') . '
' . NL; + echo '
' . NL; + echo '
' . $this->getLang('i_legend') . '' . NL; + echo '
'; + echo '' . NL; + echo '' . NL; + echo '' . NL; + echo '
'; + echo '
' . NL; + echo ' ' . $this->getLang('i_dryrun') . ' 
' . NL; + echo ' ' . $this->getLang('summary_option') . ' 
' . NL; + echo '
'; + echo ''; + echo '
' . NL; + echo '
' . NL; + echo '
' . NL; + echo '
'; + echo '
' . NL; + echo '
' . NL; + echo '
' . 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){ + /** + * 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. + */ + public function _list_removeold_files($afilelist, $dryrun, $summary_option) + { # statistic counters # $empty = count empty lines # $comments = count comments @@ -143,63 +150,66 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ # $files_deleted = count deleted files # $files_delError = count files impossible to delete - $filelist = explode(chr(10),$afilelist); - echo '

'.NL; + $filelist = explode(chr(10), $afilelist); + echo '

' . NL; - foreach($filelist as &$file) { + foreach ($filelist as &$file) { $file = trim($file); # check if item is empty => continue, do nothing - if(strlen($file)<1) { $empty++; continue; } + if (strlen($file) < 1) { + $empty++; + continue; + } # check if item is comment => continue, do nothing - if(stripos($file,"#")===0) { $comments++; continue; } + if (stripos($file, "#") === 0) { + $comments++; + continue; + } # check if file does exist - if(file_exists(DOKU_INC.$file)===true) { + if (file_exists(DOKU_INC . $file)) { # 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 == 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) { + if ($dryrun == false) { + $result = unlink(DOKU_INC . $file); + if ($result) { $result = $this->getLang('deleted'); $files_deleted++; - } - else { + } else { $result = $this->getLang('delError'); $files_delError++; } } - } - else { + } else { # file not found $result = $this->getLang('not_found'); } # echo file and result - if($summary_option==false) { - echo DOKU_INC.$file."".$result."
".NL; + if ($summary_option == false) { + echo DOKU_INC . $file . "" . $result . "
" . 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); + if (($result === $this->getLang('delError')) || ($result === $this->getLang('deleted'))) { + if ($dryrun == false) $this->__removeold_logging($file, $result); } } - echo '


'.NL; - echo '
'.$this->getLang('removeold_summary').'
'; - echo '
'.NL; - echo ''.NL; - echo ''.NL; - echo '
'.$this->getLang('exists').': '.$files_found.'
'.$this->getLang('deleted').': '.$files_deleted.'
'.$this->getLang('delError').' '.$files_delError.'
'.NL; - - echo '

'.NL; + echo '


' . NL; + echo '
' . $this->getLang('removeold_summary') . '
'; + echo '
' . NL; + echo '' . NL; + echo '' . NL; + echo '
' . $this->getLang('exists') . ': ' . $files_found . '
' . $this->getLang('deleted') . ': ' . $files_deleted . '
' . $this->getLang('delError') . ' ' . $files_delError . '
' . NL; + + echo '

' . NL; } /** @@ -207,43 +217,43 @@ function _list_removeold_files($afilelist, $dryrun, $summary_option){ * (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'); + public 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, 'r+'))) + return false; + fclose($f); + return true; + } if (!($f = @fopen($path, 'w'))) - return false; - fclose($f); - unlink($path); - return true; - } + 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 "".$this->getLang('ro_err_msg')."
".NL; - } - fclose($fh); - } + public 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 "" . $this->getLang('ro_err_msg') . "
" . NL; + } + fclose($fh); + } } From f191867786724875caeeab9d428510473942d2b3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2024 11:22:23 +0100 Subject: [PATCH 3/5] remove unneeded methods --- admin.php | 41 ++--------------------------------------- admin.svg | 1 + lang/de/lang.php | 4 ++-- lang/en/lang.php | 4 ++-- lang/ja/lang.php | 4 ++-- 5 files changed, 9 insertions(+), 45 deletions(-) create mode 100644 admin.svg diff --git a/admin.php b/admin.php index 27cae70..7e040c8 100644 --- a/admin.php +++ b/admin.php @@ -10,52 +10,15 @@ */ class admin_plugin_removeold extends AdminPlugin { - /** - * return some info - */ - public function getInfo() - { - return confToHash(__DIR__ . '/plugin.info.txt'); - } - - /** - * return prompt for admin menu - */ - public function getMenuText($language) - { - return $this->getLang('admin_removeold'); - } - /** - * return sort order for position in admin menu - */ - public function getMenuSort() - { - return 20; - } - /** - * handle user request - * - * Initializes internal vars and handles modifications - * - * @author Taggic - */ - public function handle() - { - global $ID; - } /** - * removeold Output function - * - * print a table with all found lanuage folders - * - * @author Taggic + * @inheritdoc + * print a table with all found language folders */ public function html() { - global $ID; echo '
' . NL; echo '

' . $this->getLang('admin_removeold') . '

' . NL; diff --git a/admin.svg b/admin.svg new file mode 100644 index 0000000..41c246e --- /dev/null +++ b/admin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lang/de/lang.php b/lang/de/lang.php index 03fa2f1..613f81f 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -5,7 +5,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Taggic */ -$lang['admin_removeold'] = 'Remove outdated files'; +$lang['menu'] = 'Remove outdated files'; $lang['p_include'] = 'Bitte kopieren sie die Liste der veralteten Datein in folgendes Textfeld.'; $lang['i_choose'] = 'Ein leeres Eingabefeld hat keine Auswirkung auf Ihr System.
'; $lang['i_legend'] = 'Inhalt von removeold - hier einfügen'; @@ -21,4 +21,4 @@ $lang['deleted'] = 'Datei gelöscht'; $lang['delError'] = '! FEHLER ! '; $lang['erased'] = 'Cache gelöscht'; -$lang['ro_err_msg'] = 'LOG SCHREIBFEHLER ! Dem Log-File können keine Einträge hinzugefügt werden.'; \ No newline at end of file +$lang['ro_err_msg'] = 'LOG SCHREIBFEHLER ! Dem Log-File können keine Einträge hinzugefügt werden.'; diff --git a/lang/en/lang.php b/lang/en/lang.php index 2bf3ebd..bff875d 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -5,7 +5,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Taggic */ -$lang['admin_removeold'] = 'Remove outdated files'; +$lang['menu'] = 'Remove outdated files'; $lang['p_include'] = 'Please copy the list of outdated files into the textarea.'; $lang['i_choose'] = 'An empty input field will not cause any effect to prevent misuse/mistakes.
'; $lang['i_legend'] = 'Insert the removeold - file content here'; @@ -21,4 +21,4 @@ $lang['deleted'] = 'Files deleted'; $lang['delError'] = '! ERROR ! '; $lang['erased'] = 'Cache erased'; -$lang['ro_err_msg'] = 'LOG WRITE ERROR ! Can\'t write to the log file.'; \ No newline at end of file +$lang['ro_err_msg'] = 'LOG WRITE ERROR ! Can\'t write to the log file.'; diff --git a/lang/ja/lang.php b/lang/ja/lang.php index e7a3223..243fffe 100644 --- a/lang/ja/lang.php +++ b/lang/ja/lang.php @@ -4,8 +4,8 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * */ - -$lang['admin_removeold'] = '古いファイルの削除'; + +$lang['menu'] = '古いファイルの削除'; $lang['p_include'] = 'textarea に古いファイルの一覧をコピーしてください。'; $lang['i_choose'] = 'misuse/mistakes を防ぐため、入力フィールドが空の場合は何もしません。
'; $lang['i_legend'] = '未使用ファイルの内容をここに入力してください。'; From 082cfbdad4457ebbd9cf4a4f467f4ac8081f2ad0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2024 13:27:47 +0100 Subject: [PATCH 4/5] the big refactor * automatically load all deleted.files, no more copy'n'paste * add CLI component * simplify the whole interface * remove all unnessary cruft --- VERSION | 1 - admin.php | 214 +++++-------------------------------------- cli.php | 27 ++++++ helper.php | 138 ++++++++++++++++++++++++++++ lang/en/intro.txt | 5 + lang/en/lang.php | 6 ++ lang/en/precheck.txt | 1 + style.css | 56 ----------- 8 files changed, 201 insertions(+), 247 deletions(-) delete mode 100644 VERSION create mode 100644 cli.php create mode 100644 helper.php create mode 100644 lang/en/intro.txt create mode 100644 lang/en/precheck.txt delete mode 100644 style.css diff --git a/VERSION b/VERSION deleted file mode 100644 index 1749501..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2016-07-07 \ No newline at end of file diff --git a/admin.php b/admin.php index 7e040c8..e287881 100644 --- a/admin.php +++ b/admin.php @@ -1,6 +1,7 @@ administration function @@ -10,213 +11,46 @@ */ class admin_plugin_removeold extends AdminPlugin { - - - /** * @inheritdoc - * print a table with all found language folders */ public function html() { + global $INPUT; - echo '
' . NL; - echo '

' . $this->getLang('admin_removeold') . '

' . NL; - echo '
' . NL; - - echo '
' . NL; - echo $this->locale_xhtml('help'); - echo '
' . NL; - - echo '
' . NL; - $this->_html_uinput(); - echo '
' . NL; - - $filelist = $_REQUEST['removeold_w']; - $dryrun = $_REQUEST['dryrun']; - $summary_option = $_REQUEST['summary_only']; - - // language given? - if ($filelist != false) { - if (($dryrun == true) && ($summary_option == false)) { - echo '
' . $this->getLang('removeold_willmsg') . '

'; - } elseif ($summary_option == false) { - echo '
' . $this->getLang('removeold_delmsg') . '

'; - } - - $this->_list_removeold_files($filelist, $dryrun, $summary_option); - } - echo '
' . NL; - echo '
' . NL; - echo '1)' . NL; - echo $this->getLang('p_include'); - echo '
' . NL; - - echo '
' . NL; - } + $helper = new helper_plugin_removeold($this); - /** - * Display the form with input control to let the user specify - * the files to be deleted - * - * @author Taggic - */ - public 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"); + echo $this->locale_xhtml('intro'); - if ($deleted_files !== "") { - echo '
' . $this->getLang('i_choose') . '
' . NL; - echo '
' . NL; - echo '
' . $this->getLang('i_legend') . '' . NL; - echo '
'; - echo '' . NL; - echo '' . NL; - echo '' . NL; - echo '
'; - echo '
' . NL; - echo ' ' . $this->getLang('i_dryrun') . ' 
' . NL; - echo ' ' . $this->getLang('summary_option') . ' 
' . NL; - echo '
'; - echo ''; - echo '
' . NL; - echo '
' . NL; - echo '
' . NL; - echo '
'; - echo '
' . NL; - echo '
' . NL; - echo '
' . NL; + echo '
'; + if ($INPUT->bool('exec')) { + echo '

' . $this->getLang('removeold_delmsg') . '

'; } else { - msg("File not found: " . $deleted_files, -1); - } - } + echo '

' . $this->getLang('removeold_willmsg') . '

'; - /** - * 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. - */ - public 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 '

' . 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)) { - # 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) { - $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 . "" . $result . "
" . 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 '


' . NL; - echo '
' . $this->getLang('removeold_summary') . '
'; - echo '
' . NL; - echo '' . NL; - echo '' . NL; - echo '
' . $this->getLang('exists') . ': ' . $files_found . '
' . $this->getLang('deleted') . ': ' . $files_deleted . '
' . $this->getLang('delError') . ' ' . $files_delError . '
' . NL; - - echo '

' . NL; - } - - /** - * Since looks like the Windows ACLs bug "wont fix" - * (see http://bugs.php.net/bug.php?id=27609) - * alternative function proposed on php.net: - */ - public function is__writable($path) - { - if ($path[strlen($path) - 1] == '/') - return is__writable($path . uniqid(mt_rand()) . '.tmp'); + echo $this->locale_xhtml('precheck'); - if (file_exists($path)) { - if (!($f = @fopen($path, 'r+'))) - return false; - fclose($f); - return true; + echo '

'; + $form = new Form(); + $form->addButton('exec', $this->getLang('button')); + echo $form->toHTML(); + echo '

'; } - if (!($f = @fopen($path, 'w'))) - return false; - fclose($f); - unlink($path); - return true; + $helper->run(!$INPUT->bool('exec')); + echo '
'; } /** - * logging of deleted files and deletion errors + * Implement the logging interface + * + * @param string $level + * @param string $msg + * @return void */ - public function __removeold_logging($file, $result) + public function log($level, $msg) { - 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 "" . $this->getLang('ro_err_msg') . "
" . NL; - } - fclose($fh); + if ($level === 'debug') return; // skip debugging + echo '
' . hsc($msg) . '
'; } } diff --git a/cli.php b/cli.php new file mode 100644 index 0000000..2054002 --- /dev/null +++ b/cli.php @@ -0,0 +1,27 @@ +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')); + } +} diff --git a/helper.php b/helper.php new file mode 100644 index 0000000..4d389fc --- /dev/null +++ b/helper.php @@ -0,0 +1,138 @@ +logger = $logger; + } + + public function run($dryrun = true) + { + $files = $this->getDeletedFiles(); + foreach ($files as $base => $file) { + if (file_exists($file)) { + $list = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $this->deleteFiles($list, $base, $dryrun); + } + } + } + + protected function getDeletedFiles() + { + $files = [ + DOKU_INC => DOKU_INC . 'data/deleted.files', + ]; + + foreach (glob(DOKU_PLUGIN . '*', GLOB_ONLYDIR) as $plugin) { + $files[$plugin] = $plugin . 'deleted.files'; + } + + foreach (glob(DOKU_INC . 'lib/tpl/*', GLOB_ONLYDIR) as $template) { + $files[$template] = $template . '/deleted.files'; + } + + return $files; + } + + /** + * Delete the given files from the base + * @param string[] $list + * @param string $base + * @param bool $dryrun + * @return void + */ + protected function deleteFiles($list, $base, $dryrun = true) + { + $base = rtrim($base, '/') . '/'; + + foreach ($list as $line) { + $line = preg_replace('/\.\./', '', $line); // prevent directory traversal + $line = preg_replace('/#.*$/', '', $line); // remove comments + $line = str_replace('\\', '/', $line); // normalize windows paths + $line = trim($line); // remove leading/trailing whitespace + $line = ltrim($line, '/'); // remove leading slashes + if (!$line) continue; + + $file = $base . $line; + + // file does not exist, that's fine + if (!file_exists($file)) { + $this->log('debug', $this->getLang('rm_notfound'), $file); + continue; + } + + // check that the given file is a case sensitive match + if (basename(realpath($file)) !== basename($file)) { + $this->log('info', $this->getLang('rm_mismatch'), $file); + continue; + } + + if ( + $dryrun || + (is_dir($file) && $this->recursiveDelete($file)) || + @unlink($file) + ) { + $this->log('success', $this->getLang('rm_done'), $file); + } else { + $this->log('error', $this->getLang('rm_fail'), $file); + } + } + + // clear opcache + if (function_exists('opcache_reset')) { + opcache_reset(); + } + } + + /** + * Recursive delete + * + * @author Jon Hassall + * @link http://de.php.net/manual/en/function.unlink.php#87045 + */ + protected function recursiveDelete($dir) + { + if (!$dh = @opendir($dir)) { + return false; + } + while (false !== ($obj = readdir($dh))) { + if ($obj == '.' || $obj == '..') continue; + + if (!@unlink($dir . '/' . $obj)) { + $this->recursiveDelete($dir . '/' . $obj); + } + } + closedir($dh); + return @rmdir($dir); + } + + + /** + * Log a message + * + * @param string $level + * @param $msg + * @param mixed ...$args + */ + protected function log($level, $msg, ...$args) + { + $msg = vsprintf($msg, $args); + if ($this->logger) { + $this->logger->log($level, $msg); + } else { + echo $msg; + } + } +} diff --git a/lang/en/intro.txt b/lang/en/intro.txt new file mode 100644 index 0000000..40ceb1d --- /dev/null +++ b/lang/en/intro.txt @@ -0,0 +1,5 @@ +====== Remove outdated files ====== + +This plugin allows you to removed outdated files from the DokuWiki core as well as from all installed extensions. + +Running this is usually only needed when you did manual updates or installations. diff --git a/lang/en/lang.php b/lang/en/lang.php index bff875d..14cfb7f 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -22,3 +22,9 @@ $lang['delError'] = '! ERROR ! '; $lang['erased'] = 'Cache erased'; $lang['ro_err_msg'] = 'LOG WRITE ERROR ! Can\'t write to the log file.'; + +$lang['button'] = 'Delete obsolete files!'; +$lang['rm_notfound'] = 'Not found: %s'; +$lang['rm_mismatch'] = 'Case mismatch: %s'; +$lang['rm_done'] = 'Deleted: %s'; +$lang['rm_fail'] = 'Failed to delete: %s'; diff --git a/lang/en/precheck.txt b/lang/en/precheck.txt new file mode 100644 index 0000000..37f9394 --- /dev/null +++ b/lang/en/precheck.txt @@ -0,0 +1 @@ +Below you can see a simulation of files that would be deleted. Check if everything looks fine, then hit the button to actually delete the files. diff --git a/style.css b/style.css deleted file mode 100644 index 3cb3df8..0000000 --- a/style.css +++ /dev/null @@ -1,56 +0,0 @@ -/* ----- General Elements ---------- */ -.it__negative_feedback { - border: 1px red solid; - background-color: white; - margin: 0px; - padding: 10px; - width: 60%; - border-radius: 0.5em; -} -.it__positive_feedback { - border: 1px green solid; - background-color: lightgreen; - margin: 0px; - padding: 10px; - width: 60%; - border-radius: 0.5em; -} - .it__standard_feedback { - width: 95%; - border: 1px solid #C0C0C0; - background: url("img/content-bg.jpg") repeat scroll 0 0 transparent; - padding: 3px; - padding-left: 0.45em; - border-radius: 4px; -} -/* ----- Input Elements ---------- */ -div .removeold__divinput { - width: 95%; - text-align : left !important; -} - - .removeold__fieldset { - width: 100% !important; - margin-bottom: 2em !important; - text-align: left !important; - border-radius: 0.5em; - float: left; -} - -.removeold_edit { - width: 99% !important; - margin: 1em 1em 1em 0 !important; - font-size: 8pt !important; -} - -.removeold_i_legend { - padding: 0 0.5em 0 0.5em !important; -} - -div .removeold__divright { - text-align: right; -} - -.level4 p{ -width: 95% !important; -} \ No newline at end of file From 6f671a58d30894ee96bd4d44575b1420f74089b5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 12 Mar 2024 13:29:24 +0100 Subject: [PATCH 5/5] remove unused language strings --- lang/de/lang.php | 14 -------------- lang/en/lang.php | 14 -------------- lang/ja/lang.php | 14 -------------- 3 files changed, 42 deletions(-) diff --git a/lang/de/lang.php b/lang/de/lang.php index 613f81f..99d6471 100644 --- a/lang/de/lang.php +++ b/lang/de/lang.php @@ -6,19 +6,5 @@ * @author Taggic */ $lang['menu'] = 'Remove outdated files'; -$lang['p_include'] = 'Bitte kopieren sie die Liste der veralteten Datein in folgendes Textfeld.'; -$lang['i_choose'] = 'Ein leeres Eingabefeld hat keine Auswirkung auf Ihr System.
'; -$lang['i_legend'] = 'Inhalt von removeold - hier einfügen'; -$lang['i_dryrun'] = 'Simulation'; -$lang['btn_start'] = 'Start'; $lang['removeold_willmsg'] = 'SIMULATION: Die Dateien würden wie folgt verarbeitet.'; $lang['removeold_delmsg'] = 'Die Dateien wurden nun final wie folgt verarbeitet.'; -$lang['removeold_summary'] = 'Zusammenfassung'; -$lang['summary_option'] = 'Nur Zusammenfassung anzeigen !'; -$lang['cache_option'] = 'Cache komplett löschen'; -$lang['not_found'] = 'Datei nicht gefunden'; -$lang['exists'] = 'Datei existiert'; -$lang['deleted'] = 'Datei gelöscht'; -$lang['delError'] = '! FEHLER ! '; -$lang['erased'] = 'Cache gelöscht'; -$lang['ro_err_msg'] = 'LOG SCHREIBFEHLER ! Dem Log-File können keine Einträge hinzugefügt werden.'; diff --git a/lang/en/lang.php b/lang/en/lang.php index 14cfb7f..f81c0d9 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -6,22 +6,8 @@ * @author Taggic */ $lang['menu'] = 'Remove outdated files'; -$lang['p_include'] = 'Please copy the list of outdated files into the textarea.'; -$lang['i_choose'] = 'An empty input field will not cause any effect to prevent misuse/mistakes.
'; -$lang['i_legend'] = 'Insert the removeold - file content here'; -$lang['i_dryrun'] = 'simulate only'; -$lang['btn_start'] = 'Start'; $lang['removeold_willmsg'] = 'SIMULATION: The files would be processed as follows.'; $lang['removeold_delmsg'] = 'The files are finally processed as follows.'; -$lang['removeold_summary'] = 'Summary'; -$lang['summary_option'] = 'Show summary only !'; -$lang['cache_option'] = 'Erase cache completely'; -$lang['not_found'] = 'File not found'; -$lang['exists'] = 'Files exist'; -$lang['deleted'] = 'Files deleted'; -$lang['delError'] = '! ERROR ! '; -$lang['erased'] = 'Cache erased'; -$lang['ro_err_msg'] = 'LOG WRITE ERROR ! Can\'t write to the log file.'; $lang['button'] = 'Delete obsolete files!'; $lang['rm_notfound'] = 'Not found: %s'; diff --git a/lang/ja/lang.php b/lang/ja/lang.php index 243fffe..620d1b9 100644 --- a/lang/ja/lang.php +++ b/lang/ja/lang.php @@ -6,19 +6,5 @@ */ $lang['menu'] = '古いファイルの削除'; -$lang['p_include'] = 'textarea に古いファイルの一覧をコピーしてください。'; -$lang['i_choose'] = 'misuse/mistakes を防ぐため、入力フィールドが空の場合は何もしません。
'; -$lang['i_legend'] = '未使用ファイルの内容をここに入力してください。'; -$lang['i_dryrun'] = 'シミュレートのみ'; -$lang['btn_start'] = '開始'; $lang['removeold_willmsg'] = 'シミュレーション:ファイルは、以下のように処理されるでしょう。'; $lang['removeold_delmsg'] = 'ファイルは最終的に以下のように処理されます。'; -$lang['removeold_summary'] = '概要'; -$lang['summary_option'] = '概要のみ表示!'; -$lang['cache_option'] = 'キャッシュを完全に消去'; -$lang['not_found'] = 'ファイルが存在しない'; -$lang['exists'] = 'ファイルが存在する'; -$lang['deleted'] = 'ファイルが削除された'; -$lang['delError'] = '!エラー!'; -$lang['erased'] = 'キャッシュが消去された'; -$lang['ro_err_msg'] = 'ログ書込エラー! ログファイルに書き込めません。';