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