# HG changeset patch # User Dan Fuhry # Date 1293647132 18000 # Node ID 12286b3ee21417e10634756ff8e30eeb97ea74a9 # Parent c7d6317c5e82dfcbaeb0cc2d5913b6075dd632be Added some more hooks to the page editing pipeline. It should now be possible to add controls to the page editor, send the data from them out to the server, and process them on the server side. diff -r c7d6317c5e82 -r 12286b3ee214 ajax.php --- a/ajax.php Wed Dec 29 13:23:58 2010 -0500 +++ b/ajax.php Wed Dec 29 13:25:32 2010 -0500 @@ -165,6 +165,12 @@ $return['toolbar_templates'] = $template->extract_vars('toolbar.tpl'); $return['edit_notice'] = $template->get_wiki_edit_notice(); + $code = $plugins->setHook('ajax_getsource_send_data'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + echo enano_json_encode($return); break; case "getpage": @@ -318,7 +324,7 @@ // Verification complete. Start the PageProcessor and let it do the dirty work for us. $page = new PageProcessor($paths->page_id, $paths->namespace); - if ( $page->update_page($request['src'], $request['summary'], ( $request['minor_edit'] == 1 ), $request['format']) ) + if ( $page->update_page($request['src'], $request['summary'], ( $request['minor_edit'] == 1 ), $request['format'], $request) ) { $return = array( 'mode' => 'success', diff -r c7d6317c5e82 -r 12286b3ee214 includes/clientside/static/editor.js --- a/includes/clientside/static/editor.js Wed Dec 29 13:23:58 2010 -0500 +++ b/includes/clientside/static/editor.js Wed Dec 29 13:25:32 2010 -0500 @@ -587,6 +587,8 @@ used_draft: used_draft }; + eval(setHook('editor_save_presend')); + // Do we need to add captcha info? if ( document.getElementById('enano_editor_field_captcha') && !is_draft ) { diff -r c7d6317c5e82 -r 12286b3ee214 includes/namespaces/default.php --- a/includes/namespaces/default.php Wed Dec 29 13:23:58 2010 -0500 +++ b/includes/namespaces/default.php Wed Dec 29 13:25:32 2010 -0500 @@ -730,7 +730,10 @@ $html .= '' . "\n\n"; } - if ( $this->namespace != 'Special' && $this->namespace != 'Admin' ) + // FIXME check_acl_scope here may not be a great idea... if there's no way to ever edit categorization OR tags for + // a given namespace because the permsissions don't allow for it, don't display the box at all. + if ( $this->namespace != 'Special' && $this->namespace != 'Admin' && + ($session->check_acl_scope('edit_cat', $this->namespace) || $session->check_acl_scope('tag_create', $this->namespace)) ) { $html .= '
'; $html .= '
'; diff -r c7d6317c5e82 -r 12286b3ee214 includes/pageprocess.php --- a/includes/pageprocess.php Wed Dec 29 13:23:58 2010 -0500 +++ b/includes/pageprocess.php Wed Dec 29 13:25:32 2010 -0500 @@ -367,21 +367,25 @@ * @param string A summary of edits made to the page. * @param bool If true, the edit is marked as a minor revision * @param string Page format - wikitext or xhtml. REQUIRED, and new in 1.1.6. + * @param array Optional - the entire incoming request. Plugins can add their own data to it. * @return bool True on success, false on failure. When returning false, it will push errors to the PageProcessor error stack; read with $page->pop_error() */ - function update_page($text, $edit_summary = false, $minor_edit = false, $page_format) + function update_page($text, $edit_summary = false, $minor_edit = false, $page_format, $raw_request = array()) { global $db, $session, $paths, $template, $plugins; // Common objects global $lang; // Create the page if it doesn't exist + $page_just_created = false; if ( !$this->page_exists ) { if ( !$this->create_page() ) { return false; } + // This is just to tell plugins if a page was just created, or is being edited. + $page_just_created = true; } // @@ -458,6 +462,18 @@ $minor_edit = ( $minor_edit ) ? '1' : '0'; $date_string = enano_date(ED_DATE | ED_TIME); + // Allow stuff to be run when the page is saved + $code = $plugins->setHook('update_page'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + // If a plugin raised an error, honor it. + if ( $this->_errors ) + { + return false; + } + // Insert log entry $sql = 'INSERT INTO ' . table_prefix . "logs ( time_id, date_string, log_type, action, page_id, namespace, author, author_uid, page_text, edit_summary, minor_edit, page_format )\n" . " VALUES ( $time, '$date_string', 'page', 'edit', '{$this->page_id}', '{$this->namespace}', '$author', $session->user_id, '$text', '$edit_summary', $minor_edit, '$page_format' );";