OSDN Git Service

BugTrack/2447 Show page passage by Web browser/JavaScript process
authorumorigu <umorigu@gmail.com>
Wed, 8 Nov 2017 19:53:10 +0000 (04:53 +0900)
committerumorigu <umorigu@gmail.com>
Wed, 8 Nov 2017 19:53:10 +0000 (04:53 +0900)
* lib/make_link
* related plugin
* ls2 plugin
* recent plugin
* popular plugin
* showrss plugin
* list plugin
* filelist plugin

14 files changed:
lib/file.php
lib/func.php
lib/html.php
lib/make_link.php
plugin/filelist.inc.php
plugin/list.inc.php
plugin/ls2.inc.php
plugin/popular.inc.php
plugin/recent.inc.php
plugin/related.inc.php
plugin/showrss.inc.php
skin/main.js
skin/pukiwiki.css
skin/tdiary.css

index 50a7480..cf67c38 100644 (file)
@@ -82,6 +82,19 @@ function get_filetime($page)
        return is_page($page) ? filemtime(get_filename($page)) - LOCALZONE : 0;
 }
 
+/**
+ * Get last-modified filemtime (plain value) of the page.
+ *
+ * @param $page
+ */
+function get_page_date_atom($page)
+{
+       if (is_page($page)) {
+               return get_date_atom(filemtime(get_filename($page)));
+       }
+       return null;
+}
+
 // Get physical file name of the page
 function get_filename($page)
 {
@@ -279,15 +292,6 @@ function get_update_datetime_from_author($author_line) {
        return null;
 }
 
-function get_date_atom($timestamp)
-{
-       // Compatible with DATE_ATOM format
-       // return date(DATE_ATOM, $timestamp);
-       $zmin = abs(LOCALZONE / 60);
-       return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
-               (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
-}
-
 // Generate ID
 function generate_fixed_heading_anchor_id($seed)
 {
index fba35cf..b05584d 100644 (file)
@@ -303,6 +303,53 @@ function get_search_words($words = array(), $do_escape = FALSE)
        return $regex; // For all words
 }
 
+function get_passage_date_html_span($date_atom)
+{
+       return '<span class="page_passage" data-mtime="' . $date_atom . '"></span>';
+}
+
+function get_passage_mtime_html_span($mtime)
+{
+       $date_atom = get_date_atom($mtime);
+       return get_passage_date_html_span($date_atom);
+}
+
+/**
+ * Get passage span html
+ *
+ * @param $page
+ */
+function get_passage_html_span($page)
+{
+       $date_atom = get_page_date_atom($page);
+       return get_passage_date_html_span($date_atom);
+}
+
+function get_link_passage_class() {
+       return 'link_page_passage';
+}
+
+/**
+ * Get page link general attributes
+ * @param $page
+ * @return array('data_mtime' => page mtime or null, 'class' => additinal classes)
+ */
+function get_page_link_a_attrs($page)
+{
+       global $show_passage;
+       if ($show_passage) {
+               $pagemtime = get_page_date_atom($page);
+               return array(
+                       'data_mtime' => $pagemtime,
+                       'class' => get_link_passage_class(),
+               );
+       }
+       return array(
+               'data_mtime' => '',
+               'class' => ''
+       );
+}
+
 // 'Search' main function
 function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
 {
@@ -372,7 +419,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
        foreach (array_keys($pages) as $page) {
                $r_page  = rawurlencode($page);
                $s_page  = htmlsc($page);
-               $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : '';
+               $passage = $show_passage ? ' ' . get_passage_html_span($page) : '';
                $retval .= ' <li><a href="' . get_base_uri() . '?cmd=read&amp;page=' .
                        $r_page . '&amp;word=' . $r_word . '">' . $s_page .
                        '</a>' . $passage . '</li>' . "\n";
@@ -469,11 +516,8 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
        foreach($pages as $file=>$page) {
                $r_page  = pagename_urlencode($page);
                $s_page  = htmlsc($page, ENT_QUOTES);
-               $passage = get_pg_passage($page);
-
                $str = '   <li><a href="' . $href . $r_page . '">' .
-                       $s_page . '</a>' . $passage;
-
+                       $s_page . '</a>' . get_passage_html_span($page);
                if ($withfilename) {
                        $s_file = htmlsc($file);
                        $str .= "\n" . '    <ul><li>' . $s_file . '</li></ul>' .
@@ -496,7 +540,6 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
                        $head = (preg_match('/^([A-Za-z])/', $page, $matches)) ? strtoupper($matches[1]) :
                                (preg_match('/^([ -~])/', $page) ? $symbol : $other);
                }
-
                $list[$head][$page] = $str;
        }
        uksort($pages, 'strnatcmp');
@@ -624,6 +667,18 @@ function format_date($val, $paren = FALSE)
        return $paren ? '(' . $date . ')' : $date;
 }
 
+/**
+ * Format date in DATE_ATOM format.
+ */
+function get_date_atom($timestamp)
+{
+       // Compatible with DATE_ATOM format
+       // return date(DATE_ATOM, $timestamp);
+       $zmin = abs(LOCALZONE / 60);
+       return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
+               (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
+}
+
 // Get short string of the passage, 'N seconds/minutes/hours/days/years ago'
 function get_passage($time, $paren = TRUE)
 {
index 41d53e9..e77baf3 100644 (file)
@@ -117,7 +117,7 @@ function catbody($title, $page, $body)
 
        // Last modification date (string) of the page
        $lastmodified = $is_read ?  format_date(get_filetime($_page)) .
-               ' ' . get_pg_passage($_page, FALSE) : '';
+               get_passage_html_span($_page) : '';
 
        // List of attached files to the page
        $show_attaches = $is_read || arg_check('edit');
@@ -442,15 +442,18 @@ function make_related($page, $tag = '')
        $_links = array();
        foreach ($links as $page=>$lastmod) {
                if (check_non_list($page)) continue;
-
                $page_uri = get_page_uri($page);
                $s_page   = htmlsc($page);
-               $passage  = get_passage($lastmod);
-               $_links[] = $tag ?
-                       '<a href="' . $page_uri . '" title="' .
-                       $s_page . ' ' . $passage . '">' . $s_page . '</a>' :
-                       '<a href="' . $page_uri . '">' .
-                       $s_page . '</a>' . $passage;
+               if ($tag) {
+                       $attrs = get_page_link_a_attrs($page);
+                       $_links[] = '<a href="' . $page_uri . '" class="' .
+                               $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                               '">' . $s_page . '</a>';
+               } else {
+                       $mtime_span = get_passage_mtime_html_span($lastmod + LOCALZONE);
+                       $_links[] = '<a href="' . $page_uri . '">' .
+                       $s_page . '</a>' . $mtime_span;
+               }
        }
        if (empty($_links)) return ''; // Nothing
 
index 962a2ee..3a4f409 100644 (file)
@@ -768,12 +768,7 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
 
        if ($isautolink || is_page($page)) {
                // Hyperlink to the page
-               if ($link_compact) {
-                       $title   = '';
-               } else {
-                       $title   = ' title="' . $s_page . get_pg_passage($page, FALSE) . '"';
-               }
-
+               $attrs = get_page_link_a_attrs($page);
                // AutoLink marker
                if ($isautolink) {
                        $al_left  = '<!--autolink-->';
@@ -781,9 +776,14 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
                } else {
                        $al_left = $al_right = '';
                }
-
+               $title_attr_html = '';
+               if ($s_page !== $s_alias) {
+                       $title_attr_html = ' title="' . $s_page . '"';
+               }
                return $al_left . '<a ' . 'href="' . $script . '?' . $r_page . $anchor .
-                       '"' . $title . '>' . $s_alias . '</a>' . $al_right;
+                       '"' . $title_attr_html . ' class="' .
+                       $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                       '">' . $s_alias . '</a>' . $al_right;
        } else {
                // Support Page redirection
                $redirect_page = get_pagename_on_redirect($page);
index 3df5449..a370fb3 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: filelist.inc.php,v 1.3 2005/01/09 08:16:28 henoheno Exp $
+// filelist.inc.php
+// Copyright 2003-2017 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
 //
 // Filelist plugin: redirect to list plugin
 // cmd=filelist
@@ -9,4 +11,3 @@ function plugin_filelist_action()
 {
        return do_plugin_action('list');
 }
-?>
index f59dcf7..61a48e2 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: list.inc.php,v 1.6 2006/05/13 07:36:41 henoheno Exp $
+// list.inc.php
+// Copyright 2003-2017 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
 //
 // IndexPages plugin: Show a list of page names
 
@@ -9,7 +11,7 @@ function plugin_list_action()
        global $vars, $_title_list, $_title_filelist, $whatsnew;
 
        // Redirected from filelist plugin?
-       $filelist = (isset($vars['cmd']) && $vars['cmd'] == 'filelist');
+       $filelist = (isset($vars['cmd']) && $vars['cmd'] === 'filelist');
 
        return array(
                'msg'=>$filelist ? $_title_filelist : $_title_list,
@@ -28,4 +30,3 @@ function plugin_list_getlist($withfilename = FALSE)
 
        return page_list($pages, 'read', $withfilename);
 }
-?>
index cc4e705..d4e36f8 100644 (file)
@@ -132,21 +132,24 @@ function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE,
        if (! $is_done) $params["page_$page"] = ++$_ls2_anchor;
 
        $s_page = htmlsc($page);
-       $title  = $s_page . ' ' . get_pg_passage($page, FALSE);
+       $attrs = get_page_link_a_attrs($page);
        $href   = get_page_uri($page);
 
        plugin_ls2_list_push($params, $level);
        $ret = $include ? '<li>include ' : '<li>';
 
        if ($is_done) {
-               $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> ';
+               $ret .= '<a href="' . $href . '" class="' .
+                       $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                       '">' . $s_page . '</a> ';
                $ret .= '<a href="#list_' . $params["page_$page"] . '"><sup>&uarr;</sup></a>';
                array_push($params['result'], $ret);
                return;
        }
 
        $ret .= '<a id="list_' . $params["page_$page"] . '" href="' . $href .
-               '" title="' . $title . '">' . $s_page . '</a>';
+               '" class="' . $attrs['class'] . '" data-mtime="' .
+               $attrs['data_mtime'] . '">' . $s_page . '</a>';
        array_push($params['result'], $ret);
 
        $anchor = PLUGIN_LS2_ANCHOR_ORIGIN;
index 1c54a60..07bf2fa 100644 (file)
@@ -57,9 +57,10 @@ function plugin_popular_convert()
                        $s_page = htmlsc($page);
                        if ($page === $vars['page']) {
                                // No need to link itself, notifies where you just read
-                               $pg_passage = get_pg_passage($page,FALSE);
-                               $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
-                                       $s_page . '<span class="counter">(' . $count .
+                               $attrs = get_page_link_a_attrs($page);
+                               $items .= ' <li><span class="' .
+                                       $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                                       '">' . $s_page . '<span class="counter">(' . $count .
                                        ')</span></span></li>' . "\n";
                        } else {
                                $items .= ' <li>' . make_pagelink($page,
index e7166a5..f90b916 100644 (file)
@@ -25,7 +25,7 @@ define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
 
 function plugin_recent_convert()
 {
-       global $vars, $date_format, $_recent_plugin_frame, $show_passage;
+       global $vars, $date_format, $_recent_plugin_frame;
        static $exec_count = 1;
 
        $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
@@ -76,9 +76,10 @@ function plugin_recent_convert()
                        // No need to link to the page you just read, or notify where you just read
                        $items .= ' <li>' . $s_page . '</li>' . "\n";
                } else {
-                       $passage = $show_passage ? ' ' . get_passage($time) : '';
-                       $items .= ' <li><a href="' . get_page_uri($page) . '"' .
-                               ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
+                       $attrs = get_page_link_a_attrs($page);
+                       $items .= ' <li><a href="' . get_page_uri($page) . '" class="' .
+                               $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                               '">' . $s_page . '</a></li>' . "\n";
                }
        }
        // End of the day
index 9b56ca4..d301e02 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: related.inc.php,v 1.11 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C) 2005, 2007 PukiWiki Developers Team
+// related.inc.php
+// Copyright 2005-2017 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // Related plugin: Show Backlinks for the page
@@ -16,7 +16,7 @@ function plugin_related_convert()
 // Show Backlinks: via related caches for the page
 function plugin_related_action()
 {
-       global $vars, $script, $defaultpage, $whatsnew;
+       global $vars, $defaultpage, $whatsnew;
 
        $_page = isset($vars['page']) ? $vars['page'] : '';
        if ($_page == '') $_page = $defaultpage;
@@ -30,14 +30,11 @@ function plugin_related_action()
                            check_non_list($page))
                                unset($data[$page]);
        }
-
        // Result
-       $r_word = pagename_urlencode($_page);
        $s_word = htmlsc($_page);
        $msg = 'Backlinks for: ' . $s_word;
-       $retval  = '<a href="' . $script . '?' . $r_word . '">' .
+       $retval  = '<a href="' . get_page_uri($_page) . '">' .
                'Return to ' . $s_word .'</a><br />'. "\n";
-
        if (empty($data)) {
                $retval .= '<ul><li>No related pages found.</li></ul>' . "\n";  
        } else {
@@ -45,14 +42,12 @@ function plugin_related_action()
                ksort($data, SORT_STRING);
                $retval .= '<ul>' . "\n";
                foreach ($data as $page=>$time) {
-                       $r_page  = pagename_urlencode($page);
                        $s_page  = htmlsc($page);
-                       $passage = get_passage($time);
-                       $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
-                               '</a> ' . $passage . '</li>' . "\n";
+                       $mtime_span = get_passage_mtime_html_span($time + LOCALZONE);
+                       $retval .= ' <li><a href="' . get_page_uri($page) . '">' . $s_page .
+                               '</a>' . $mtime_span . '</li>' . "\n";
                }
                $retval .= '</ul>' . "\n";
        }
        return array('msg'=>$msg, 'body'=>$retval);
 }
-
index 29415f4..041bf7d 100644 (file)
@@ -94,9 +94,10 @@ class ShowRSS_html
                        foreach ($items as $item) {
                                $link  = $item['LINK'];
                                $title = $item['TITLE'];
-                               $passage = get_passage($item['_TIMESTAMP']);
-                               $link = '<a href="' . $link . '" title="' .  $title . ' ' .
-                                       $passage . '" rel="nofollow">' . $title . '</a>';
+                               $date = get_date_atom($item['_TIMESTAMP'] + LOCALZONE);
+                               $link = '<a href="' . $link . '" data-mtime="' .
+                                        $date . '" class="' . get_link_passage_class() .
+                                        '" rel="nofollow">' . $title . '</a>';
                                $this->items[$date][] = $this->format_link($link);
                        }
                }
index 24316db..4252983 100644 (file)
@@ -6,6 +6,19 @@
 // PukiWiki JavaScript client script
 window.addEventListener && window.addEventListener('DOMContentLoaded', function() { // eslint-disable-line no-unused-expressions
   'use strict';
+  /**
+   * @param {NodeList} nodeList
+   * @param {function(Node, number): void} func
+   */
+  function forEach(nodeList, func) {
+    if (nodeList.forEach) {
+      nodeList.forEach(func);
+    } else {
+      for (var i = 0, n = nodeList.length; i < n; i++) {
+        func(nodeList[i], i);
+      }
+    }
+  }
   // Name for comment
   function setYourName() {
     var NAME_KEY_ID = 'pukiwiki_comment_plugin_name';
@@ -276,7 +289,51 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
       e.returnValue = message;
     }, false);
   }
+  function showPagePassage() {
+    /**
+     * @param {Date} now
+     * @param {string} dateText
+     */
+    function getPassage(dateText, now) {
+      if (!dateText) {
+        return '';
+      }
+      var units = [{u: 'm', max: 60}, {u: 'h', max: 24}, {u: 'd', max: 1}];
+      var d = new Date();
+      d.setTime(Date.parse(dateText));
+      var t = (now.getTime() - d.getTime()) / (1000 * 60); // minutes
+      var unit = units[0].u; var card = units[0].max;
+      for (var i = 0; i < units.length; i++) {
+        unit = units[i].u; card = units[i].max;
+        if (t < card) break;
+        t = t / card;
+      }
+      return '(' + Math.floor(t) + unit + ')';
+    }
+    var now = new Date();
+    var elements = document.getElementsByClassName('page_passage');
+    forEach(elements, function(e) {
+      var dt = e.getAttribute('data-mtime');
+      if (dt) {
+        var d = new Date(dt);
+        e.textContent = ' ' + getPassage(d, now);
+      }
+    });
+    var links = document.getElementsByClassName('link_page_passage');
+    forEach(links, function(e) {
+      var dt = e.getAttribute('data-mtime');
+      if (dt) {
+        var d = new Date(dt);
+        if (e.title) {
+          e.title = e.title + ' ' + getPassage(d, now);
+        } else {
+          e.title = e.textContent + ' ' + getPassage(d, now);
+        }
+      }
+    });
+  }
   setYourName();
   autoTicketLink();
   confirmEditFormLeaving();
+  showPagePassage();
 });
index 8168837..3c332bd 100644 (file)
@@ -388,6 +388,9 @@ div#related {
   padding:0px;
   margin:16px 0px 0px 0px;
 }
+div#related .page_passage {
+  font-size:60%;
+}
 
 div#footer {
   font-size:70%;
@@ -417,6 +420,11 @@ img#logo {
   vertical-align:super;
 }
 
+/* list.inc.php */
+.page_passage {
+  font-size: small;
+}
+
 /* br.inc.php */
 br.spacer {}
 
index 1785f37..0ec60ed 100644 (file)
@@ -282,6 +282,9 @@ div#related {
   padding:0px;
   margin:0px 0px 0px 0px;
 }
+div#related .page_passage {
+  font-size:60%;
+}
 
 div#footer {
   font-size:70%;
@@ -311,6 +314,11 @@ img#logo {
   vertical-align:super;
 }
 
+/* list.inc.php */
+.page_passage {
+  font-size: small;
+}
+
 /* br.inc.php */
 br.spacer {}