diff -r ac34de920762 -r eefe9ab7fe7c plugins/admin/PageManager.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/admin/PageManager.php Sun Dec 30 01:13:24 2007 -0500 @@ -0,0 +1,594 @@ +auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); + echo '
' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '
'; + return; + } + + echo '' . $lang->get('acppm_msg_results_ambiguous_body') . '
'; + echo '' . $lang->get('acppm_err_ambig_absolute') . '
'; + break; + } + } + + // From this point on we can assume that exactly one matching page was found. + $dataset = $db->fetchrow(); + $page_id = $dataset['urlname']; + $namespace = $dataset['namespace']; + + // This is used to re-determine the page ID after submit. + $pathskey = $paths->nslist[$namespace] . sanitize_page_id($page_id); + + // The extra switch allows us to break out of the save routine if needed + switch ( $act ) + { + case 'save': + + $errors = array(); + $page_id_changed = false; + $namespace_changed = false; + + // Backup the dataset to avoid redundantly updating values + $dataset_backup = $dataset; + + // We've elected to save the page. The angle of attack here is to validate each form field, + // and if the field validates successfully, change the value in $dataset accordingly. + + // Field: page name + $page_name = $_POST['page_name']; + $page_name = trim($page_name); + if ( empty($page_name) ) + { + $errors[] = $lang->get('acppm_err_invalid_page_name'); + } + else + { + $dataset['name'] = $page_name; + } + + // Field: page URL string + $page_urlname = $_POST['page_urlname']; + $page_urlname = trim($_POST['page_urlname']); + if ( empty($page_urlname) && getConfig('main_page') !== '' ) + { + $errors[] = $lang->get('acppm_err_invalid_url_string'); + } + else + { + $page_id_changed = ( $_POST['page_urlname'] !== $dataset['urlname'] ); + $dataset['urlname'] = sanitize_page_id($page_urlname); + } + + // Field: namespace + $namespace = $_POST['page_namespace']; + if ( !isset($paths->nslist[ $namespace ]) ) + { + $errors[] = $lang->get('acppm_err_invalid_namespace'); + } + else + { + $namespace_changed = ( $_POST['page_namespace'] !== $dataset['namespace'] ); + $dataset['namespace'] = $namespace; + } + + // Field: comments enabled + $dataset['comments_on'] = ( isset($_POST['comments_on']) ) ? 1 : 0; + + // Field: page visible + $dataset['visible'] = ( isset($_POST['visible']) ) ? 1 : 0; + + // Field: standalone page + $dataset['special'] = ( isset($_POST['special']) ) ? 1 : 0; + + // Field: page protection + $protect_level = $_POST['protected']; + if ( !in_array($protect_level, array('0', '1', '2')) ) + { + $errors[] = $lang->get('acppm_err_invalid_protection'); + } + else + { + $dataset['protected'] = intval($protect_level); + } + + // Field: wiki mode + $wiki_mode = $_POST['wikimode']; + if ( !in_array($wiki_mode, array('0', '1', '2')) ) + { + $errors[] = $lang->get('acppm_err_invalid_wiki_mode'); + } + else + { + $dataset['wiki_mode'] = intval($wiki_mode); + } + + if ( count($errors) < 1 ) + { + // We're free of errors. Build a SQL query to update the page table. + $particles = array(); + + foreach ( $dataset as $key => $value ) + { + if ( $value === $dataset_backup[$key] || ( is_int($value) && $value === intval($dataset_backup[$key]) ) ) + continue; + if ( is_int($value) ) + { + $particle = "$key = $value"; + } + else + { + $value = $db->escape($value); + $particle = "$key = '$value'"; + } + $particles[] = $particle; + unset($particle); + } + + $page_id_new = $db->escape($dataset['urlname']); + $namespace_new = $db->escape($dataset['namespace']); + + // Only run the update query if at least one field was changed. + if ( count($particles) > 0 ) + { + $particles = implode(', ', $particles); + $page_id_db = $db->escape($page_id); + $namespace_db = $db->escape($namespace); + $sql = 'UPDATE ' . table_prefix . "pages SET $particles WHERE urlname = '$page_id_db' AND namespace = '$namespace_db';"; + + if ( !$db->sql_query($sql) ) + $db->_die('PageManager running primary update query'); + + // Did we change the page ID or namespace? If so we need to also change logs, comments, tags, etc. + if ( $page_id_changed || $namespace_changed ) + { + $sql = array( + 'UPDATE ' . table_prefix . "logs SET page_id = '$page_id_new', namespace = '$namespace_new' WHERE page_id = '$page_id_db' AND namespace = '$namespace_db';", + 'UPDATE ' . table_prefix . "tags SET page_id = '$page_id_new', namespace = '$namespace_new' WHERE page_id = '$page_id_db' AND namespace = '$namespace_db';", + 'UPDATE ' . table_prefix . "comments SET page_id = '$page_id_new', namespace = '$namespace_new' WHERE page_id = '$page_id_db' AND namespace = '$namespace_db';", + 'UPDATE ' . table_prefix . "page_text SET page_id = '$page_id_new', namespace = '$namespace_new' WHERE page_id = '$page_id_db' AND namespace = '$namespace_db';", + 'UPDATE ' . table_prefix . "categories SET page_id = '$page_id_new', namespace = '$namespace_new' WHERE page_id = '$page_id_db' AND namespace = '$namespace_db';" + ); + foreach ( $sql as $q ) + { + if ( !$db->sql_query($q) ) + $db->_die('PageManager running slave update query after page ID/namespace change'); + } + } + + // Did we change the name of the page? If so, make PageUtils log it + if ( $dataset_backup['name'] != $dataset['name'] ) + { + PageUtils::rename($page_id_new, $namespace_new, $dataset['name']); + } + } + + // Did the user ask to delete the page? + if ( isset($_POST['delete']) ) + { + PageUtils::deletepage($page_id_new, $namespace_new, $lang->get('acppm_delete_reason')); + } + + echo '+ {lang:acppm_heading_editing} "{PAGE_NAME}" + | +|
---|---|
+ {lang:acppm_lbl_page_name} + | ++ + | +
+ {lang:acppm_lbl_page_urlname} + {lang:acppm_lbl_page_urlname_hint} + |
+ + + | +
+ {lang:acppm_lbl_namespace} + | ++ + | +
+ {lang:acppm_heading_advanced} + | +|
+ {lang:acppm_lbl_enable_comments_title} + | +
+
+ + {lang:acppm_lbl_enable_comments_hint} + |
+
+ {lang:acppm_lbl_special_title} + | +
+
+ + {lang:acppm_lbl_special_hint} + |
+
+ {lang:acppm_lbl_visible_title} + | +
+
+ + {lang:acppm_lbl_visible_hint} + |
+
+ {lang:acppm_lbl_protected_title} + | +
+
+ + + + + + {lang:acppm_lbl_protected_hint} + |
+
+ {lang:acppm_lbl_wikimode_title} + | +
+
+ + + + + + {lang:acppm_lbl_wikimode_hint} + |
+
+ {lang:acppm_lbl_delete_title} + | +
+
+ + {lang:acppm_lbl_delete_hint} + |
+
+ + + | +
' . $lang->get('acppm_hint') . '
'; + + // Show the search form + + $form_action = makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageManager", true); + echo ""; + + // Grab all pages from the database and show a list of pages on the site + + echo '' . $lang->get('acppm_hint_select_page_from_list') . '
'; + + $q = $db->sql_query('SELECT COUNT(name) AS num_pages FROM ' . table_prefix . 'pages;'); + if ( !$q ) + $db->_die('PageManager doing initial page count'); + list($num_pages) = $db->fetchrow_num(); + $db->free_result(); + + $pg_start = ( isset($_GET['offset']) ) ? intval($_GET['offset']) : 0; + + $q = $db->sql_unbuffered_query('SELECT urlname, name, namespace, ' . $num_pages . ' AS num_pages, ' . $pg_start . ' AS offset FROM ' . table_prefix . 'pages ORDER BY name ASC;'); + if ( !$q ) + $db->_die('PageManager doing main select query for page list'); + + // Paginate results + $html = paginate( + $q, + '{urlname}', + $num_pages, + makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageManager&offset=%s", false), + $pg_start, + 99, + array('urlname' => 'admin_pagemanager_format_listing'), + '