Limit Page name length for wiki and ref files.
* Normally - 115 bytes (38 Japaneses chars); 230 bytes in wiki base name.
* Hard limit - 125 bytes (41 Japaneses chars); 250 bytes in wiki base name.
For existing page in history, we can name long page within hard limit.
/** Absolute URI. */
define('PKWK_URI_ABSOLUTE', 2);
+/** New page name - its length is need to be within the soft limit. */
+define('PKWK_PAGENAME_BYTES_SOFT_LIMIT', 115);
+/** Page name - its length is need to be within the hard limit. */
+define('PKWK_PAGENAME_BYTES_HARD_LIMIT', 125);
+
function pkwk_log($message)
{
$log_filepath = 'log/error.log.php';
return file_exists(get_filename($page));
}
+function is_pagename_bytes_within_soft_limit($page)
+{
+ return strlen($page) <= PKWK_PAGENAME_BYTES_SOFT_LIMIT;
+}
+
+function is_pagename_bytes_within_hard_limit($page)
+{
+ return strlen($page) <= PKWK_PAGENAME_BYTES_SOFT_LIMIT;
+}
+
+function page_exists_in_history($page)
+{
+ if (is_page($page)) {
+ return true;
+ }
+ $diff_file = DIFF_DIR . encode($page) . '.txt';
+ if (file_exists($diff_file)) {
+ return true;
+ }
+ $backup_file = BACKUP_DIR . encode($page) . BACKUP_EXT;
+ if (file_exists($backup_file)) {
+ return true;
+ }
+ return false;
+}
+
function is_editable($page)
{
global $cantedit;
<?php
// PukiWiki - Yet another WikiWikiWeb clone
// link.php
-// Copyright 2003-2020 PukiWiki Development Team
+// Copyright 2003-2022 PukiWiki Development Team
// License: GPL v2 or (at your option) any later version
//
// Backlinks / AutoLinks related functions
}
unlink($ref_file);
}
+ if (! $is_page) {
+ if (! is_pagename_bytes_within_soft_limit($_page)) {
+ continue;
+ }
+ }
if ($is_page || ! $all_auto) {
$fp = fopen($ref_file, 'w')
or die_message('cannot write ' . htmlsc($ref_file));
<?php
// PukiWiki - Yet another WikiWikiWeb clone.
// edit.inc.php
-// Copyright 2001-2019 PukiWiki Development Team
+// Copyright 2001-2022 PukiWiki Development Team
// License: GPL v2 or (at your option) any later version
//
// Edit plugin (cmd=edit)
} else if (isset($vars['cancel'])) {
return plugin_edit_cancel();
}
-
+ ensure_valid_page_name_length($page);
$postdata = @join('', get_source($page));
if ($postdata === '') $postdata = auto_template($page);
$postdata = remove_author_info($postdata);
return array('msg'=>$_title_edit, 'body'=>edit_form($page, $postdata));
}
+function ensure_valid_page_name_length($page)
+{
+ if (is_page($page)) {
+ // Continue
+ } else {
+ if (is_pagename_bytes_within_soft_limit($page)) {
+ // Continue
+ } else {
+ if (page_exists_in_history($page)) {
+ if (is_pagename_bytes_within_hard_limit($page)) {
+ // Continue
+ } else {
+ die_message('Page name too long (hard limit): ' . htmlsc($page));
+ exit;
+ }
+ } else {
+ die_message('Page name too long: ' . htmlsc($page));
+ exit;
+ }
+ }
+ }
+}
+
/**
* Preview with template
*/
$add = isset($vars['add']) ? $vars['add'] : '';
$digest = isset($vars['digest']) ? $vars['digest'] : '';
+ ensure_valid_page_name_length($page);
$vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
$msg = & $vars['msg']; // Reference