OSDN Git Service

BugTrack2/170: Added ''rename'' function.
authorteanan <teanan>
Mon, 10 Apr 2006 17:37:08 +0000 (02:37 +0900)
committerteanan <teanan>
Mon, 10 Apr 2006 17:37:08 +0000 (02:37 +0900)
en.lng.php
ja.lng.php
plugin/attach.inc.php

index 227f4ec..8c2a4d7 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: en.lng.php,v 1.14 2006/01/09 12:09:57 henoheno Exp $
+// $Id: en.lng.php,v 1.15 2006/04/10 17:36:56 teanan Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -145,6 +145,7 @@ $_attach_messages = array(
        'msg_deleted'  => 'Deleted the file in  $1',
        'msg_freezed'  => 'The file has been frozen.',
        'msg_unfreezed'=> 'The file has been unfrozen',
+       'msg_renamed'  => 'The file has been renamed',
        'msg_upload'   => 'Upload to $1',
        'msg_info'     => 'File information',
        'msg_confirm'  => '<p>Delete %s.</p>',
@@ -160,6 +161,8 @@ $_attach_messages = array(
        'msg_freeze'   => 'Freeze file.',
        'msg_unfreeze' => 'Unfreeze file.',
        'msg_isfreeze' => 'File is frozen.',
+       'msg_rename'   => 'Rename',
+       'msg_newname'  => 'New file name',
        'msg_require'  => '(require administrator password)',
        'msg_filesize' => 'size',
        'msg_date'     => 'date',
@@ -173,6 +176,7 @@ $_attach_messages = array(
        'err_notfound' => 'Could not fid the file in  $1',
        'err_noexist'  => 'File does not exist.',
        'err_delete'   => 'Cannot delete file in  $1',
+       'err_rename'   => 'Cannot rename this file',
        'err_password' => 'Wrong password.',
        'err_adminpass'=> 'Wrong administrator password',
        'btn_upload'   => 'Upload',
index 2e8c43f..3b57ee8 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: ja.lng.php,v 1.13 2006/01/09 12:09:57 henoheno Exp $
+// $Id: ja.lng.php,v 1.14 2006/04/10 17:36:56 teanan Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -147,6 +147,7 @@ $_attach_messages = array(
        'msg_deleted'  => '$1 ¤«¤é¥Õ¥¡¥¤¥ë¤òºï½ü¤·¤Þ¤·¤¿',
        'msg_freezed'  => 'źÉÕ¥Õ¥¡¥¤¥ë¤òÅà·ë¤·¤Þ¤·¤¿¡£',
        'msg_unfreezed'=> 'źÉÕ¥Õ¥¡¥¤¥ë¤òÅà·ë²ò½ü¤·¤Þ¤·¤¿¡£',
+       'msg_renamed'  => 'źÉÕ¥Õ¥¡¥¤¥ë¤Î̾Á°¤òÊѹ¹¤·¤Þ¤·¤¿¡£',
        'msg_upload'   => '$1 ¤Ø¤ÎźÉÕ',
        'msg_info'     => 'źÉÕ¥Õ¥¡¥¤¥ë¤Î¾ðÊó',
        'msg_confirm'  => '<p>%s ¤òºï½ü¤·¤Þ¤¹¡£</p>',
@@ -162,6 +163,8 @@ $_attach_messages = array(
        'msg_freeze'   => '¤³¤Î¥Õ¥¡¥¤¥ë¤òÅà·ë¤·¤Þ¤¹¡£',
        'msg_unfreeze' => '¤³¤Î¥Õ¥¡¥¤¥ë¤òÅà·ë²ò½ü¤·¤Þ¤¹¡£',
        'msg_isfreeze' => '¤³¤Î¥Õ¥¡¥¤¥ë¤ÏÅà·ë¤µ¤ì¤Æ¤¤¤Þ¤¹¡£',
+       'msg_rename'   => '̾Á°¤òÊѹ¹¤·¤Þ¤¹¡£',
+       'msg_newname'  => '¿·¤·¤¤Ì¾Á°',
        'msg_require'  => '(´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤¬É¬ÍפǤ¹)',
        'msg_filesize' => '¥µ¥¤¥º',
        'msg_date'     => 'ÅÐÏ¿Æü»þ',
@@ -175,6 +178,7 @@ $_attach_messages = array(
        'err_notfound' => '$1 ¤Ë¤½¤Î¥Õ¥¡¥¤¥ë¤Ï¸«¤Ä¤«¤ê¤Þ¤»¤ó',
        'err_noexist'  => 'źÉÕ¥Õ¥¡¥¤¥ë¤¬¤¢¤ê¤Þ¤»¤ó¡£',
        'err_delete'   => '$1 ¤«¤é¥Õ¥¡¥¤¥ë¤òºï½ü¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿',
+       'err_rename'   => '¥Õ¥¡¥¤¥ë̾¤òÊѹ¹¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿',
        'err_password' => '¥Ñ¥¹¥ï¡¼¥É¤¬°ìÃפ·¤Þ¤»¤ó¡£',
        'err_adminpass'=> '´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤¬°ìÃפ·¤Þ¤»¤ó¡£',
        'btn_upload'   => '¥¢¥Ã¥×¥í¡¼¥É',
index 4fb0d08..0aca7d3 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: attach.inc.php,v 1.80 2005/12/18 15:27:43 henoheno Exp $
+// $Id: attach.inc.php,v 1.81 2006/04/10 17:37:08 teanan Exp $
 // Copyright (C)
-//   2003-2005 PukiWiki Developers Team
+//   2003-2006 PukiWiki Developers Team
 //   2002-2003 PANDA <panda@arino.jp> http://home.arino.jp/
 //   2002      Y.MASUI <masui@hisec.co.jp> http://masui.net/pukiwiki/
 //   2001-2002 Originally written by yu-ji
@@ -32,6 +32,9 @@ define('PLUGIN_ATTACH_DELETE_ADMIN_NOBACKUP', TRUE); // FALSE or TRUE
 // ¥¢¥Ã¥×¥í¡¼¥É/ºï½ü»þ¤Ë¥Ñ¥¹¥ï¡¼¥É¤òÍ׵᤹¤ë(ADMIN_ONLY¤¬Í¥Àè)
 define('PLUGIN_ATTACH_PASSWORD_REQUIRE', FALSE); // FALSE or TRUE
 
+// ÅºÉÕ¥Õ¥¡¥¤¥ë̾¤òÊѹ¹¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë
+define('PLUGIN_ATTACH_RENAME_ENABLE', TRUE); // FALSE or TRUE
+
 // ¥Õ¥¡¥¤¥ë¤Î¥¢¥¯¥»¥¹¸¢
 define('PLUGIN_ATTACH_FILE_MODE', 0644);
 //define('PLUGIN_ATTACH_FILE_MODE', 0604); // for XREA.COM
@@ -118,6 +121,7 @@ function plugin_attach_action()
                case 'list'     : return attach_list();
                case 'freeze'   : return attach_freeze(TRUE);
                case 'unfreeze' : return attach_freeze(FALSE);
+               case 'rename'   : return attach_rename();
                case 'upload'   : return attach_showform();
                }
                if ($page == '' || ! is_page($page)) {
@@ -275,6 +279,26 @@ function attach_freeze($freeze)
        }
 }
 
+// ¥ê¥Í¡¼¥à
+function attach_rename()
+{
+       global $vars, $_attach_messages;
+
+       foreach (array('refer', 'file', 'age', 'pass', 'newname') as $var) {
+               ${$var} = isset($vars[$var]) ? $vars[$var] : '';
+       }
+
+       if (is_freeze($refer) || ! is_editable($refer)) {
+               return array('msg'=>$_attach_messages['err_noparm']);
+       }
+       $obj = & new AttachFile($refer, $file, $age);
+       if (! $obj->getstatus())
+               return array('msg'=>$_attach_messages['err_notfound']);
+
+       return $obj->rename($pass, $newname);
+
+}
+
 // ¥À¥¦¥ó¥í¡¼¥É
 function attach_open()
 {
@@ -502,6 +526,7 @@ class AttachFile
                $s_file = htmlspecialchars($this->file);
                $s_err = ($err == '') ? '' : '<p style="font-weight:bold">' . $_attach_messages[$err] . '</p>';
 
+               $msg_rename  = '';
                if ($this->age) {
                        $msg_freezed = '';
                        $msg_delete  = '<input type="radio" name="pcmd" id="_p_attach_delete" value="delete" />' .
@@ -525,6 +550,16 @@ class AttachFile
                                $msg_freeze  = '<input type="radio" name="pcmd" id="_p_attach_freeze" value="freeze" />' .
                                        '<label for="_p_attach_freeze">' .  $_attach_messages['msg_freeze'] .
                                        $_attach_messages['msg_require'] . '</label><br />';
+
+                               if (PLUGIN_ATTACH_RENAME_ENABLE) {
+                                       $msg_rename  = '<input type="radio" name="pcmd" id="_p_attach_rename" value="rename" />' .
+                                               '<label for="_p_attach_rename">' .  $_attach_messages['msg_rename'] .
+                                               $_attach_messages['msg_require'] . '</label><br />&nbsp;&nbsp;&nbsp;&nbsp;' .
+                                               '<label for="_p_attach_newname">' . $_attach_messages['msg_newname'] .
+                                               ':</label> ' .
+                                               '<input type="test" name="newname" id="_p_attach_newname" size="40" value="' .
+                                               $this->file . '" /><br />';
+                               }
                        }
                }
                $info = $this->toString(TRUE, FALSE);
@@ -556,6 +591,8 @@ $s_err
   <input type="hidden" name="age" value="{$this->age}" />
   $msg_delete
   $msg_freeze
+  $msg_rename
+  <br />
   <label for="_p_attach_password">{$_attach_messages['msg_password']}:</label>
   <input type="password" name="pass" id="_p_attach_password" size="8" />
   <input type="submit" value="{$_attach_messages['btn_submit']}" />
@@ -617,6 +654,31 @@ EOD;
                return array('msg'=>$_attach_messages['msg_deleted']);
        }
 
+       function rename($pass, $newname)
+       {
+               global $_attach_messages, $notify, $notify_subject;
+
+               if ($this->status['freeze']) return attach_info('msg_isfreeze');
+
+               if (! pkwk_login($pass)) {
+                       if (PLUGIN_ATTACH_DELETE_ADMIN_ONLY || $this->age) {
+                               return attach_info('err_adminpass');
+                       } else if (PLUGIN_ATTACH_PASSWORD_REQUIRE &&
+                               md5($pass) != $this->status['pass']) {
+                               return attach_info('err_password');
+                       }
+               }
+               $newbase = UPLOAD_DIR . encode($this->page) . '_' . encode($newname);
+               if (file_exists($newbase)) {
+                       return array('msg'=>$_attach_messages['err_exists']);
+               }
+               if (! PLUGIN_ATTACH_RENAME_ENABLE || ! rename($this->basename, $newbase)) {
+                       return array('msg'=>$_attach_messages['err_rename']);
+               }
+
+               return array('msg'=>$_attach_messages['msg_renamed']);
+       }
+
        function freeze($freeze, $pass)
        {
                global $_attach_messages;