OSDN Git Service

BugTrack2/369 Support PHP7 - Remove '& new Class' notation
[pukiwiki/pukiwiki.git] / lib / make_link.php
index e25f7e4..e978f34 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: make_link.php,v 1.28 2005/06/27 14:18:07 henoheno Exp $
+// $Id: make_link.php,v 1.38 2011/01/25 15:01:01 henoheno Exp $
 // Copyright (C)
-//   2003-2005 PukiWiki Developers Team
+//   2003-2007 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -95,7 +95,7 @@ class InlineConverter
                $string = preg_replace_callback('/' . $this->pattern . '/x',
                        array(& $this, 'replace'), $string);
 
-               $arr = explode("\x08", make_line_rules(htmlspecialchars($string)));
+               $arr = explode("\x08", make_line_rules(htmlsc($string)));
                $retval = '';
                while (! empty($arr)) {
                        $retval .= array_shift($arr) . array_shift($this->result);
@@ -108,7 +108,7 @@ class InlineConverter
                $obj = $this->get_converter($arr);
 
                $this->result[] = ($obj !== NULL && $obj->set($arr, $this->page) !== FALSE) ?
-                       $obj->toString() : make_line_rules(htmlspecialchars($arr[0]));
+                       $obj->toString() : make_line_rules(htmlsc($arr[0]));
 
                return "\x08"; // Add a mark into latest processed part
        }
@@ -187,7 +187,7 @@ class Link
                $this->type = $type;
                if (! PKWK_DISABLE_INLINE_IMAGE_FROM_URI &&
                        is_url($alias) && preg_match('/\.(gif|png|jpe?g)$/i', $alias)) {
-                       $alias = '<img src="' . htmlspecialchars($alias) . '" alt="' . $name . '" />';
+                       $alias = '<img src="' . htmlsc($alias) . '" alt="' . $name . '" />';
                } else if ($alias != '') {
                        if ($converter === NULL)
                                $converter = new InlineConverter(array('plugin'));
@@ -270,7 +270,7 @@ EOD;
                } else {
                        // No such plugin, or Failed
                        $body = (($body == '') ? '' : '{' . $body . '}') . ';';
-                       return make_line_rules(htmlspecialchars('&' . $this->plain) . $body);
+                       return make_line_rules(htmlsc('&' . $this->plain) . $body);
                }
        }
 }
@@ -287,7 +287,7 @@ class Link_note extends Link
        {
                return <<<EOD
 \(\(
- ((?:(?R)|(?!\)\)).)*) # (1) note body
+ ((?>(?=\(\()(?R)|(?!\)\)).)*) # (1) note body
 \)\)
 EOD;
        }
@@ -304,9 +304,11 @@ EOD;
 
                list(, $body) = $this->splice($arr);
 
-               $script = '';
-               if (! PKWK_ALLOW_RELATIVE_FOOTNOTE_ANCHOR)
-                       $script = get_script_uri() . '?' . $page;
+               if (PKWK_ALLOW_RELATIVE_FOOTNOTE_ANCHOR) {
+                       $script = '';
+               } else {
+                       $script = get_script_uri() . '?' . pagename_urlencode($page);
+               }
 
                $id   = ++$note_id;
                $note = make_link($body);
@@ -319,9 +321,18 @@ EOD;
                        '<span class="small">' . $note . '</span><br />';
 
                // A hyperlink, content-body to footnote
+               if (! is_numeric(PKWK_FOOTNOTE_TITLE_MAX) || PKWK_FOOTNOTE_TITLE_MAX <= 0) {
+                       $title = '';
+               } else {
+                       $title = strip_tags($note);
+                       $count = mb_strlen($title, SOURCE_ENCODING);
+                       $title = mb_substr($title, 0, PKWK_FOOTNOTE_TITLE_MAX, SOURCE_ENCODING);
+                       $abbr  = (mb_strlen($title) < $count) ? '...' : '';
+                       $title = ' title="' . $title . $abbr . '"';
+               }
                $name = '<a id="notetext_' . $id . '" href="' . $script .
-                       '#notefoot_' . $id . '" class="note_super" title="' .
-                       strip_tags($note) . '">*' . $id . '</a>';
+                       '#notefoot_' . $id . '" class="note_super"' . $title .
+                       '>*' . $id . '</a>';
 
                return parent::setParam($page, $name, $body);
        }
@@ -363,7 +374,7 @@ EOD;
        function set($arr, $page)
        {
                list(, , $alias, $name) = $this->splice($arr);
-               return parent::setParam($page, htmlspecialchars($name),
+               return parent::setParam($page, htmlsc($name),
                        '', 'url', $alias == '' ? $name : $alias);
        }
 
@@ -407,7 +418,7 @@ EOD;
        function set($arr, $page)
        {
                list(, $name, $alias) = $this->splice($arr);
-               return parent::setParam($page, htmlspecialchars($name), '', 'url', $alias);
+               return parent::setParam($page, htmlsc($name), '', 'url', $alias);
        }
 
        function toString()
@@ -508,12 +519,12 @@ EOD;
 
                $url = get_interwiki_url($name, $this->param);
                $this->url = ($url === FALSE) ?
-                       $script . '?' . rawurlencode('[[' . $name . ':' . $this->param . ']]') :
-                       htmlspecialchars($url);
+                       $script . '?' . pagename_urlencode('[[' . $name . ':' . $this->param . ']]') :
+                       htmlsc($url);
 
                return parent::setParam(
                        $page,
-                       htmlspecialchars($name . ':' . $this->param),
+                       htmlsc($name . ':' . $this->param),
                        '',
                        'InterWikiName',
                        $alias == '' ? $name . ':' . $this->param : $alias
@@ -697,15 +708,15 @@ function make_pagelink($page, $alias = '', $anchor = '', $refer = '', $isautolin
 {
        global $script, $vars, $link_compact, $related, $_symbol_noexists;
 
-       $s_page = htmlspecialchars(strip_bracket($page));
+       $s_page = htmlsc(strip_bracket($page));
        $s_alias = ($alias == '') ? $s_page : $alias;
 
        if ($page == '') return '<a href="' . $anchor . '">' . $s_alias . '</a>';
 
-       $r_page  = rawurlencode($page);
+       $r_page  = pagename_urlencode($page);
        $r_refer = ($refer == '') ? '' : '&amp;refer=' . rawurlencode($refer);
 
-       if (! isset($related[$page]) && $page != $vars['page'] && is_page($page))
+       if (! isset($related[$page]) && $page !== $vars['page'] && is_page($page))
                $related[$page] = get_filetime($page);
 
        if ($isautolink || is_page($page)) {
@@ -840,4 +851,4 @@ function get_interwiki_url($name, $param)
 
        return $url;
 }
-?>
+