includes/pageprocess.php
changeset 1332 12286b3ee214
parent 1252 e34c23a35dc9
child 1343 2a31905a567d
equal deleted inserted replaced
1331:c7d6317c5e82 1332:12286b3ee214
   365  	* Updates (saves/changes/edits) the content of the page.
   365  	* Updates (saves/changes/edits) the content of the page.
   366  	* @param string The new text for the page
   366  	* @param string The new text for the page
   367  	* @param string A summary of edits made to the page.
   367  	* @param string A summary of edits made to the page.
   368  	* @param bool If true, the edit is marked as a minor revision
   368  	* @param bool If true, the edit is marked as a minor revision
   369  	* @param string Page format - wikitext or xhtml. REQUIRED, and new in 1.1.6.
   369  	* @param string Page format - wikitext or xhtml. REQUIRED, and new in 1.1.6.
       
   370  	* @param array Optional - the entire incoming request. Plugins can add their own data to it.
   370  	* @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()
   371  	* @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()
   371  	*/
   372  	*/
   372 	
   373 	
   373 	function update_page($text, $edit_summary = false, $minor_edit = false, $page_format)
   374 	function update_page($text, $edit_summary = false, $minor_edit = false, $page_format, $raw_request = array())
   374 	{
   375 	{
   375 		global $db, $session, $paths, $template, $plugins; // Common objects
   376 		global $db, $session, $paths, $template, $plugins; // Common objects
   376 		global $lang;
   377 		global $lang;
   377 		
   378 		
   378 		// Create the page if it doesn't exist
   379 		// Create the page if it doesn't exist
       
   380 		$page_just_created = false;
   379 		if ( !$this->page_exists )
   381 		if ( !$this->page_exists )
   380 		{
   382 		{
   381 			if ( !$this->create_page() )
   383 			if ( !$this->create_page() )
   382 			{
   384 			{
   383 				return false;
   385 				return false;
   384 			}
   386 			}
       
   387 			// This is just to tell plugins if a page was just created, or is being edited.
       
   388 			$page_just_created = true;
   385 		}
   389 		}
   386 			
   390 			
   387 		//
   391 		//
   388 		// Validation
   392 		// Validation
   389 		//
   393 		//
   455 		$author = $db->escape($session->username);
   459 		$author = $db->escape($session->username);
   456 		$time = time();
   460 		$time = time();
   457 		$edit_summary = ( strval($edit_summary) === $edit_summary ) ? $db->escape($edit_summary) : '';
   461 		$edit_summary = ( strval($edit_summary) === $edit_summary ) ? $db->escape($edit_summary) : '';
   458 		$minor_edit = ( $minor_edit ) ? '1' : '0';
   462 		$minor_edit = ( $minor_edit ) ? '1' : '0';
   459 		$date_string = enano_date(ED_DATE | ED_TIME);
   463 		$date_string = enano_date(ED_DATE | ED_TIME);
       
   464 		
       
   465 		// Allow stuff to be run when the page is saved
       
   466 		$code = $plugins->setHook('update_page');
       
   467 		foreach ( $code as $cmd )
       
   468 		{
       
   469 			eval($cmd);
       
   470 		}
       
   471 		// If a plugin raised an error, honor it.
       
   472 		if ( $this->_errors )
       
   473 		{
       
   474 			return false;
       
   475 		}
   460 		
   476 		
   461 		// Insert log entry
   477 		// Insert log entry
   462 		$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"
   478 		$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"
   463  				. "  VALUES ( $time, '$date_string', 'page', 'edit', '{$this->page_id}', '{$this->namespace}', '$author', $session->user_id, '$text', '$edit_summary', $minor_edit, '$page_format' );";
   479  				. "  VALUES ( $time, '$date_string', 'page', 'edit', '{$this->page_id}', '{$this->namespace}', '$author', $session->user_id, '$text', '$edit_summary', $minor_edit, '$page_format' );";
   464 		if ( !$db->sql_query($sql) )
   480 		if ( !$db->sql_query($sql) )