1<?php 2 3/** 4 * All DokuWiki plugins to extend the admin function 5 * need to inherit from this class 6 */ 7class admin_plugin_userhistory extends DokuWiki_Admin_Plugin { 8 9 function admin_plugin_userhistory ( ) { 10 $this->setupLocale ( ); 11 } 12 13 /** 14 * return sort order for position in admin menu 15 */ 16 function getMenuSort ( ) { 17 return 999; 18 } 19 20 /** 21 * handle user request 22 */ 23 function handle ( ) { 24 } 25 26 /** 27 * output appropriate html 28 */ 29 function _userList ( ) { 30 global $auth; 31 global $ID; 32 33 $user_list = $auth->retrieveUsers ( ); 34 35 echo ( '<h2 id="'.str_replace ( array ( " ", "'" ), "_", strtolower ( $this->getLang ( 'list' ) ) ).'">'.$this->getLang ( 'list' ).'</h2>' ); 36 37 echo ( '<div class = "editor_list"><p class = "editor_counter">'.$this->getLang ( 'total' ).': '.count ( $user_list ).'</p><ol>' ); 38 foreach ( $user_list as $key => $value ) { 39 $nick = $key; 40 $name = $value['name']; 41 $href = wl ( $ID ). ( strpos ( wl ( $ID ), '?' )?'&':'?' ).'do=admin&page='.$this->getPluginName ( ).'&user='.hsc ( $nick ); 42 echo ( '<li><a href = "'.$href.'">'.$nick.' - '.$name.'</li>' ); 43 } 44 echo ( '</ol></div>' ); 45 } 46 47 function _getChanges ( $user ) { 48 global $conf; 49 50 function globr ( $dir, $pattern ) { 51 $files = glob ( $dir.'/'.$pattern ); 52 $subdirs = glob ( $dir.'/*', GLOB_ONLYDIR ); /* Rework by bugmenot2 */ 53 if ( !empty ( $subdirs ) ) { 54 foreach ( $subdirs as $subdir ) { 55 $subfiles = globr ( $subdir, $pattern ); 56 if ( !empty ( $subfiles ) && !empty ( $files ) ) { 57 $files = array_merge ( $files, $subfiles ); 58 } 59 } 60 } 61 return $files; 62 } 63 64 $changes = array ( ); 65 $alllist = globr ( $conf['metadir'], '*.changes' ); 66 $skip = array ( '_comments.changes', '_dokuwiki.changes' ); 67 68 for ( $i = 0; $i < count ( $alllist ); $i++ ) { /* for all files */ 69 $fullname = $alllist[$i]; 70 $filepart = basename ( $fullname ); 71 if ( in_array ( $filepart, $skip ) ) continue; 72 73 $f = file ( $fullname ); 74 for ( $j = 0; $j < count ( $f ); $j++ ) { /* for all lines */ 75 $line = $f[$j]; 76 $change = dokuwiki\ChangeLog\ChangeLog::parseLogLine ( $line ); 77 if ( strtolower ( $change['user'] ) == strtolower ( $user ) ) $changes[] = $change; 78 } 79 } 80 81 function cmp ( $a, $b ) { 82 $time1 = $a['date']; 83 $time2 = $b['date']; 84 if ( $time1 == $time2 ) { return 0; } 85 return ( $time1 < $time2 ? 1 : -1 ); 86 } 87 88 uasort ( $changes, 'cmp' ); 89 90 return $changes; 91 } 92 93 function _userHistory ( $user ) { 94 global $conf; 95 global $ID; 96 global $lang; 97 98 $href = wl ( $ID ). ( strpos ( wl ( $ID ), '?' )?'&':'?' ).'do=admin&page='.$this->getPluginName ( ); 99 echo ( '<p><a href = "'.$href.'">['.$this->getLang('back').']</a></p>' ); 100 echo ( '<h2>'.$user.'</h2>' ); 101 $changes = array_values ( $this->_getChanges ( $user ) ); 102 echo ( '<div class = "edit_list"><p class = "edit_counter">'.$this->getLang ( 'total' ).': '.count ( $changes ).'</p><ol>' ); 103 104 foreach ( $changes as $key => $change ) { 105 if ( $key == 1000 ) { /* long list limiter */ 106 break; 107 }; 108 $date = strftime ( $conf['dformat'], $change['date'] ); 109 echo ( $change['type'] === 'e' ? '<li class = "minor">' : '<li>' ); 110 echo ( '<div class = "li"><span class="date">'.$date.'</span>' ); 111 $p = array ( ); 112 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 113 $p['title'] = $lang['diff']; 114 $p['alt'] = $lang['diff']; 115 $att = buildAttributes ( $p ); 116 echo ( '<a class = "diff_link" href = "'.wl ( $change['id'], "do=diff&rev=".$change['date'] ).'"><img '.$att.' /></a>' ); 117 $p['src'] = DOKU_BASE.'lib/images/history.png'; 118 $p['title'] = $lang['btn_revs']; 119 $p['alt'] = $lang['btn_revs']; 120 $att = buildAttributes ( $p ); 121 echo ( '<a class = "revisions_link" href = "'.wl ( $change['id'], "do=revisions" ).'"><img '.$att.' /></a> ' ); 122 echo ( $change['id'].' – '.html_wikilink ( ':'.$change['id'], $conf['useheading'] ? NULL : $change['id'] ) ); 123 if ( $change['sum'] != "" ) { 124 echo ( ' – '.hsc ( $change['sum'] ) ); 125 }; 126 echo ( '</div></li>' ); 127 } 128 echo ( '</ol></div>' ); 129 } 130 131 function html ( ) { 132 echo ( '<h1 id="'.str_replace ( array ( " ", "'" ), "_", strtolower ( $this->getLang ( 'menu' ) ) ).'">'.$this->getLang ( 'menu' ).'</h1>' ); 133 134 if ( isset ( $_REQUEST['user'] ) ) { 135 $this->_userHistory ( $_REQUEST['user'] ); 136 } else { 137 $this->_userList ( ); 138 } 139 } 140 141} 142