X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=file.php;h=9190f0474638cf5fbf2d961445401b87d9437ff6;hb=533f27e1e283c1f017f6acd998c03114a15898c9;hp=d9a4af242ae6f71af31b61f4878dab4e4dcc4878;hpb=3b491012a9b3571bb07520b6e4029ea4de549dc4;p=pukiwiki%2Fpukiwiki.git diff --git a/file.php b/file.php index d9a4af2..9190f04 100644 --- a/file.php +++ b/file.php @@ -1,227 +1,231 @@ maybe permission is not writable or filename is too long"); - while(!flock($fp,LOCK_EX)); + + $fp = fopen($file,'w') + or die_message('cannot write page file or diff file or other'.htmlspecialchars($page).'
maybe permission is not writable or filename is too long'); + flock($fp,LOCK_EX); fputs($fp,$str); flock($fp,LOCK_UN); fclose($fp); - if($timestamp) - touch($dir.encode($page).".txt",$timestamp); + if ($timestamp) { + touch($file,$timestamp + LOCALZONE); + } } - if(!$timestamp) + if (!$timestamp) { put_lastmodified(); - - if($update_exec and $dir == DATA_DIR) - { - system($update_exec." > /dev/null &"); + } + + if ($update_exec and $dir == DATA_DIR) { + system($update_exec.' > /dev/null &'); } } // ºÇ½ª¹¹¿·¥Ú¡¼¥¸¤Î¹¹¿· function put_lastmodified() { - global $script,$maxshow,$whatsnew,$date_format,$time_format,$weeklabels,$post,$non_list; + global $script,$post,$maxshow,$whatsnew,$non_list; - if($post["notimestamp"]) return; - - $files = get_existpages(); - foreach($files as $page) { - if($page == $whatsnew) continue; - if(preg_match("/$non_list/",$page)) continue; - - if(file_exists(get_filename(encode($page)))) - { - $page_url = rawurlencode($page); - $lastmodtime = filemtime(get_filename(encode($page))); - $lastmod = date($date_format,$lastmodtime) - . " (" . $weeklabels[date("w",$lastmodtime)] . ") " - . date($time_format,$lastmodtime); - $putval[$lastmodtime][] = "-$lastmod - $page"; + $pages = array(); + foreach(get_existpages() as $page) { + if ($page == $whatsnew or preg_match("/$non_list/",$page)) { + continue; } + + $time = get_filetime($page); + $s_page = htmlspecialchars($page); + $pages[$s_page] = $time; } - $cnt = 1; - krsort($putval); - $fp = fopen(get_filename(encode($whatsnew)),"w"); - if($fp===FALSE) die_message("cannot write page file ".htmlspecialchars($whatsnew)."
maybe permission is not writable or filename is too long"); + arsort($pages); //»þ¹ï¹ß½ç¤Ç¥½¡¼¥È + + $fp = fopen(get_filename($whatsnew),'w') + or die_message('cannot write page file '.htmlspecialchars($whatsnew).'
maybe permission is not writable or filename is too long'); + flock($fp,LOCK_EX); - foreach($putval as $pages) - { - foreach($pages as $page) - { - fputs($fp,$page."\n"); - $cnt++; - if($cnt > $maxshow) break; - } - if($cnt > $maxshow) break; + + foreach($pages as $s_page => $time) { + fputs($fp, "//$time $s_page\n"); } - flock($fp,LOCK_EX); - fclose($fp); -} - -// ¥Õ¥¡¥¤¥ë̾¤òÆÀ¤ë(¥¨¥ó¥³¡¼¥É¤µ¤ì¤Æ¤¤¤ëɬÍ×Í­¤ê) -function get_filename($pagename) -{ - return DATA_DIR.$pagename.".txt"; -} - -// ¥Ú¡¼¥¸¤¬Â¸ºß¤¹¤ë¤«¤·¤Ê¤¤¤« -function is_page($page,$reload=false) -{ - global $InterWikiName,$_ispage; - - if(($_ispage[$page] === true || $_ispage[$page] === false) && !$reload) return $_ispage[$page]; - - if(preg_match("/($InterWikiName)/",$page)) - $_ispage[$page] = false; - else if(!page_exists($page)) - $_ispage[$page] = false; - else - $_ispage[$page] = true; - - return $_ispage[$page]; -} - -// ¥Ú¡¼¥¸¤¬ÊÔ½¸²Äǽ¤« -function is_editable($page) -{ - global $BracketName,$WikiName,$InterWikiName,$cantedit,$_editable; - - if($_editable === true || $_editable === false) return $_editable; - - if(preg_match("/^$InterWikiName$/",$page)) - $_editable = false; - elseif(!preg_match("/^$BracketName$/",$page) && !preg_match("/^$WikiName$/",$page)) - $_editable = false; - else if(in_array($page,$cantedit)) - $_editable = false; - else - $_editable = true; - - return $_editable; -} - -// ¥Ú¡¼¥¸¤¬Åà·ë¤µ¤ì¤Æ¤¤¤ë¤« -function is_freeze($page) -{ - global $_freeze; - - if(!is_page($page)) return false; - if($_freeze === true || $_freeze === false) return $_freeze; - - $lines = get_source($page); - if($lines[0] == "#freeze\n") - $_freeze = true; - else - $_freeze = false; + $pages = array_splice($pages,0,$maxshow); + + foreach($pages as $s_page => $time) { + $lastmod = format_date($time); + fputs($fp, "-$lastmod - [[$s_page]]\n"); + } - return $_freeze; + fputs($fp,"#norelated\n"); // :) + flock($fp,LOCK_UN); + fclose($fp); } // »ØÄꤵ¤ì¤¿¥Ú¡¼¥¸¤Î·Ð²á»þ¹ï -function get_pg_passage($page,$sw=true) +function get_pg_passage($page,$sw=TRUE) { - global $_pg_passage,$show_passage; - - if(!$show_passage) return ""; - - if(isset($_pg_passage[$page])) - { - if($sw) - return $_pg_passage[$page]["str"]; - else - return $_pg_passage[$page]["label"]; - } - if($pgdt = @filemtime(get_filename(encode($page)))) - { - $pgdt = UTIME - $pgdt; - if(ceil($pgdt / 60) < 60) - $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60)."m)"; - else if(ceil($pgdt / 60 / 60) < 24) - $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60 / 60)."h)"; - else - $_pg_passage[$page]["label"] = "(".ceil($pgdt / 60 / 60 / 24)."d)"; - - $_pg_passage[$page]["str"] = "".$_pg_passage[$page]["label"].""; + global $show_passage; + static $pg_passage; + + if (!$show_passage) { + return ''; } - else - { - $_pg_passage[$page]["label"] = ""; - $_pg_passage[$page]["str"] = ""; + + if (!isset($pg_passage)) { + $pg_passage = array(); } - - if($sw) - return $_pg_passage[$page]["str"]; - else - return $_pg_passage[$page]["label"]; + + if (!array_key_exists($page,$pg_passage)) { + $pg_passage[$page] = (is_page($page) and $time = get_filetime($page)) ? get_passage($time) : ''; + } + + return $sw ? "{$pg_passage[$page]}" : $pg_passage[$page]; } // Last-Modified ¥Ø¥Ã¥À -function header_lastmod($page) +function header_lastmod() { global $lastmod; - if($lastmod && is_page($page)) - { - header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime(get_filename(encode($page))))." GMT"); + if ($lastmod and is_page($page)) { + header('Last-Modified: '.date('D, d M Y H:i:s',get_filetime($page)).' GMT'); } } // Á´¥Ú¡¼¥¸Ì¾¤òÇÛÎó¤Ë -function get_existpages() +function get_existpages($dir = DATA_DIR) { $aryret = array(); - - if ($dir = @opendir(DATA_DIR)) - { - while($file = readdir($dir)) - { - if($file == ".." || $file == "." || strstr($file,".txt")===FALSE) continue; - $page = decode(trim(preg_replace("/\.txt$/"," ",$file))); - array_push($aryret,$page); + + $dir = @opendir($dir) or die(); + + while ($file = readdir($dir)) { + if (preg_match('/^([0-9A-F]+)/',$file,$matches)) { + $aryret[] = decode($matches[1]); } - closedir($dir); } + closedir($dir); + return $aryret; } + +function links_update($page) +{ + global $vars; + + // link¥Ç¡¼¥¿¥Ù¡¼¥¹¤ò¹¹¿· + if (defined('LINK_DB') and exist_plugin_action('links')) { + // ¤Á¤ç¤Ã¤È¸È© + $tmp = $vars['page']; + $vars['page'] = $page; + do_plugin_action('links'); + $vars['page'] = $tmp; + } +} +//¤¢¤ë¥Ú¡¼¥¸¤Î´ØÏ¢¥Ú¡¼¥¸¤òÆÀ¤ë +function links_get_related($page) +{ + global $vars,$related; + static $links; + + if (!isset($links)) { + $links = array(); + } + + if (array_key_exists($page,$links)) { + return $links[$page]; + } + + // ²Äǽ¤Ê¤émake_link()¤ÇÀ¸À®¤·¤¿´ØÏ¢¥Ú¡¼¥¸¤ò¼è¤ê¹þ¤à + $links[$page] = ($page == $vars['page']) ? $related : array(); + + $a_page = addslashes($page); + + if (defined('LINK_DB')) { + $sql = <<