ajax.php
changeset 1343 2a31905a567d
parent 1340 d1d64b373878
equal deleted inserted replaced
1342:2164d18cb10c 1343:2a31905a567d
    75 				'revid' => $revid,
    75 				'revid' => $revid,
    76 				'have_draft' => false
    76 				'have_draft' => false
    77 			);
    77 			);
    78 		
    78 		
    79 		$return['page_format'] = $page->ns->cdata['page_format'];
    79 		$return['page_format'] = $page->ns->cdata['page_format'];
    80 		if ( $return['page_format'] == 'xhtml' )
    80 		$code = $plugins->setHook('get_page_source');
    81 		{
    81 		foreach ( $code as $cmd )
    82 			// gently process headings to make tinymce format them correctly
    82 		{
    83 			if ( preg_match_all('/^ *?(={1,6}) *(.+?) *\\1 *$/m', $return['src'], $matches) )
    83 			eval($cmd);
    84 			{
       
    85 				foreach ( $matches[0] as $i => $match )
       
    86 				{
       
    87 					$hi = strlen($matches[1][$i]);
       
    88 					$heading = "<h{$hi}>{$matches[2][$i]}</h{$hi}>";
       
    89 					$return['src'] = str_replace_once($match, $heading, $return['src']);
       
    90 				}
       
    91 			}
       
    92 		}
    84 		}
    93 		
    85 		
    94 		if ( $have_draft )
    86 		if ( $have_draft )
    95 		{
    87 		{
    96 			$row =& $draft_row;
    88 			$row =& $draft_row;
   242 					);
   234 					);
   243 				}
   235 				}
   244 				else
   236 				else
   245 				{
   237 				{
   246 					$src = RenderMan::preprocess_text($request['src'], false, false);
   238 					$src = RenderMan::preprocess_text($request['src'], false, false);
   247 					$draft_format = $request['format'];
   239 					$draft_format = $db->escape($request['format']);
   248 					if ( !in_array($draft_format, array('xhtml', 'wikitext')) )
   240 					
       
   241 					// Save the draft
       
   242 					if ( !preg_match('/^[a-z0-9_]+$/', $draft_format) )
   249 					{
   243 					{
   250 						$return = array(
   244 						$return = array(
   251 							'mode' => 'error',
   245 								'mode' => 'error',
   252 							'error' => 'invalid_format'
   246 								'error' => 'Page format must match /^[a-z0-9_]+$/'
   253 						);
   247 							);
   254 					}
   248 					}
   255 					else
   249 					else
   256 					{
   250 					{
   257 						// Save the draft
       
   258 						$q = $db->sql_query('INSERT INTO ' . table_prefix . 'logs ( log_type, action, page_id, namespace, author, author_uid, edit_summary, page_text, is_draft, time_id, page_format )
   251 						$q = $db->sql_query('INSERT INTO ' . table_prefix . 'logs ( log_type, action, page_id, namespace, author, author_uid, edit_summary, page_text, is_draft, time_id, page_format )
   259 												VALUES (
   252 											VALUES (
   260 													\'page\',
   253 												\'page\',
   261 													\'edit\',
   254 												\'edit\',
   262 													\'' . $db->escape($paths->page_id) . '\',
   255 												\'' . $db->escape($paths->page_id) . '\',
   263 													\'' . $db->escape($paths->namespace) . '\',
   256 												\'' . $db->escape($paths->namespace) . '\',
   264 													\'' . $db->escape($session->username) . '\',
   257 												\'' . $db->escape($session->username) . '\',
   265 													' . $session->user_id . ',
   258 												' . $session->user_id . ',
   266 													\'' . $db->escape($request['summary']) . '\',
   259 												\'' . $db->escape($request['summary']) . '\',
   267 													\'' . $db->escape($src) . '\',
   260 												\'' . $db->escape($src) . '\',
   268 													1,
   261 												1,
   269 													' . time() . ',
   262 												' . time() . ',
   270 													\'' . $draft_format . '\'
   263 												\'' . $draft_format . '\'
   271 												);');
   264 											);');
   272 						
       
   273 						// Done!
   265 						// Done!
   274 						$return = array(
   266 						$return = array(
   275 								'mode' => 'success',
   267 								'mode' => 'success',
   276 								'is_draft' => true
   268 								'is_draft' => true
   277 							);
   269 							);
   300 				echo enano_json_encode($return);
   292 				echo enano_json_encode($return);
   301 				break;
   293 				break;
   302 			}
   294 			}
   303 			
   295 			
   304 			// Verify captcha, if needed
   296 			// Verify captcha, if needed
   305 			if ( false && !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' )
   297 			if ( !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' )
   306 			{
   298 			{
   307 				if ( !isset($request['captcha_id']) || !isset($request['captcha_code']) )
   299 				if ( !isset($request['captcha_id']) || !isset($request['captcha_code']) )
   308 				{
   300 				{
   309 					die('Invalid request, need captcha metadata');
   301 					die('Invalid request, need captcha metadata');
   310 				}
   302 				}