diff -r 4ccdfeee9a11 -r cdf24ba5f114 plugins/admin/PageEditor.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/admin/PageEditor.php Thu Jan 03 00:55:10 2008 -0500 @@ -0,0 +1,177 @@ +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_title') . '

'; + echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; + return; + } + + echo '

' . $lang->get('acped_heading_main') . '

'; + $show_select = true; + + if ( isset($_REQUEST['action']) || isset($_REQUEST['source']) ) + { + if ( isset($_REQUEST['action']) ) + { + $act =& $_REQUEST['action']; + $act = strtolower($act); + } + else if ( isset($_REQUEST['source']) && $_REQUEST['source'] == 'ajax' ) + { + $act = 'select'; + } + switch ( $act ) + { + case 'save': + case 'select': + // First step is to determine the page ID and namespace + + if ( isset($_REQUEST['pid_search']) ) + { + list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']); + $name = $db->escape(dirtify_page_id($page_id)); + $page_id = $db->escape(sanitize_page_id($page_id)); + $namespace = $db->escape($namespace); + $name = strtolower($name); + $page_id = strtolower($page_id); + $sql = "SELECT * FROM " . table_prefix . "pages WHERE ( " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '%$page_id%' OR " . ENANO_SQLFUNC_LOWERCASE . "(name) LIKE '%$name%' ) ORDER BY name ASC;"; + } + else + { + // pid_search was not set, assume absolute page ID + list($page_id, $namespace) = RenderMan::strToPageID($_REQUEST['page_id']); + $page_id = $db->escape(sanitize_page_id($page_id)); + $namespace = $db->escape($namespace); + + $sql = "SELECT * FROM " . table_prefix . "pages WHERE urlname = '$page_id' AND namespace = '$namespace';"; + } + + if ( !($q = $db->sql_query($sql)) ) + { + $db->_die('PageManager selecting dataset for page'); + } + + if ( $db->numrows() < 1 ) + { + echo '
+ ' . $lang->get('acped_err_page_not_found') . ' +
'; + break; + } + + if ( $db->numrows() > 1 ) + { + // Ambiguous results + if ( isset($_REQUEST['pid_search']) ) + { + echo '

' . $lang->get('acped_msg_results_ambiguous_title') . '

'; + echo '

' . $lang->get('acped_msg_results_ambiguous_body') . '

'; + echo ''; + $show_select = false; + break; + } + else + { + echo '

' . $lang->get('acped_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']; + $url = makeUrlNS($namespace, $page_id, false, true) . '#do:edit'; + $url = addslashes($url); + echo ''; + + $show_select = false; + break; + } + } + + if ( $show_select ) + { + echo '

' . $lang->get('acped_hint') . '

'; + + // Show the search form + + $form_action = makeUrlNS('Special', 'Administration', "module={$paths->nslist['Admin']}PageEditor", true); + echo "
"; + echo $lang->get('acped_lbl_field_search') . ' '; + echo $template->pagename_field('page_id') . ' '; + echo ''; + echo ''; + echo "
"; + + // Grab all pages from the database and show a list of pages on the site + + echo '

' . $lang->get('acped_heading_select_page_from_list') . '

'; + echo '

' . $lang->get('acped_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, \'edit\' AS mode 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']}PageEditor&offset=%s", false), + $pg_start, + 99, + array('urlname' => 'admin_pagemanager_format_listing'), + '
+ ', + '
+
' + ); + echo $html; + } + +} + +?>