OSDN Git Service

Remove media selector, use media query
[pukiwiki/pukiwiki.git] / lib / html.php
index 8be5be4..6b2fc6c 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: html.php,v 1.66 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C)
-//   2002-2006 PukiWiki Developers Team
+// html.php
+// Copyright
+//   2002-2016 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -48,6 +48,12 @@ function catbody($title, $page, $body)
        $_page  = isset($vars['page']) ? $vars['page'] : '';
        $r_page = pagename_urlencode($_page);
 
+       // Canonical URL
+       $canonical_url = $script;
+       if ($_page !== $defaultpage) {
+               $canonical_url = $script . '?' . $r_page;
+       }
+
        // Set $_LINK for skin
        $_LINK['add']      = "$script?cmd=add&amp;page=$r_page";
        $_LINK['backup']   = "$script?cmd=backup&amp;page=$r_page";
@@ -61,7 +67,7 @@ function catbody($title, $page, $body)
        $_LINK['new']      = "$script?plugin=newpage&amp;refer=$r_page";
        $_LINK['rdf']      = "$script?cmd=rss&amp;ver=1.0";
        $_LINK['recent']   = "$script?" . pagename_urlencode($whatsnew);
-       $_LINK['reload']   = "$script?$r_page";
+       $_LINK['reload']   = $canonical_url;
        $_LINK['rename']   = "$script?plugin=rename&amp;refer=$r_page";
        $_LINK['rss']      = "$script?cmd=rss";
        $_LINK['rss10']    = "$script?cmd=rss&amp;ver=1.0"; // Same as 'rdf'
@@ -70,6 +76,7 @@ function catbody($title, $page, $body)
        $_LINK['top']      = "$script?" . pagename_urlencode($defaultpage);
        $_LINK['unfreeze'] = "$script?cmd=unfreeze&amp;page=$r_page";
        $_LINK['upload']   = "$script?plugin=attach&amp;pcmd=upload&amp;page=$r_page";
+       $login_link = "#LOGIN_ERROR"; // dummy link that is not used
        switch ($auth_type) {
                case AUTH_TYPE_FORM:
                        $login_link = "$script?plugin=loginform&pcmd=login&page=$r_page";
@@ -132,6 +139,18 @@ function catbody($title, $page, $body)
        // Last modification date (UNIX timestamp) of the page
        $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
 
+       // Output nofollow / noindex regardless os skin file
+       if (!$is_read || $nofollow) {
+               if (!headers_sent()) {
+                       header("X-Robots-Tag: noindex,nofollow");
+               }
+       }
+
+       // Send Canonical URL for Search Engine Optimization
+       if ($is_read && !headers_sent()) {
+               header("Link: <$canonical_url>; rel=\"canonical\"");
+       }
+
        // Search words
        if ($search_word_color && isset($vars['word'])) {
                $body = '<div class="small">' . $_msg_word . htmlsc($vars['word']) .
@@ -183,6 +202,7 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
        global $_btn_preview, $_btn_repreview, $_btn_update, $_btn_cancel, $_msg_help;
        global $whatsnew, $_btn_template, $_btn_load, $load_template_func;
        global $notimeupdate;
+       global $_title_list, $_label_template_pages;
 
        // Newly generate $digest or not
        if ($digest === FALSE) $digest = md5(join('', get_source($page)));
@@ -203,20 +223,54 @@ function edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
        }
 
        if($load_template_func && $b_template) {
-               $pages  = array();
+               $tpage_names = array(); // Pages marked as template
+               $template_page = ':config/Templates';
+               $page_max = 100;
+               foreach(get_source($template_page) as $_templates) {
+                       $m = array();
+                       if (! preg_match('#\-\s*\[\[([^\[\]]+)\]\]#', $_templates, $m)) continue;
+                       $tpage = preg_replace('#^./#', "$template_page/", $m[1]);
+                       if (! is_page($tpage)) continue;
+                       $tpage_names[] = $tpage;
+               }
+               $page_names = array();
                foreach(get_existpages() as $_page) {
                        if ($_page == $whatsnew || check_non_list($_page))
                                continue;
-                       $s_page = htmlsc($_page);
-                       $pages[$_page] = '   <option value="' . $s_page . '">' .
-                               $s_page . '</option>';
+                       if (preg_match('/template/i', $_page)) {
+                               $tpage_names[] = $_page;
+                       } else {
+                               if (count($page_names) >= $page_max) continue;
+                               $page_names[] = $_page;
+                       }
+               }
+               $tpage_names2 = array_values(array_unique($tpage_names));
+               natcasesort($tpage_names2);
+               natcasesort($page_names);
+               $tpages = array(); // Template pages
+               $npages = array(); // Normal pages
+               foreach($tpage_names2 as $p) {
+                       $ps = htmlsc($p);
+                       $tpages[] = '   <option value="' . $ps . '">' . $ps . '</option>';
                }
-               ksort($pages, SORT_STRING);
-               $s_pages  = join("\n", $pages);
+               foreach($page_names as $p) {
+                       $ps = htmlsc($p);
+                       $npages[] = '   <option value="' . $ps . '">' . $ps . '</option>';
+               }
+               if (count($page_names) === $page_max) {
+                       $npages[] = '   <option value="">...</option>';
+               }
+               $s_tpages  = join("\n", $tpages);
+               $s_npages  = join("\n", $npages);
                $template = <<<EOD
   <select name="template_page">
    <option value="">-- $_btn_template --</option>
-$s_pages
+   <optgroup label="$_label_template_pages">
+$s_tpages
+   </optgroup>
+   <optgroup label="$_title_list">
+$s_npages
+   </optgroup>
   </select>
   <input type="submit" name="template" value="$_btn_load" accesskey="r" />
   <br />
@@ -559,4 +613,3 @@ function pkwk_output_dtd($pkwk_dtd = PKWK_DTD_XHTML_1_1, $charset = CONTENT_CHAR
                return '<meta http-equiv="content-type" content="text/html; charset=' . $charset . '" />' . "\n";
        }
 }
-