OSDN Git Service

BugTrack/768: XHTML 1.1 hates font tag
[pukiwiki/pukiwiki.git] / plugin / links.inc.php
index 27402d2..fa008d2 100644 (file)
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: links.inc.php,v 1.12 2003/03/10 12:27:12 panda Exp $
+// $Id: links.inc.php,v 1.20 2004/07/31 03:09:20 henoheno Exp $
 //
 
-function plugin_links_action()
+// ¥á¥Ã¥»¡¼¥¸ÀßÄê
+function plugin_links_init()
 {
-       global $vars,$adminpass,$whatsnew;
-       
-       set_time_limit(0);
-       
-       if ($vars['page'] != '' and $vars['page'] != $whatsnew)
-       {
-               plugin_links_updatedata($vars['page']);
-               return;
-       }
-       if (md5($vars['adminpass']) != $adminpass)
-       {
-               return array('msg'=>'update database',
-                       'body'=>'<p>administrator password require.</p>');
-       }
-       return plugin_links_initdata();
-}
+       $messages = array(
+               '_links_messages'=>array(
+                       'title_update'  => '¥­¥ã¥Ã¥·¥å¹¹¿·',
+                       'msg_adminpass' => '´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É',
+                       'btn_submit'    => '¼Â¹Ô',
+                       'msg_done'      => '¥­¥ã¥Ã¥·¥å¤Î¹¹¿·¤¬´°Î»¤·¤Þ¤·¤¿¡£',
+                       'msg_usage'     => "
+* ½èÍýÆâÍÆ
 
-function plugin_links_initdata()
-{
-       global $whatsnew;
-       
-       if (defined('LINK_DB'))
-       {
-               // ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î½é´ü²½
-               $pages = get_existpages();
-               db_exec('DELETE FROM page;');
-               db_exec('DELETE FROM link;');
-               foreach ($pages as $page)
-               {
-                       if ($page == $whatsnew)
-                       {
-                               continue;
-                       }
-                       $time = get_filetime($page);
-                       $a_page = addslashes($page);
-                       db_exec("INSERT INTO page (name,lastmod) VALUES ('$a_page',$time);");
-               }
-               $rows = db_query('SELECT id,name FROM page;');
-               $pages = array();
-               foreach ($rows as $row)
-               {
-                       $pages[$row['name']] = $row['id'];
-               }
-               
-               $obj = new InlineConverter(array('page','auto')); 
-               foreach ($pages as $page=>$id)
-               {
-                       $links = $obj->get_objects(join('',preg_grep('/^(?!\/\/|\s)./',get_source($page))),$page);
-                       foreach ($links as $_obj)
-                       {
-                               if ($_obj->type != 'pagename')
-                               {
-                                       continue;
-                               }
-                               $_page = $_obj->name;
-                               if (!array_key_exists($_page,$pages))
-                               {
-                                       $a_page = addslashes($_page);
-                                       db_exec("INSERT INTO page (name) VALUES ('$a_page');");
-                                       $rows = db_query("SELECT id,name FROM page WHERE name='$a_page';");
-                                       $row = $rows[0];
-                                       $pages[$row['name']] = $row['id'];
-                               }       
-                                       
-                               $ref_id = $pages[$_page];
-                               if ($ref_id and $ref_id != $id)
-                               {
-                                       db_exec("INSERT INTO link (page_id,ref_id) VALUES ($id,$ref_id);");
-                               }
-                       }
-               }
-       }
-       else // if (!defined('LINK_DB'))
-       {
-               // ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î½é´ü²½
-               foreach (get_existfiles(CACHE_DIR,'.ref') as $cache)
-               {
-                       unlink($cache);
-               }
-               foreach (get_existfiles(CACHE_DIR,'.rel') as $cache)
-               {
-                       unlink($cache);
-               }
-               $pages = get_existpages();
-               $ref = array(); // »²¾È¸µ
-               $obj = new InlineConverter(array('page','auto')); 
-               foreach ($pages as $page)
-               {
-                       if ($page == $whatsnew)
-                       {
-                               continue;
-                       }
-                       $time = get_filetime($page);
-                       $rel = array(); // »²¾ÈÀè
-                       $links = $obj->get_objects(join('',preg_grep('/^(?!\/\/|\s)./',get_source($page))),$page);
-                       foreach ($links as $_obj)
-                       {
-                               if (!isset($_obj->type) or $_obj->type != 'pagename')
-                               {
-                                       continue;
-                               }                       
-                               $_page = $_obj->name;
-                               if ($_page != $page)
-                               {
-                                       $rel[$_page] = 1;
-                                       $ref[$_page][$page] = $time;
-                               }
-                       }
-                       if (count($rel))
-                       {
-                               $fp = fopen(CACHE_DIR.encode($page).'.rel','w')
-                                       or die_message('cannot write '.htmlspecialchars(CACHE_DIR.encode($page).'.rel'));
-                               fputs($fp,join("\t",array_keys($rel)));
-                               fclose($fp);
-                       }
-               }
-               
-               foreach ($ref as $page=>$arr)
-               {
-                       if (count($arr) == 0)
-                       {
-                               continue;
-                       }
-                       $fp = fopen(CACHE_DIR.encode($page).'.ref','w')
-                               or die_message('cannot write '.htmlspecialchars(CACHE_DIR.encode($page).'.ref'));
-                       foreach ($arr as $_page=>$time)
-                       {
-                               fputs($fp,"$_page\t$time\n");
-                       }
-                       fclose($fp);
-               }
-       }
-       return array('msg'=>'update database','body'=>'<p>done.</p>');
+:¥­¥ã¥Ã¥·¥å¤ò¹¹¿·|
+Á´¤Æ¤Î¥Ú¡¼¥¸¤ò¥¹¥­¥ã¥ó¤·¡¢¤¢¤ë¥Ú¡¼¥¸¤¬¤É¤Î¥Ú¡¼¥¸¤«¤é¥ê¥ó¥¯¤µ¤ì¤Æ¤¤¤ë¤«¤òÄ´ºº¤·¤Æ¡¢¥­¥ã¥Ã¥·¥å¤Ëµ­Ï¿¤·¤Þ¤¹¡£
+
+* Ãí°Õ
+¼Â¹Ô¤Ë¤Ï¿ôʬ¤«¤«¤ë¾ì¹ç¤â¤¢¤ê¤Þ¤¹¡£¼Â¹Ô¥Ü¥¿¥ó¤ò²¡¤·¤¿¤¢¤È¡¢¤·¤Ð¤é¤¯¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£
+
+* ¼Â¹Ô
+´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ·¤Æ¡¢[¼Â¹Ô]¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£
+"
+               )
+       );
+       set_plugin_messages($messages);
 }
-function plugin_links_updatedata($page)
+
+function plugin_links_action()
 {
-       global $whatsnew;
-       
-       if (defined('LINK_DB'))
+       global $script, $post, $vars, $foot_explain;
+       global $_links_messages;
+
+       if (empty($vars['action']) or empty($post['adminpass']) or ! pkwk_login($post['adminpass']))
        {
-               $is_page = is_page($page);
-               $time = ($is_page) ? get_filetime($page) : 0;
-               $a_page = addslashes($page);
-               
-               $rows = db_query("SELECT id FROM page WHERE name='$a_page';");
-               if (count($rows) == 0)
-               {
-                       if (!$is_page)
-                       {
-                               return;
-                       }
-                       db_exec("INSERT INTO page (name,lastmod) VALUES ('$a_page',$time);");
-                       $rows = db_query("SELECT id FROM page WHERE name='$a_page';");
-                       $id = $rows[0]['id'];
-               }
-               else // if (count($rows) > 0)
-               {
-                       $id = $rows[0]['id'];
-                       // $page¤¬»²¾È¤·¤Æ¤¤¤ë¥Ú¡¼¥¸¤ò½é´ü²½
-                       db_exec("DELETE FROM link WHERE page_id=$id;");
-                       if (!$is_page)
-                       {
-                               $_rows = db_query("SELECT * FROM link WHERE ref_id=$id;");
-                               if (count($_rows) == 0)
-                               {
-                                       // $page¤ò»²¾È¤·¤Æ¤¤¤ë¥Ú¡¼¥¸¤¬¤Ê¤¤¤Î¤Ç¡¢¤³¤Î¥ì¥³¡¼¥É¤òºï½ü
-                                       db_exec("DELETE FROM page WHERE id=$id;");
-                                       return;
-                               }
-                       }
-                       // ¥Ú¡¼¥¸¤Î¹¹¿·»þ¹ï¤ò¥»¥Ã¥È
-                       db_exec("UPDATE page SET lastmod=$time WHERE id=$id;");
-               }
-               
-               // cache
-               $pages = array();
-               
-               $obj = new InlineConverter();
-               $links = $obj->get_objects(join('',preg_grep('/^(?!\/\/|\s)./',get_source($page))),$page);
-               foreach ($links as $_obj)
-               {
-                       if (!isset($_obj->type) or $_obj->type != 'pagename' or $_obj->name == $page)
-                       {
-                               continue;
-                       }                       
-                       $_page = $_obj->name;
-                       if (!array_key_exists($_page,$pages))
-                       {
-                               $a_page = addslashes($_page);
-                               $rows = db_query("SELECT id,name FROM page WHERE name='$a_page';");
-                               if (count($rows) == 0)
-                               {
-                                       db_exec("INSERT INTO page (name,lastmod) VALUES ('$a_page',0);");
-                                       $rows = db_query("SELECT id,name FROM page WHERE name='$a_page';");
-                               }
-                               $pages[$rows[0]['name']] = TRUE;
-                               $ref_id =$rows[0]['id'];
-                               db_exec("INSERT INTO link (page_id,ref_id) VALUES ($id,$ref_id);");
-                       }
-               }
-               // Ã¯¤«¤é¤â»²¾È¤µ¤ì¤Ê¤¯¤Ê¤Ã¤¿¡Ö¸ºß¤·¤Ê¤¤¥Ú¡¼¥¸¡×¤ò¾Ãµî
-               // MySQL3¤Ï¡ÖÉûÌ䤤¹ç¤ï¤»¡×¤Ë̤Âбþ¡Ä?
-//             db_exec("DELETE FROM page WHERE id in (SELECT id FROM page LEFT JOIN link ON id=ref_id WHERE lastmod=0 AND page_id IS NULL);");
-               $rows = db_query("SELECT id FROM page LEFT JOIN link ON id=ref_id WHERE lastmod=0 AND page_id IS NULL;");
-               $_arr = array();
-               foreach ($rows as $row)
-               {
-                       $_arr[] = $row['id'];
-               }
-               if (count($_arr))
-               {
-                       db_exec("DELETE FROM page WHERE id in (".join(',',$_arr).");");
-               }
+               $body = convert_html($_links_messages['msg_usage']);
+               $body .= <<<EOD
+<form method="POST" action="$script">
+ <div>
+  <input type="hidden" name="plugin" value="links" />
+  <input type="hidden" name="action" value="update" />
+  {$_links_messages['msg_adminpass']}
+  <input type="password" name="adminpass" size="20" value="" />
+  <input type="submit" value="{$_links_messages['btn_submit']}" />
+ </div>
+</form>
+EOD;
+               return array(
+                       'msg'=>$_links_messages['title_update'],
+                       'body'=>$body
+               );
        }
-       else // if (!defined('LINK_DB'))
+       else if ($vars['action'] == 'update')
        {
-               $obj = new InlineConverter();
-               $time = is_page($page) ? get_filetime($page) : 0;
-               
-               $rel_old = array();
-               $rel_file = CACHE_DIR.encode($page).'.rel';
-               if (file_exists($rel_file))
-               {
-                       $lines = file($rel_file);
-                       if (array_key_exists(0,$lines))
-                       {
-                               $rel_old = explode("\t",rtrim($lines[0]));
-                       }
-                       unlink($rel_file);
-               }
-               $rel_new = array(); // »²¾ÈÀè
-               $links = $obj->get_objects(join('',preg_grep('/^(?!\/\/|\s)./',get_source($page))),$page);
-               foreach ($links as $_obj)
-               {
-                       if (!isset($_obj->type) or $_obj->type != 'pagename')
-                       {
-                               continue;
-                       }                       
-                       $_page = $_obj->name;
-                       if ($_page != $page)
-                       {
-                               $rel_new[$_page] = 1;
-                       }
-               }
-               
-               // .rel:$page¤¬»²¾È¤·¤Æ¤¤¤ë¥Ú¡¼¥¸¤Î°ìÍ÷
-               if (count($rel_new))
-               {
-                       $rel_new = array_keys($rel_new);
-                       $fp = fopen($rel_file,'w')
-                               or die_message('cannot write '.htmlspecialchars($rel_file));
-                       fputs($fp,join("\t",$rel_new));
-                       fclose($fp);
-               }
-               
-               // .ref:$_page¤ò»²¾È¤·¤Æ¤¤¤ë¥Ú¡¼¥¸¤Î°ìÍ÷
-               $add = array_diff($rel_new,$rel_old);
-               foreach ($add as $_page)
-               {
-                       $ref_file = CACHE_DIR.encode($_page).'.ref';
-                       $ref = "$page\t$time\n";
-                       if (file_exists($ref_file))
-                       {
-                               foreach (file($ref_file) as $line)
-                               {
-                                       list($ref_page,$time) = explode("\t",rtrim($line));
-                                       if ($ref_page != $page)
-                                       {
-                                               $ref .= $line;
-                                       }
-                               }
-                       }
-                       $fp = fopen($ref_file,'w')
-                                or die_message('cannot write '.htmlspecialchars($ref_file));
-                       fputs($fp,$ref);
-                       fclose($fp);
-               }
-               
-               $del = array_diff($rel_old,$rel_new);
-               foreach ($del as $_page)
-               {
-                       $ref_file = CACHE_DIR.encode($_page).'.ref';
-                       if (file_exists($ref_file))
-                       {
-                               $ref = '';
-                               foreach (file($ref_file) as $line)
-                               {
-                                       list($ref_page,$time) = explode("\t",rtrim($line));
-                                       if ($ref_page != $page)
-                                       {
-                                               $ref .= $line;
-                                       }
-                               }
-                               unlink($ref_file);
-                               if ($ref != '')
-                               {
-                                       $fp = fopen($ref_file,'w')
-                                               or die_message('cannot write '.htmlspecialchars($ref_file));
-                                       fputs($fp,$ref);
-                                       fclose($fp);
-                               }
-                       }
-               }
+               links_init();
+
+               // Ãí¼á¤ò¶õ¤Ë¤¹¤ë
+               $foot_explain = array();
+               return array(
+                       'msg'=>$_links_messages['title_update'],
+                       'body'=>$_links_messages['msg_done']
+               );
        }
+
+       return array(
+               'msg'=>$_links_messages['title_update'],
+               'body'=>$_links_messages['err_invalid']
+       );
 }
 ?>