• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

PukiWiki


Commit MetaInfo

Revision9f1f2ad1239162c08fb6a301b102485ee6181b9c (tree)
Zeit2016-02-03 02:03:30
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

Merge branch 'bugtrack2374_record_page_author' into branch_r1_5

* Record '#author' line that shows text modified date and author
* Implement auth username prefix that shows its auth provider

  • Default list: 'default:', 'ldap:' and 'external:'

* Recoard Full name of author, it is included on '#author' info
* backup list shows its authors
* Hide author info when user edit wiki text

Ändern Zusammenfassung

Diff

--- a/lib/auth.php
+++ b/lib/auth.php
@@ -243,7 +243,8 @@ function basic_auth($page, $auth_flag, $exit_flag, $auth_pages, $title_cannot)
243243 function ensure_valid_auth_user()
244244 {
245245 global $auth_type, $auth_users, $_msg_auth, $auth_user, $auth_groups;
246- global $auth_user_groups;
246+ global $auth_user_groups, $auth_user_fullname;
247+ global $auth_provider_user_prefix;
247248 switch ($auth_type) {
248249 case AUTH_TYPE_BASIC:
249250 {
@@ -254,6 +255,7 @@ function ensure_valid_auth_user()
254255 $_SERVER['PHP_AUTH_PW'],
255256 $auth_users[$user]) === $auth_users[$user]) {
256257 $auth_user = $user;
258+ $auth_user_fullname = $auth_user;
257259 $auth_user_groups = get_groups_from_username($user);
258260 return true;
259261 }
@@ -269,22 +271,37 @@ function ensure_valid_auth_user()
269271 case AUTH_TYPE_EXTERNAL:
270272 {
271273 session_start();
272- // session_regenerate_id(true);
273274 $user = '';
275+ $fullname = '';
274276 if (isset($_SESSION['authenticated_user'])) {
275277 $user = $_SESSION['authenticated_user'];
278+ if (isset($_SESSION['authenticated_user_fullname'])) {
279+ $fullname = $_SESSION['authenticated_user_fullname'];
280+ } else {
281+ if ($auth_type === AUTH_TYPE_EXTERNAL && $ldap_user_account) {
282+ $ldap_user_info = ldap_get_simple_user_info($user);
283+ if ($ldap_user_info) {
284+ $fullname = $ldap_user_info['fullname'];
285+ $_SESSION['authenticated_user_fullname'] = $fullname;
286+ }
287+ }
288+ }
276289 }
277290 $auth_user = $user;
291+ $auth_user_fullname = $fullname;
278292 break;
279293 }
280294 case AUTH_TYPE_EXTERNAL_REMOTE_USER:
281295 $auth_user = $_SERVER['REMOTE_USER'];
296+ $auth_user_fullname = $auth_user;
282297 break;
283298 case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
284299 $auth_user = $_SERVER['HTTP_X_FORWARDED_USER'];
300+ $auth_user_fullname = $auth_user;
285301 break;
286302 default: // AUTH_TYPE_NONE
287303 $auth_user = '';
304+ $auth_user_fullname = '';
288305 break;
289306 }
290307 $auth_user_groups = get_groups_from_username($auth_user);
@@ -354,8 +371,10 @@ function form_auth($username, $password)
354371 if (pkwk_hash_compute(
355372 $password,
356373 $auth_users[$user]) === $auth_users[$user]) {
357- $_SESSION['authenticated_user'] = $user;
374+ session_start();
358375 session_regenerate_id(true); // require: PHP5.1+
376+ $_SESSION['authenticated_user'] = $user;
377+ $_SESSION['authenticated_user_fullname'] = $user;
359378 return true;
360379 }
361380 }
@@ -379,8 +398,9 @@ function ldap_auth($username, $password)
379398 if ($ldap_bind_user) {
380399 $user_info = get_ldap_user_info($ldapconn, $username, $ldap_base_dn);
381400 if ($user_info) {
382- $_SESSION['authenticated_user'] = $user_info['uid'];
383401 session_regenerate_id(true); // require: PHP5.1+
402+ $_SESSION['authenticated_user'] = $user_info['uid'];
403+ $_SESSION['authenticated_user_fullname'] = $user_info['fullname'];
384404 return true;
385405 }
386406 }
@@ -392,8 +412,9 @@ function ldap_auth($username, $password)
392412 if ($user_info) {
393413 $ldap_bind_user2 = ldap_bind($ldapconn, $user_info['dn'], $password);
394414 if ($ldap_bind_user2) {
395- $_SESSION['authenticated_user'] = $user_info['uid'];
396415 session_regenerate_id(true); // require: PHP5.1+
416+ $_SESSION['authenticated_user'] = $user_info['uid'];
417+ $_SESSION['authenticated_user_fullname'] = $user_info['fullname'];
397418 return true;
398419 }
399420 }
@@ -401,6 +422,30 @@ function ldap_auth($username, $password)
401422 }
402423 }
403424 }
425+ return false;
426+}
427+
428+// Get LDAP user info via bind DN
429+function ldap_get_simple_user_info($username)
430+{
431+ global $ldap_url, $ldap_bind_dn, $ldap_bind_password;
432+ if (preg_match('#^(ldap\:\/\/[^/]+/)(.*)$#', $ldap_url, $m)) {
433+ $ldap_server = $m[1];
434+ $ldap_base_dn = $m[2];
435+ $ldapconn = ldap_connect($ldap_server);
436+ if ($ldapconn) {
437+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
438+ // Bind by bind dn
439+ $ldap_bind = ldap_bind($ldapconn, $ldap_bind_dn, $ldap_bind_password);
440+ if ($ldap_bind) {
441+ $user_info = get_ldap_user_info($ldapconn, $username, $ldap_base_dn);
442+ if ($user_info) {
443+ return $user_info;
444+ }
445+ }
446+ }
447+ }
448+ return false;
404449 }
405450
406451 /**
--- a/lib/backup.php
+++ b/lib/backup.php
@@ -13,7 +13,7 @@
1313 * @create
1414 * @version $Id: backup.php,v 1.13 2011/01/25 15:01:01 henoheno Exp $
1515 * Copyright (C)
16- * 2002-2006 PukiWiki Developers Team
16+ * 2002-2016 PukiWiki Development Team
1717 * 2001-2002 Originally written by yu-ji
1818 * License: GPL v2 or (at your option) any later version
1919 **/
@@ -33,6 +33,7 @@ function make_backup($page, $delete = FALSE)
3333 {
3434 global $cycle, $maxage;
3535 global $do_backup, $del_backup;
36+ global $auth_user;
3637
3738 if (PKWK_READONLY || ! $do_backup) return;
3839
@@ -44,7 +45,22 @@ function make_backup($page, $delete = FALSE)
4445 if (! is_page($page)) return;
4546
4647 $lastmod = _backup_get_filetime($page);
47- if ($lastmod == 0 || UTIME - $lastmod > 60 * 60 * $cycle)
48+ $backups = get_backup($page);
49+ $is_author_differ = false;
50+ $need_backup_by_time = $lastmod == 0 || UTIME - $lastmod > 60 * 60 * $cycle;
51+ if (!$need_backup_by_time) {
52+ // Backup file is saved recently, but the author may differ.
53+ $last_content = get_source($page, FALSE, TRUE);
54+ $m = array();
55+ if (preg_match('/^\s*#author\("([^"]+)","([^"]+)","([^"]*)"\)/m', $last_content, $m)) {
56+ $prev_author = $m[2];
57+ $simple_author =preg_replace('/^[^:]:/', '', $prev_author);
58+ if ($simple_author !== $auth_user) {
59+ $is_author_differ = true;
60+ }
61+ }
62+ }
63+ if ($need_backup_by_time || $is_author_differ)
4864 {
4965 $backups = get_backup($page);
5066 $count = count($backups) + 1;
@@ -105,6 +121,11 @@ function get_backup($page, $age = 0)
105121
106122 // Allocate
107123 $retvars[$_age] = array('time'=>$match[1], 'data'=>array());
124+ } else if (preg_match('/^\s*#author\("([^"]+)","([^"]+)","([^"]*)"\)/', $line, $match)) {
125+ $retvars[$_age]['author_datetime'] = $match[1];
126+ $retvars[$_age]['author'] = $match[2];
127+ $retvars[$_age]['author_fullname'] = $match[3];
128+ $retvars[$_age]['data'][] = $line;
108129 } else {
109130 // The first ... the last line of the data
110131 $retvars[$_age]['data'][] = $line;
@@ -306,4 +327,3 @@ else
306327 array();
307328 }
308329 }
309-?>
--- a/lib/file.php
+++ b/lib/file.php
@@ -84,6 +84,7 @@ function page_write($page, $postdata, $notimestamp = FALSE)
8484 if (PKWK_READONLY) return; // Do nothing
8585
8686 $postdata = make_str_rules($postdata);
87+ $postdata = add_author_info(remove_author_info($postdata));
8788
8889 // Create and write diff
8990 $oldpostdata = is_page($page) ? join('', get_source($page)) : '';
@@ -158,6 +159,50 @@ function make_str_rules($source)
158159 return implode("\n", $lines);
159160 }
160161
162+function add_author_info($wikitext)
163+{
164+ global $auth_user, $auth_user_fullname, $auth_type, $ldap_user_account;
165+ $author = preg_replace('/"/', '', $auth_user);
166+ $displayname = preg_replace('/"/', '', $auth_user_fullname);
167+ $user_prefix = '';
168+ switch ($auth_type) {
169+ case AUTH_TYPE_BASIC:
170+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
171+ break;
172+ case AUTH_TYPE_EXTERNAL:
173+ case AUTH_TYPE_EXTERNAL_REMOTE_USER:
174+ case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
175+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_EXTERNAL;
176+ break;
177+ case AUTH_TYPE_FORM:
178+ if ($ldap_user_account) {
179+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_LDAP;
180+ } else {
181+ $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
182+ }
183+ break;
184+ }
185+ $author_text = sprintf('#author("%s","%s","%s")',
186+ get_date_atom(UTIME + LOCALZONE),
187+ ($author ? $user_prefix . $author : ''),
188+ $displayname) . "\n";
189+ return $author_text . $wikitext;
190+}
191+
192+function remove_author_info($wikitext)
193+{
194+ return preg_replace('/^\s*#author\([^\n]*(\n|$)/m', '', $wikitext);
195+}
196+
197+function get_date_atom($timestamp)
198+{
199+ // Compatible with DATE_ATOM format
200+ // return date(DATE_ATOM, $timestamp);
201+ $zmin = abs(LOCALZONE / 60);
202+ return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
203+ (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
204+}
205+
161206 // Generate ID
162207 function generate_fixed_heading_anchor_id($seed)
163208 {
--- /dev/null
+++ b/plugin/author.inc.php
@@ -0,0 +1,9 @@
1+<?php
2+// PukiWiki - Yet another WikiWikiWeb clone.
3+// author.inc.php
4+// Copyright: 2016 PukiWiki Development Team
5+// License: GPL v2 or (at your option) any later version
6+//
7+// author plugin
8+
9+function plugin_author_convert() { return ''; }
--- a/plugin/backup.inc.php
+++ b/plugin/backup.inc.php
@@ -1,8 +1,8 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone.
3-// $Id: backup.inc.php,v 1.29 2011/01/25 15:01:01 henoheno Exp $
3+// backup.inc.php
44 // Copyright (C)
5-// 2002-2005 PukiWiki Developers Team
5+// 2002-2016 PukiWiki Development Team
66 // 2001-2002 Originally written by yu-ji
77 // License: GPL v2 or (at your option) any later version
88 //
@@ -218,12 +218,17 @@ EOD;
218218 $_anchor_to = '</a>';
219219 }
220220 $date = format_date($data['time'], TRUE);
221+ $author_info = '';
222+ if (isset($data['author'])) {
223+ $author_info = htmlsc('by ' . $data['author_fullname']
224+ . '(' . $data['author'] . ')');
225+ }
221226 $retval[1] .= <<<EOD
222227 <li>$_anchor_from$age $date$_anchor_to
223228 [ <a href="$href$age&amp;action=diff">$_msg_diff</a>
224229 | <a href="$href$age&amp;action=nowdiff">$_msg_nowdiff</a>
225230 | <a href="$href$age&amp;action=source">$_msg_source</a>
226- ]
231+ ] $author_info
227232 </li>
228233 EOD;
229234 }
@@ -244,4 +249,3 @@ function plugin_backup_get_list_all($withfilename = FALSE)
244249 return page_list($pages, 'backup', $withfilename);
245250 }
246251 }
247-?>
--- a/plugin/edit.inc.php
+++ b/plugin/edit.inc.php
@@ -29,7 +29,7 @@ function plugin_edit_action()
2929
3030 $postdata = @join('', get_source($page));
3131 if ($postdata == '') $postdata = auto_template($page);
32-
32+ $postdata = remove_author_info($postdata);
3333 return array('msg'=>$_title_edit, 'body'=>edit_form($page, $postdata));
3434 }
3535
--- a/pukiwiki.ini.php
+++ b/pukiwiki.ini.php
@@ -282,6 +282,12 @@ $ldap_user_account = 0;
282282 // $ldap_bind_password = '';
283283
284284 /////////////////////////////////////////////////
285+// User prefix that shows its auth provider
286+define('AUTH_PROVIDER_USER_PREFIX_DEFAULT', 'default:');
287+define('AUTH_PROVIDER_USER_PREFIX_LDAP', 'ldap:');
288+define('AUTH_PROVIDER_USER_PREFIX_EXTERNAL', 'external:');
289+
290+/////////////////////////////////////////////////
285291 // $whatsnew: Max number of RecentChanges
286292 $maxshow = 60;
287293