@@ -3478,7 +3478,7 @@ function pginfo_rename_db_write ($fromname, $toname) {
3478
3478
}
3479
3479
3480
3480
// リンク情報更新準備
3481
- $ this ->plain_db_write ($ fromname ," delete " );
3481
+ $ this ->plain_db_write ($ fromname , ' delete ' );
3482
3482
3483
3483
$ _toname = addslashes ($ toname );
3484
3484
$ reading = addslashes ($ this ->get_page_reading ($ toname , TRUE ));
@@ -3711,14 +3711,21 @@ function plain_db_write($page, $action, $init = FALSE, $notimestamp = FALSE)
3711
3711
// ページ削除
3712
3712
elseif ($ action === 'delete ' )
3713
3713
{
3714
- $ query = "DELETE FROM " .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname ."_plain " )." WHERE pgid = $ pgid; " ;
3714
+ $ plugin = end ($ this ->root ->plugin_stack );
3715
+
3716
+ $ query = "DELETE FROM " .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname ."_plain " )." WHERE pgid = $ pgid " ;
3715
3717
$ result =$ this ->xpwiki ->db ->queryF ($ query );
3716
- //if (!$result) echo $query."<hr>";
3717
3718
3718
3719
//リンクページ
3719
- $ query = "DELETE FROM " .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname ."_rel " )." WHERE pgid = " .$ pgid ." OR relid = " .$ pgid. " ; " ;
3720
+ $ query = "DELETE FROM " .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname ."_rel " )." WHERE pgid = " .$ pgid ." OR relid = " .$ pgid ;
3720
3721
$ result =$ this ->xpwiki ->db ->queryF ($ query );
3721
3722
3723
+ if ($ plugin !== 'rename ' ) {
3724
+ // alias
3725
+ $ query = "DELETE FROM " .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname ."_alias " )." WHERE pgid = $ pgid " ;
3726
+ $ result =$ this ->xpwiki ->db ->queryF ($ query );
3727
+ }
3728
+
3722
3729
// Optimaize DB tables
3723
3730
$ tables = array ();
3724
3731
foreach (array ('attach ' , 'cache ' , 'count ' , 'pginfo ' , 'plain ' , 'rel ' , 'tb ' ) as $ table ) {
@@ -4327,32 +4334,34 @@ function get_page_reading ($page, $init = FALSE) {
4327
4334
4328
4335
// ページ別名を取得
4329
4336
function get_page_alias ($ page , $ as_array = false , $ clr = false , $ path = 'real ' ) {
4330
- static $ pg_ary ;
4331
-
4337
+ static $ pg_ary = array ();
4338
+
4339
+ if (! isset ($ pg_ary [$ this ->xpwiki ->pid ])) {
4340
+ $ pg_ary [$ this ->xpwiki ->pid ] = array ();
4341
+ }
4342
+
4332
4343
if ($ path !== 'real ' ) $ path = 'relative ' ;
4333
4344
4334
- if ($ clr || !isset ($ pg_ary [$ this ->xpwiki ->pid ])) {
4335
- $ _tmp = $ pg_ary [$ this ->xpwiki ->pid ] = array ();
4345
+ if ($ clr || ! isset ($ pg_ary [$ this ->xpwiki ->pid ][ $ page ])) {
4346
+ $ pg_ary [$ this ->xpwiki ->pid ][ $ page ] = array ();
4336
4347
$ dirreg = '#^ ' . preg_quote ($ this ->page_dirname ($ page ), '# ' ) . '/# ' ;
4337
- foreach ($ this ->root ->page_aliases as $ _alias => $ _page ) {
4338
- $ pg_ary [$ this ->xpwiki ->pid ][$ _page ]['real ' ][] = $ _alias ;
4339
- $ pg_ary [$ this ->xpwiki ->pid ][$ _page ]['relative ' ][] = preg_replace ($ dirreg , '../ ' , $ _alias );
4340
- }
4341
- foreach ($ pg_ary [$ this ->xpwiki ->pid ] as $ _page => $ _ary ) {
4342
- natcasesort ($ pg_ary [$ this ->xpwiki ->pid ][$ _page ]['real ' ]);
4343
- natcasesort ($ pg_ary [$ this ->xpwiki ->pid ][$ _page ]['relative ' ]);
4344
- }
4348
+ $ _alias = $ this ->get_pagealiases (array ($ page ));
4349
+ $ pg_ary [$ this ->xpwiki ->pid ][$ page ]['real ' ] = $ _alias ;
4350
+ $ pg_ary [$ this ->xpwiki ->pid ][$ page ]['relative ' ] = preg_replace ($ dirreg , '../ ' , $ _alias );
4351
+ natcasesort ($ pg_ary [$ this ->xpwiki ->pid ][$ page ]['real ' ]);
4352
+ natcasesort ($ pg_ary [$ this ->xpwiki ->pid ][$ page ]['relative ' ]);
4345
4353
}
4346
-
4347
- $ ret = (isset ($ pg_ary [$ this ->xpwiki ->pid ][$ page ]))? $ pg_ary [$ this ->xpwiki ->pid ][$ page ][$ path ] : array ();
4354
+
4355
+ $ ret = (! empty ($ pg_ary [$ this ->xpwiki ->pid ][$ page ]))? $ pg_ary [$ this ->xpwiki ->pid ][$ page ][$ path ] : array ();
4356
+
4348
4357
if ($ as_array ) return $ ret ;
4349
4358
return join (': ' , $ ret );
4350
4359
}
4351
4360
4352
4361
// ページ別名を保存
4353
4362
function put_page_alias ($ page , $ alias ) {
4354
- if (!$ alias && in_array ( $ page , $ this ->root -> page_aliases ) === false ) return false ;
4355
-
4363
+ if (!$ alias && ! $ aliases_old = $ this ->get_page_alias ( $ page , true ) ) return false ;
4364
+
4356
4365
$ alias = trim ($ alias );
4357
4366
$ alias = preg_replace ('/[\r\n]+/ ' , ': ' , $ alias );
4358
4367
$ aliases = explode (': ' , $ alias );
@@ -4364,74 +4373,94 @@ function put_page_alias ($page, $alias) {
4364
4373
natcasesort ($ aliases );
4365
4374
$ aliases = array_slice ($ aliases , 0 );
4366
4375
}
4367
-
4376
+
4368
4377
$ aliases_old = $ this ->get_page_alias ($ page , true );
4369
4378
$ aliases_old = array_slice ($ aliases_old , 0 );
4370
-
4379
+
4371
4380
if ($ aliases_old === $ aliases ) return false ;
4372
-
4373
- $ this ->root ->page_aliases = array_diff ($ this ->root ->page_aliases , array ($ page ));
4374
-
4381
+
4375
4382
if ($ alias ) {
4383
+ $ pgid = $ this ->get_pgid_by_name ($ page );
4384
+ $ query = 'DELETE FROM ` ' .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname .'_alias ' ).'` WHERE `pgid`= ' .$ pgid ;
4385
+ $ this ->xpwiki ->db ->query ($ query );
4386
+ $ query = array ();
4376
4387
foreach ($ aliases as $ _alias ) {
4377
4388
$ _check = ($ this ->root ->page_case_insensitive )? $ this ->get_pagename_realcase ($ _alias ) : $ _alias ;
4378
- if (!isset ( $ this -> root -> page_aliases [ $ _alias ]) && ! $ this ->is_page ($ _check )) {
4379
- $ this ->root -> page_aliases [ $ _alias] = $ page ;
4389
+ if (!$ this ->is_page ($ _check )) {
4390
+ $ query [] = ' ( ' . $ this ->xpwiki -> db -> quoteString ( $ _alias). ' , ' . $ this -> get_pgid_by_name ( $ page). ' ) ' ;
4380
4391
}
4381
4392
}
4393
+ if ($ query ) {
4394
+ $ query = 'INSERT INTO ` ' .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname .'_alias ' ).'` (`name`,`pgid`) VALUES ' .join (', ' , $ query );
4395
+ $ this ->xpwiki ->db ->query ($ query );
4396
+ }
4382
4397
}
4383
-
4384
- // save
4385
- $ this ->save_page_alias ();
4386
-
4398
+
4387
4399
// Cache remake of get_page_alias()
4388
- $ this ->get_page_alias ('' , true , true );
4389
-
4400
+ $ this ->get_page_alias ($ page , true , true );
4401
+
4390
4402
return true ;
4391
4403
}
4392
4404
4393
4405
function save_page_alias () {
4394
- natcasesort ($ this ->root ->page_aliases );
4395
- $ page_aliases_i = array_change_key_case ($ this ->root ->page_aliases , CASE_LOWER );
4396
-
4397
- $ quote ['from ' ] = array ('\\' , "' " ,);
4398
- $ quote ['to ' ] = array ('\\\\' , "\\' " );
4399
-
4400
- $ dat = "\$root->page_aliases = array( \n" ;
4401
- foreach ($ this ->root ->page_aliases as $ _alias => $ _page ) {
4402
- $ _alias = str_replace ($ quote ['from ' ], $ quote ['to ' ], $ _alias );
4403
- $ _page = str_replace ($ quote ['from ' ], $ quote ['to ' ], $ _page );
4404
- $ dat .= "\t' {$ _alias }' => ' {$ _page }', \n" ;
4405
- }
4406
- $ dat .= "); \n" ;
4407
-
4408
- //$this->save_config('pukiwiki.ini.php', 'page_aliases', $dat);
4409
-
4410
- $ dat .= "\$root->page_aliases_i = array( \n" ;
4411
- foreach ($ page_aliases_i as $ _alias => $ _page ) {
4412
- $ _alias = str_replace ($ quote ['from ' ], $ quote ['to ' ], $ _alias );
4413
- $ _page = str_replace ($ quote ['from ' ], $ quote ['to ' ], $ _page );
4414
- $ dat .= "\t' {$ _alias }' => ' {$ _page }', \n" ;
4415
- }
4416
- $ dat .= "); " ;
4417
-
4418
- $ this ->save_config ('pukiwiki.ini.php ' , 'page_aliases ' , $ dat );
4419
-
4420
4406
// Clear cache *.api
4421
4407
$ GLOBALS ['xpwiki_cache_deletes ' ][$ this ->cont ['CACHE_DIR ' ]]['api ' ] = '*.autolink.api ' ;
4422
4408
}
4423
4409
4424
4410
// ページ別名が設定されているか
4425
4411
function is_alias ($ name ) {
4412
+ $ page = $ this ->get_name_by_alias ($ name );
4413
+ return ($ page === '' )? false : $ page ;
4414
+ }
4415
+
4416
+ // db からページ別名一覧を取得
4417
+ function get_pagealiases ($ pages = array (), $ asKey = false ) {
4418
+ $ aliases = array ();
4419
+ $ in = array ();
4420
+ if ($ pages ) {
4421
+ foreach ($ pages as $ page ) {
4422
+ if ($ pgid = $ this ->get_pgid_by_name ($ page )) {
4423
+ $ in [] = $ pgid ;
4424
+ }
4425
+ }
4426
+ }
4427
+ if (! $ pages || $ in ) {
4428
+ $ where = '' ;
4429
+ if ($ in ) {
4430
+ $ where = ' WHERE `pgid` IN ( ' .join (', ' , $ in ).') ' ;
4431
+ }
4432
+ $ query = 'SELECT `name` ' .($ asKey ? ', `pgid` ' : '' ).' FROM ` ' .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname .'_alias ' ).'` ' .$ where ;
4433
+ if ($ result = $ this ->xpwiki ->db ->query ($ query )) {
4434
+ while ($ alias = $ this ->xpwiki ->db ->fetchRow ($ result )) {
4435
+ if (! $ asKey ) {
4436
+ $ aliases [] = $ alias [0 ];
4437
+ } else {
4438
+ $ aliases [$ alias [0 ]] = $ alias [1 ];
4439
+ }
4440
+ }
4441
+ }
4442
+ }
4443
+ return $ aliases ;
4444
+ }
4445
+
4446
+ // db からページ別名に対応する実ページ名を取得
4447
+ function get_name_by_alias ($ alias ) {
4448
+ $ page = '' ;
4426
4449
if ($ this ->root ->page_case_insensitive ) {
4427
- $ page_aliases = $ this ->root ->page_aliases_i ;
4428
- $ name = strtolower ($ name );
4450
+ $ where = ' WHERE LOWER(`name`)= ' .$ this ->xpwiki ->db ->quoteString (strtolower ($ alias ));
4429
4451
} else {
4430
- $ page_aliases = $ this ->root ->page_aliases ;
4452
+ $ where = ' WHERE `name`= ' .$ this ->xpwiki ->db ->quoteString ($ alias );
4453
+ }
4454
+ $ query = 'SELECT `pgid` FROM ` ' .$ this ->xpwiki ->db ->prefix ($ this ->root ->mydirname .'_alias ' ).'` ' .$ where .' LIMIT 1 ' ;
4455
+ //exit($query);
4456
+ if ($ result = $ this ->xpwiki ->db ->query ($ query )) {
4457
+ list ($ pgid ) = $ this ->xpwiki ->db ->fetchRow ($ result );
4458
+ $ page = $ this ->get_name_by_pgid ($ pgid );
4431
4459
}
4432
- return isset ( $ page_aliases [ $ name ])? $ page_aliases [ $ name ] : FALSE ;
4460
+ return $ page ;
4433
4461
}
4434
-
4462
+
4463
+
4435
4464
// ページオーダーを取得
4436
4465
function get_page_order ($ page ) {
4437
4466
if (! isset ($ this ->root ->pgorders [$ page ])) {
0 commit comments