includes/pageprocess.php
changeset 335 67bd3121a12e
parent 329 0437a7cf1acc
child 343 eefe9ab7fe7c
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
   349   
   349   
   350   /**
   350   /**
   351    * Updates the content of the page.
   351    * Updates the content of the page.
   352    * @param string The new text for the page
   352    * @param string The new text for the page
   353    * @param string A summary of edits made to the page.
   353    * @param string A summary of edits made to the page.
       
   354    * @param bool If true, the edit is marked as a minor revision
   354    * @return bool True on success, false on failure
   355    * @return bool True on success, false on failure
   355    */
   356    */
   356   
   357   
   357   function update_page($text, $edit_summary = false)
   358   function update_page($text, $edit_summary = false, $minor_edit = false)
   358   {
   359   {
   359     global $db, $session, $paths, $template, $plugins; // Common objects
   360     global $db, $session, $paths, $template, $plugins; // Common objects
       
   361     global $lang;
   360     
   362     
   361     // Create the page if it doesn't exist
   363     // Create the page if it doesn't exist
   362     if ( !$this->page_exists )
   364     if ( !$this->page_exists )
   363     {
   365     {
   364       if ( !$this->create_page() )
   366       if ( !$this->create_page() )
   377     $q = $db->sql_query('SELECT protected FROM ' . table_prefix . "pages WHERE urlname='$page_id' AND namespace='$namespace';");
   379     $q = $db->sql_query('SELECT protected FROM ' . table_prefix . "pages WHERE urlname='$page_id' AND namespace='$namespace';");
   378     if ( !$q )
   380     if ( !$q )
   379       $db->_die('PageProcess updating page content');
   381       $db->_die('PageProcess updating page content');
   380     if ( $db->numrows() < 1 )
   382     if ( $db->numrows() < 1 )
   381     {
   383     {
   382       $this->raise_error('Page doesn\'t exist in the database');
   384       $this->raise_error($lang->get('editor_err_no_rows'));
   383       return false;
   385       return false;
   384     }
   386     }
   385     
   387     
   386     // Do we have permission to edit the page?
   388     // Do we have permission to edit the page?
   387     if ( !$this->perms->get_permissions('edit_page') )
   389     if ( !$this->perms->get_permissions('edit_page') )
   388     {
   390     {
   389       $this->raise_error('You do not have permission to edit this page.');
   391       $this->raise_error($lang->get('editor_err_no_permission'));
   390       return false;
   392       return false;
   391     }
   393     }
   392     
   394     
   393     list($protection) = $db->fetchrow_num();
   395     list($protection) = $db->fetchrow_num();
   394     $db->free_result();
   396     $db->free_result();
   396     if ( $protection == 1 )
   398     if ( $protection == 1 )
   397     {
   399     {
   398       // The page is protected - do we have permission to edit protected pages?
   400       // The page is protected - do we have permission to edit protected pages?
   399       if ( !$this->perms->get_permissions('even_when_protected') )
   401       if ( !$this->perms->get_permissions('even_when_protected') )
   400       {
   402       {
   401         $this->raise_error('This page is protected, and you do not have permission to edit protected pages.');
   403         $this->raise_error($lang->get('editor_err_page_protected'));
   402         return false;
   404         return false;
   403       }
   405       }
   404     }
   406     }
   405     else if ( $protection == 2 )
   407     else if ( $protection == 2 )
   406     {
   408     {
   408       if (
   410       if (
   409            ( !$session->user_logged_in || // Is the user logged in?
   411            ( !$session->user_logged_in || // Is the user logged in?
   410              ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days?
   412              ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days?
   411            && !$this->perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection?
   413            && !$this->perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection?
   412       {
   414       {
   413         $this->raise_error('This page is protected, and you do not have permission to edit protected pages.');
   415         $this->raise_error($lang->get('editor_err_page_protected'));
   414         return false;
   416         return false;
   415       }
   417       }
   416     }
   418     }
   417     
   419     
   418     // Protection validated
   420     //
       
   421     // Protection validated; update page content
       
   422     //
       
   423     
       
   424     $text_undb = RenderMan::preprocess_text($text, false, false);
       
   425     $text = $db->escape($text_undb);
       
   426     $author = $db->escape($session->username);
       
   427     $time = time();
       
   428     $edit_summary = ( strval($edit_summary) === $edit_summary ) ? $db->escape($edit_summary) : '';
       
   429     $minor_edit = ( $minor_edit ) ? '1' : '0';
       
   430     $date_string = date('d M Y h:i a');
       
   431     
       
   432     // Insert log entry
       
   433     $sql = 'INSERT INTO ' . table_prefix . "logs ( time_id, date_string, log_type, action, page_id, namespace, author, page_text, edit_summary, minor_edit )\n"
       
   434          . "  VALUES ( $time, '$date_string', 'page', 'edit', '{$this->page_id}', '{$this->namespace}', '$author', '$text', '$edit_summary', $minor_edit );";
       
   435     if ( !$db->sql_query($sql) )
       
   436     {
       
   437       $this->raise_error($db->get_error());
       
   438       return false;
       
   439     }
       
   440     
       
   441     // Update the master text entry
       
   442     $sql = 'UPDATE ' . table_prefix . "page_text SET page_text = '$text' WHERE page_id = '{$this->page_id}' AND namespace = '{$this->namespace}';";
       
   443     if ( !$db->sql_query($sql) )
       
   444     {
       
   445       $this->raise_error($db->get_error());
       
   446       return false;
       
   447     }
       
   448     
       
   449     // Rebuild the search index
       
   450     $paths->rebuild_page_index($this->page_id, $this->namespace);
       
   451     
       
   452     $this->text_cache = $text;
       
   453     
       
   454     return true;
   419     
   455     
   420   }
   456   }
   421   
   457   
   422   /**
   458   /**
   423    * Creates the page if it doesn't already exist.
   459    * Creates the page if it doesn't already exist.