Last active
September 4, 2017 06:47
-
-
Save phy25/871390a4816eef9b9db634c3bd96c1c5 to your computer and use it in GitHub Desktop.
dokuwiki-plugin-fixcontrib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin fixcontrib | |
* | |
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) | |
* @author Phy <dokuwiki.fixcontrib@phy25.com> | |
*/ | |
// must be run within Dokuwiki | |
if(!defined('DOKU_INC')) die(); | |
class admin_plugin_fixcontrib extends DokuWiki_Admin_Plugin { | |
var $output = ''; | |
var $_metaPath = ''; | |
function __construct(){ | |
global $conf; | |
$this->_metaPath = $conf['metadir']; | |
} | |
/** | |
* handle user request | |
*/ | |
function handle() { | |
global $INPUT; | |
if (!$INPUT->str('cmd')) return; // first time - nothing to do | |
$this->output = 'invalid'; | |
if (!checkSecurityToken()) return; | |
if($INPUT->str('cmd') == 'fix'){ | |
$this->output = ''; | |
$this->fix(); | |
} | |
} | |
/** | |
* output appropriate html | |
*/ | |
function html() { | |
global $auth; | |
ptln('<form action="'.wl($ID).'" method="post">'); | |
// output hidden values to ensure dokuwiki will return back to this plugin | |
ptln(' <input type="hidden" name="do" value="admin" />'); | |
ptln(' <input type="hidden" name="page" value="'.$this->getPluginName().'" />'); | |
ptln(' <input type="hidden" name="cmd" value="fix" />'); | |
formSecurityToken(); | |
ptln(' <button type="submit">Fix</button>'); | |
ptln('</form>'); | |
ptln('<p>'.$this->output.'</p>'); | |
} | |
function fix() { | |
global $conf; | |
$data = array(); | |
search($data, $conf['metadir'], array($this, '_search_list_loop'), array()); | |
foreach($data as $line){ | |
$this->output .= $line.'<br />'; | |
} | |
} | |
function _search_list_loop(&$data,$base,$file,$type,$lvl,$opts){ | |
global $auth; | |
// traverse | |
if($type == 'd'){ | |
return true; | |
} | |
if(substr($file,-5) == '.meta'){ | |
$meta = unserialize(io_readFile($base.$file, false)); | |
if(!empty($meta['current']['contributor']) || !empty($meta['persistent']['contributor'])){ | |
// generate first | |
$c = array(); | |
$changelog_file = io_readFile($base.substr($file, 0, -5).'.changes', false); | |
$changelog = explode("\n", $changelog_file); | |
foreach($changelog as $l){ | |
$l_array = explode("\t", $l); | |
if(!empty($l_array[4])){ | |
$c[$l_array[4]] = $l_array[4]; | |
} | |
} | |
// ID to name | |
foreach ($c as $key => $value) { | |
$info = $auth->getUserData($key); | |
if(!empty($info['name'])){ | |
$c[$key] = $info['name']; | |
}elseif($info == false){ | |
unset($c[$key]); | |
} | |
} | |
// put back | |
if(!empty($meta['current']['contributor'])) $meta['current']['contributor'] = $c; | |
if(!empty($meta['persistent']['contributor'])) $meta['persistent']['contributor'] = $c; | |
io_saveFile($base.$file, serialize($meta)); | |
$data[] = $base.$file.': Rebuilt '.count($c).' contributors'; | |
} | |
} | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base fixcontrib | |
author Phy | |
email dokuwiki.fixcontrib@phy25.com | |
date 2017-08-25 | |
name Fix contributors in meta | |
desc Helps to fix contributors array in meta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment