335 $message = RenderMan::preprocess_text($message, false, false); |
352 $message = RenderMan::preprocess_text($message, false, false); |
336 |
353 |
337 $msg = $db->escape($message); |
354 $msg = $db->escape($message); |
338 |
355 |
339 $minor = $minor ? 'true' : 'false'; |
356 $minor = $minor ? 'true' : 'false'; |
340 $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$paths->cpage['urlname_nons'].'\', \''.$paths->namespace.'\', \''.$msg.'\', \''.$uid.'\', \''.$session->username.'\', \''.$db->escape(htmlspecialchars($summary)).'\', '.$minor.');'; |
357 $q='INSERT INTO ' . table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \'' . $paths->cpage['urlname_nons'] . '\', \'' . $paths->namespace . '\', \'' . $msg . '\', \'' . $uid . '\', \'' . $session->username . '\', \'' . $db->escape(htmlspecialchars($summary)) . '\', ' . $minor . ');'; |
341 if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.'); |
358 if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.'); |
342 |
359 |
343 $q = 'UPDATE '.table_prefix.'page_text SET page_text=\''.$msg.'\',char_tag=\''.$uid.'\' WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'; |
360 $q = 'UPDATE ' . table_prefix.'page_text SET page_text=\'' . $msg . '\',char_tag=\'' . $uid . '\' WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'; |
344 $e = $db->sql_query($q); |
361 $e = $db->sql_query($q); |
345 if(!$e) $db->_die('Enano was unable to save the page contents. Your changes have been lost <tt>:\'(</tt>.'); |
362 if(!$e) $db->_die('Enano was unable to save the page contents. Your changes have been lost <tt>:\'(</tt>.'); |
346 |
363 |
347 $paths->rebuild_page_index($page_id, $namespace); |
364 $paths->rebuild_page_index($page_id, $namespace); |
348 |
365 |
360 { |
377 { |
361 global $db, $session, $paths, $template, $plugins; // Common objects |
378 global $db, $session, $paths, $template, $plugins; // Common objects |
362 if(in_array($namespace, Array('Special', 'Admin'))) |
379 if(in_array($namespace, Array('Special', 'Admin'))) |
363 { |
380 { |
364 // echo '<b>Notice:</b> PageUtils::createPage: You can\'t create a special page in the database<br />'; |
381 // echo '<b>Notice:</b> PageUtils::createPage: You can\'t create a special page in the database<br />'; |
365 return false; // Can't create a special page |
382 return 'You can\'t create a special page in the database'; |
366 } |
383 } |
367 |
384 |
368 if(!isset($paths->nslist[$namespace])) |
385 if(!isset($paths->nslist[$namespace])) |
369 { |
386 { |
370 // echo '<b>Notice:</b> PageUtils::createPage: Couldn\'t look up the namespace<br />'; |
387 // echo '<b>Notice:</b> PageUtils::createPage: Couldn\'t look up the namespace<br />'; |
371 return false; // Couldn't look up namespace |
388 return 'Couldn\'t look up the namespace'; |
372 } |
389 } |
373 |
390 |
374 $pname = $paths->nslist[$namespace] . $page_id; |
391 $pname = $paths->nslist[$namespace] . $page_id; |
375 if(isset($paths->pages[$pname])) |
392 if(isset($paths->pages[$pname])) |
376 { |
393 { |
377 // echo '<b>Notice:</b> PageUtils::createPage: Page already exists<br />'; |
394 // echo '<b>Notice:</b> PageUtils::createPage: Page already exists<br />'; |
378 return false; // Page already exists |
395 return 'Page already exists'; |
379 } |
396 } |
380 |
397 |
381 if(!$session->get_permissions('create_page')) |
398 if(!$session->get_permissions('create_page')) |
382 { |
399 { |
383 // echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create pages<br />'; |
400 // echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create pages<br />'; |
384 return false; // Access denied |
401 return 'Not authorized to create pages'; |
385 } |
402 } |
386 |
403 |
387 if($session->user_level < USER_LEVEL_ADMIN && $namespace == 'System') |
404 if($session->user_level < USER_LEVEL_ADMIN && $namespace == 'System') |
388 { |
405 { |
389 // echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create system messages<br />'; |
406 // echo '<b>Notice:</b> PageUtils::createPage: Not authorized to create system messages<br />'; |
390 return false; // Not authorized to create system messages |
407 return 'Not authorized to create system messages'; |
|
408 } |
|
409 |
|
410 if ( substr($page_id, 0, 8) == 'Project:' ) |
|
411 { |
|
412 // echo '<b>Notice:</b> PageUtils::createPage: Prefix "Project:" is reserved<br />'; |
|
413 return 'The prefix "Project:" is reserved for a parser shortcut; if a page was created using this prefix, it would not be possible to link to it.'; |
391 } |
414 } |
392 |
415 |
393 $page_id = dirtify_page_id($page_id); |
416 $page_id = dirtify_page_id($page_id); |
394 |
417 |
395 if ( !$name ) |
418 if ( !$name ) |
396 $name = str_replace('_', ' ', $page_id); |
419 $name = str_replace('_', ' ', $page_id); |
397 $regex = '#^([A-z0-9 _\-\.\/\!\@\(\)]*)$#is'; |
420 $regex = '#^([A-z0-9 _\-\.\/\!\@\(\)]*)$#is'; |
398 if(!preg_match($regex, $page)) |
421 if(!preg_match($regex, $page)) |
399 { |
422 { |
400 //echo '<b>Notice:</b> PageUtils::createPage: Name contains invalid characters<br />'; |
423 //echo '<b>Notice:</b> PageUtils::createPage: Name contains invalid characters<br />'; |
401 return false; // Name contains invalid characters |
424 return 'Name contains invalid characters'; |
402 } |
425 } |
403 |
426 |
404 $page_id = sanitize_page_id( $page_id ); |
427 $page_id = sanitize_page_id( $page_id ); |
405 |
428 |
406 $prot = ( $namespace == 'System' ) ? 1 : 0; |
429 $prot = ( $namespace == 'System' ) ? 1 : 0; |
419 |
442 |
420 // die('PageUtils::createpage: Creating page with this data:<pre>' . print_r($page_data, true) . '</pre>'); |
443 // die('PageUtils::createpage: Creating page with this data:<pre>' . print_r($page_data, true) . '</pre>'); |
421 |
444 |
422 $paths->add_page($page_data); |
445 $paths->add_page($page_data); |
423 |
446 |
424 $qa = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace,visible,protected,delvote_ips) VALUES(\''.$db->escape($name).'\', \''.$db->escape($page_id).'\', \''.$namespace.'\', '. ( $visible ? '1' : '0' ) .', '.$prot.', \'' . $db->escape(serialize($ips)) . '\');'); |
447 $qa = $db->sql_query('INSERT INTO ' . table_prefix.'pages(name,urlname,namespace,visible,protected,delvote_ips) VALUES(\'' . $db->escape($name) . '\', \'' . $db->escape($page_id) . '\', \'' . $namespace . '\', '. ( $visible ? '1' : '0' ) .', ' . $prot . ', \'' . $db->escape(serialize($ips)) . '\');'); |
425 $qb = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace) VALUES(\''.$db->escape($page_id).'\', \''.$namespace.'\');'); |
448 $qb = $db->sql_query('INSERT INTO ' . table_prefix.'page_text(page_id,namespace) VALUES(\'' . $db->escape($page_id) . '\', \'' . $namespace . '\');'); |
426 $qc = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$db->escape($page_id).'\', \''.$namespace.'\');'); |
449 $qc = $db->sql_query('INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \'' . $session->username . '\', \'' . $db->escape($page_id) . '\', \'' . $namespace . '\');'); |
427 |
450 |
428 if($qa && $qb && $qc) |
451 if($qa && $qb && $qc) |
429 return true; |
452 return 'good'; |
430 else |
453 else |
431 { |
454 { |
432 echo $db->get_error(); |
455 return $db->get_error(); |
433 return false; |
|
434 } |
456 } |
435 } |
457 } |
436 |
458 |
437 /** |
459 /** |
438 * Sets the protection level on a page. |
460 * Sets the protection level on a page. |
448 |
470 |
449 $pname = $paths->nslist[$namespace] . $page_id; |
471 $pname = $paths->nslist[$namespace] . $page_id; |
450 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
472 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
451 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
473 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
452 |
474 |
453 if(!$session->get_permissions('protect')) return('Insufficient access rights'); |
475 if ( !$session->get_permissions('protect') ) |
454 if(!$wiki) return('Page protection only has an effect when Wiki Mode is enabled.'); |
476 { |
455 if(!preg_match('#^([0-9]+){1}$#', (string)$level)) return('Invalid $level parameter.'); |
477 return('Insufficient access rights'); |
456 |
478 } |
457 if($reason!='NO_REASON') { |
479 if ( !$wiki ) |
458 switch($level) |
480 { |
459 { |
481 return('Page protection only has an effect when Wiki Mode is enabled.'); |
460 case 0: |
482 } |
461 $q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'unprot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');'; |
483 if ( !preg_match('#^([0-9]+){1}$#', (string)$level) ) |
462 break; |
484 { |
463 case 1: |
485 return('Invalid $level parameter.'); |
464 $q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'prot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');'; |
486 } |
465 break; |
487 |
466 case 2: |
488 switch($level) |
467 $q = 'INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'semiprot\', \''.$session->username.'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape(htmlspecialchars($reason)).'\');'; |
489 { |
468 break; |
490 case 0: |
469 default: |
491 $q = 'INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'unprot\', \'' . $session->username . '\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $db->escape(htmlspecialchars($reason)) . '\');'; |
470 return 'PageUtils::protect(): Invalid value for $level'; |
492 break; |
471 break; |
493 case 1: |
472 } |
494 $q = 'INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'prot\', \'' . $session->username . '\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $db->escape(htmlspecialchars($reason)) . '\');'; |
473 if(!$db->sql_query($q)) $db->_die('The log entry for the page protection could not be inserted.'); |
495 break; |
474 } |
496 case 2: |
475 |
497 $q = 'INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'semiprot\', \'' . $session->username . '\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $db->escape(htmlspecialchars($reason)) . '\');'; |
476 $q = $db->sql_query('UPDATE '.table_prefix.'pages SET protected='.$_POST['level'].' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
498 break; |
477 if(!$q) $db->_die('The pages table was not updated.'); |
499 default: |
|
500 return 'PageUtils::protect(): Invalid value for $level'; |
|
501 break; |
|
502 } |
|
503 if(!$db->sql_query($q)) $db->_die('The log entry for the page protection could not be inserted.'); |
|
504 |
|
505 $q = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=' . $level . ' WHERE urlname=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
|
506 if ( !$q ) |
|
507 { |
|
508 $db->_die('The pages table was not updated.'); |
|
509 } |
478 |
510 |
479 return('good'); |
511 return('good'); |
480 } |
512 } |
481 |
513 |
482 /** |
514 /** |
487 */ |
519 */ |
488 |
520 |
489 function histlist($page_id, $namespace) |
521 function histlist($page_id, $namespace) |
490 { |
522 { |
491 global $db, $session, $paths, $template, $plugins; // Common objects |
523 global $db, $session, $paths, $template, $plugins; // Common objects |
|
524 global $lang; |
492 |
525 |
493 if(!$session->get_permissions('history_view')) |
526 if(!$session->get_permissions('history_view')) |
494 return 'Access denied'; |
527 return 'Access denied'; |
495 |
528 |
496 ob_start(); |
529 ob_start(); |
497 |
530 |
498 $pname = $paths->nslist[$namespace] . $page_id; |
531 $pname = $paths->nslist[$namespace] . $page_id; |
499 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
532 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
500 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
533 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
501 |
534 |
502 $q = 'SELECT time_id,date_string,page_id,namespace,author,edit_summary,minor_edit FROM '.table_prefix.'logs WHERE log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' ORDER BY time_id DESC;'; |
535 $q = 'SELECT time_id,date_string,page_id,namespace,author,edit_summary,minor_edit FROM ' . table_prefix.'logs WHERE log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' ORDER BY time_id DESC;'; |
503 if(!$db->sql_query($q)) $db->_die('The history data for the page "'.$paths->cpage['name'].'" could not be selected.'); |
536 if(!$db->sql_query($q)) $db->_die('The history data for the page "' . $paths->cpage['name'] . '" could not be selected.'); |
504 echo 'History of edits and actions<h3>Edits:</h3>'; |
537 echo $lang->get('history_page_subtitle') . ' |
|
538 <h3>' . $lang->get('history_heading_edits') . '</h3>'; |
505 $numrows = $db->numrows(); |
539 $numrows = $db->numrows(); |
506 if($numrows < 1) echo 'No history entries in this category.'; |
540 if ( $numrows < 1 ) |
|
541 { |
|
542 echo $lang->get('history_no_entries'); |
|
543 } |
507 else |
544 else |
508 { |
545 { |
509 |
|
510 echo '<form action="'.makeUrlNS($namespace, $page_id, 'do=diff').'" onsubmit="ajaxHistDiff(); return false;" method="get"> |
546 echo '<form action="'.makeUrlNS($namespace, $page_id, 'do=diff').'" onsubmit="ajaxHistDiff(); return false;" method="get"> |
511 <input type="submit" value="Compare selected revisions" /> |
547 <input type="submit" value="' . $lang->get('history_btn_compare') . '" /> |
512 ' . ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars($paths->nslist[$namespace] . $page_id) . '" />' : '' ) . ' |
548 ' . ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars($paths->nslist[$namespace] . $page_id) . '" />' : '' ) . ' |
513 ' . ( $session->sid_super ? '<input type="hidden" name="auth" value="' . $session->sid_super . '" />' : '') . ' |
549 ' . ( $session->sid_super ? '<input type="hidden" name="auth" value="' . $session->sid_super . '" />' : '') . ' |
514 <input type="hidden" name="do" value="diff" /> |
550 <input type="hidden" name="do" value="diff" /> |
515 <br /><span> </span> |
551 <br /><span> </span> |
516 <div class="tblholder"> |
552 <div class="tblholder"> |
517 <table border="0" width="100%" cellspacing="1" cellpadding="4"> |
553 <table border="0" width="100%" cellspacing="1" cellpadding="4"> |
518 <tr> |
554 <tr> |
519 <th colspan="2">Diff</th> |
555 <th colspan="2">' . $lang->get('history_col_diff') . '</th> |
520 <th>Date/time</th> |
556 <th>' . $lang->get('history_col_datetime') . '</th> |
521 <th>User</th> |
557 <th>' . $lang->get('history_col_user') . '</th> |
522 <th>Edit summary</th> |
558 <th>' . $lang->get('history_col_summary') . '</th> |
523 <th>Minor</th> |
559 <th>' . $lang->get('history_col_minor') . '</th> |
524 <th colspan="3">Actions</th> |
560 <th colspan="3">' . $lang->get('history_col_actions') . '</th> |
525 </tr>'."\n"."\n"; |
561 </tr>'."\n"."\n"; |
526 $cls = 'row2'; |
562 $cls = 'row2'; |
527 $ticker = 0; |
563 $ticker = 0; |
528 |
564 |
529 while($r = $db->fetchrow()) { |
565 while ( $r = $db->fetchrow() ) |
|
566 { |
530 |
567 |
531 $ticker++; |
568 $ticker++; |
532 |
569 |
533 if($cls == 'row2') $cls = 'row1'; |
570 if($cls == 'row2') $cls = 'row1'; |
534 else $cls = 'row2'; |
571 else $cls = 'row2'; |
549 else |
586 else |
550 { |
587 { |
551 $s1 = ''; |
588 $s1 = ''; |
552 $s2 = ''; |
589 $s2 = ''; |
553 } |
590 } |
554 if($ticker > 1) echo '<td class="'.$cls.'" style="padding: 0;"><input '.$s1.'name="diff1" type="radio" value="'.$r['time_id'].'" id="diff1_'.$r['time_id'].'" class="clsDiff1Radio" onclick="selectDiff1Button(this);" /></td>'."\n"; else echo '<td class="'.$cls.'"></td>'; |
591 if($ticker > 1) echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s1 . 'name="diff1" type="radio" value="' . $r['time_id'] . '" id="diff1_' . $r['time_id'] . '" class="clsDiff1Radio" onclick="selectDiff1Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>'; |
555 if($ticker < $numrows) echo '<td class="'.$cls.'" style="padding: 0;"><input '.$s2.'name="diff2" type="radio" value="'.$r['time_id'].'" id="diff2_'.$r['time_id'].'" class="clsDiff2Radio" onclick="selectDiff2Button(this);" /></td>'."\n"; else echo '<td class="'.$cls.'"></td>'; |
592 if($ticker < $numrows) echo '<td class="' . $cls . '" style="padding: 0;"><input ' . $s2 . 'name="diff2" type="radio" value="' . $r['time_id'] . '" id="diff2_' . $r['time_id'] . '" class="clsDiff2Radio" onclick="selectDiff2Button(this);" /></td>'."\n"; else echo '<td class="' . $cls . '"></td>'; |
556 |
593 |
557 // Date and time |
594 // Date and time |
558 echo '<td class="'.$cls.'">'.$r['date_string'].'</td class="'.$cls.'">'."\n"; |
595 echo '<td class="' . $cls . '">' . $r['date_string'] . '</td class="' . $cls . '">'."\n"; |
559 |
596 |
560 // User |
597 // User |
561 if($session->get_permissions('mod_misc') && preg_match('#^([0-9]*){1,3}\.([0-9]*){1,3}\.([0-9]*){1,3}\.([0-9]*){1,3}$#', $r['author'])) $rc = ' style="cursor: pointer;" title="Click cell background for reverse DNS info" onclick="ajaxReverseDNS(this, \''.$r['author'].'\');"'; |
598 if ( $session->get_permissions('mod_misc') && is_valid_ip($r['author']) ) |
562 else $rc = ''; |
599 { |
563 echo '<td class="'.$cls.'"'.$rc.'><a href="'.makeUrlNS('User', $r['author']).'" '; |
600 $rc = ' style="cursor: pointer;" title="' . $lang->get('history_tip_rdns') . '" onclick="ajaxReverseDNS(this, \'' . $r['author'] . '\');"'; |
564 if(!isPage($paths->nslist['User'] . $r['author'])) echo 'class="wikilink-nonexistent"'; |
601 } |
565 echo '>'.$r['author'].'</a></td class="'.$cls.'">'."\n"; |
602 else |
|
603 { |
|
604 $rc = ''; |
|
605 } |
|
606 echo '<td class="' . $cls . '"' . $rc . '><a href="'.makeUrlNS('User', $r['author']).'" '; |
|
607 if ( !isPage($paths->nslist['User'] . $r['author']) ) |
|
608 { |
|
609 echo 'class="wikilink-nonexistent"'; |
|
610 } |
|
611 echo '>' . $r['author'] . '</a></td class="' . $cls . '">'."\n"; |
566 |
612 |
567 // Edit summary |
613 // Edit summary |
568 echo '<td class="'.$cls.'">'.$r['edit_summary'].'</td>'."\n"; |
614 if ( $r['edit_summary'] == 'Automatic backup created when logs were purged' ) |
|
615 { |
|
616 $r['edit_summary'] = $lang->get('history_summary_clearlogs'); |
|
617 } |
|
618 echo '<td class="' . $cls . '">' . $r['edit_summary'] . '</td>'."\n"; |
569 |
619 |
570 // Minor edit |
620 // Minor edit |
571 echo '<td class="'.$cls.'" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'."\n"; |
621 echo '<td class="' . $cls . '" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'."\n"; |
572 |
622 |
573 // Actions! |
623 // Actions! |
574 echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'oldid='.$r['time_id']).'" onclick="ajaxHistView(\''.$r['time_id'].'\'); return false;">View revision</a></td>'."\n"; |
624 echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'oldid=' . $r['time_id']) . '" onclick="ajaxHistView(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_view') . '</a></td>'."\n"; |
575 echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">View user contribs</a></td>'."\n"; |
625 echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'."\n"; |
576 echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">Revert to this revision</a></td>'."\n"; |
626 echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id=' . $r['time_id']) . '" onclick="ajaxRollback(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_restore') . '</a></td>'."\n"; |
577 |
627 |
578 echo '</tr>'."\n"."\n"; |
628 echo '</tr>'."\n"."\n"; |
579 |
629 |
580 } |
630 } |
581 echo '</table> |
631 echo '</table> |
582 </div> |
632 </div> |
583 <br /> |
633 <br /> |
584 <input type="hidden" name="do" value="diff" /> |
634 <input type="hidden" name="do" value="diff" /> |
585 <input type="submit" value="Compare selected revisions" /> |
635 <input type="submit" value="' . $lang->get('history_btn_compare') . '" /> |
586 </form> |
636 </form> |
587 <script type="text/javascript">if ( !KILL_SWITCH ) { buildDiffList(); }</script>'; |
637 <script type="text/javascript">if ( !KILL_SWITCH ) { buildDiffList(); }</script>'; |
588 } |
638 } |
589 $db->free_result(); |
639 $db->free_result(); |
590 echo '<h3>Other changes:</h3>'; |
640 echo '<h3>' . $lang->get('history_heading_other') . '</h3>'; |
591 $q = 'SELECT time_id,action,date_string,page_id,namespace,author,edit_summary,minor_edit FROM '.table_prefix.'logs WHERE log_type=\'page\' AND action!=\'edit\' AND page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$paths->namespace.'\' ORDER BY time_id DESC;'; |
641 $q = 'SELECT time_id,action,date_string,page_id,namespace,author,edit_summary,minor_edit FROM ' . table_prefix.'logs WHERE log_type=\'page\' AND action!=\'edit\' AND page_id=\'' . $paths->cpage['urlname_nons'] . '\' AND namespace=\'' . $paths->namespace . '\' ORDER BY time_id DESC;'; |
592 if(!$db->sql_query($q)) $db->_die('The history data for the page "'.$paths->cpage['name'].'" could not be selected.'); |
642 if ( !$db->sql_query($q) ) |
593 if($db->numrows() < 1) echo 'No history entries in this category.'; |
643 { |
594 else { |
644 $db->_die('The history data for the page "' . htmlspecialchars($paths->cpage['name']) . '" could not be selected.'); |
|
645 } |
|
646 if ( $db->numrows() < 1 ) |
|
647 { |
|
648 echo $lang->get('history_no_entries'); |
|
649 } |
|
650 else |
|
651 { |
595 |
652 |
596 echo '<div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4"><tr><th>Date/time</th><th>User</th><th>Minor</th><th>Action taken</th><th>Extra info</th><th colspan="2"></th></tr>'; |
653 echo '<div class="tblholder"> |
|
654 <table border="0" width="100%" cellspacing="1" cellpadding="4"><tr> |
|
655 <th>' . $lang->get('history_col_datetime') . '</th> |
|
656 <th>' . $lang->get('history_col_user') . '</th> |
|
657 <th>' . $lang->get('history_col_minor') . '</th> |
|
658 <th>' . $lang->get('history_col_action_taken') . '</th> |
|
659 <th>' . $lang->get('history_col_extra') . '</th> |
|
660 <th colspan="2"></th> |
|
661 </tr>'; |
597 $cls = 'row2'; |
662 $cls = 'row2'; |
598 while($r = $db->fetchrow()) { |
663 while($r = $db->fetchrow()) { |
599 |
664 |
600 if($cls == 'row2') $cls = 'row1'; |
665 if($cls == 'row2') $cls = 'row1'; |
601 else $cls = 'row2'; |
666 else $cls = 'row2'; |
602 |
667 |
603 echo '<tr>'; |
668 echo '<tr>'; |
604 |
669 |
605 // Date and time |
670 // Date and time |
606 echo '<td class="'.$cls.'">'.$r['date_string'].'</td class="'.$cls.'">'; |
671 echo '<td class="' . $cls . '">' . $r['date_string'] . '</td class="' . $cls . '">'; |
607 |
672 |
608 // User |
673 // User |
609 echo '<td class="'.$cls.'"><a href="'.makeUrlNS('User', $r['author']).'" '; |
674 echo '<td class="' . $cls . '"><a href="'.makeUrlNS('User', $r['author']).'" '; |
610 if(!isPage($paths->nslist['User'] . $r['author'])) echo 'class="wikilink-nonexistent"'; |
675 if(!isPage($paths->nslist['User'] . $r['author'])) echo 'class="wikilink-nonexistent"'; |
611 echo '>'.$r['author'].'</a></td class="'.$cls.'">'; |
676 echo '>' . $r['author'] . '</a></td class="' . $cls . '">'; |
612 |
677 |
613 |
678 |
614 // Minor edit |
679 // Minor edit |
615 echo '<td class="'.$cls.'" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'; |
680 echo '<td class="' . $cls . '" style="text-align: center;">'. (( $r['minor_edit'] ) ? 'M' : '' ) .'</td>'; |
616 |
681 |
617 // Action taken |
682 // Action taken |
618 echo '<td class="'.$cls.'">'; |
683 echo '<td class="' . $cls . '">'; |
619 // Some of these are sanitized at insert-time. Others follow the newer Enano policy of stripping HTML at runtime. |
684 // Some of these are sanitized at insert-time. Others follow the newer Enano policy of stripping HTML at runtime. |
620 if ($r['action']=='prot') echo 'Protected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary']; |
685 if ($r['action']=='prot') echo $lang->get('history_log_protect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
621 elseif($r['action']=='unprot') echo 'Unprotected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary']; |
686 elseif($r['action']=='unprot') echo $lang->get('history_log_unprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
622 elseif($r['action']=='semiprot') echo 'Semi-protected page</td><td class="'.$cls.'">Reason: '.$r['edit_summary']; |
687 elseif($r['action']=='semiprot') echo $lang->get('history_log_semiprotect') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
623 elseif($r['action']=='rename') echo 'Renamed page</td><td class="'.$cls.'">Old title: '.htmlspecialchars($r['edit_summary']); |
688 elseif($r['action']=='rename') echo $lang->get('history_log_rename') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_oldtitle') . ' '.htmlspecialchars($r['edit_summary']); |
624 elseif($r['action']=='create') echo 'Created page</td><td class="'.$cls.'">'; |
689 elseif($r['action']=='create') echo $lang->get('history_log_create') . '</td><td class="' . $cls . '">'; |
625 elseif($r['action']=='delete') echo 'Deleted page</td><td class="'.$cls.'">Reason: '.$r['edit_summary']; |
690 elseif($r['action']=='delete') echo $lang->get('history_log_delete') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' ' . $r['edit_summary']; |
626 elseif($r['action']=='reupload') echo 'Uploaded new file version</td><td class="'.$cls.'">Reason: '.htmlspecialchars($r['edit_summary']); |
691 elseif($r['action']=='reupload') echo $lang->get('history_log_uploadnew') . '</td><td class="' . $cls . '">' . $lang->get('history_extra_reason') . ' '.htmlspecialchars($r['edit_summary']); |
627 echo '</td>'; |
692 echo '</td>'; |
628 |
693 |
629 // Actions! |
694 // Actions! |
630 echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">View user contribs</a></td>'; |
695 echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrl($paths->nslist['Special'].'Contributions/' . $r['author']) . '">' . $lang->get('history_action_contrib') . '</a></td>'; |
631 echo '<td class="'.$cls.'" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">Revert action</a></td>'; |
696 echo '<td class="' . $cls . '" style="text-align: center;"><a href="'.makeUrlNS($namespace, $page_id, 'do=rollback&id=' . $r['time_id']) . '" onclick="ajaxRollback(\'' . $r['time_id'] . '\'); return false;">' . $lang->get('history_action_revert') . '</a></td>'; |
632 |
|
633 //echo '(<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">rollback</a>) <i>'.$r['date_string'].'</i> '.$r['author'].' (<a href="'.makeUrl($paths->nslist['User'].$r['author']).'">Userpage</a>, <a href="'.makeUrl($paths->nslist['Special'].'Contributions/'.$r['author']).'">Contrib</a>): '; |
|
634 |
|
635 if($r['minor_edit']) echo '<b> - minor edit</b>'; |
|
636 echo '<br />'; |
|
637 |
697 |
638 echo '</tr>'; |
698 echo '</tr>'; |
639 } |
699 } |
640 echo '</table></div>'; |
700 echo '</table></div>'; |
641 } |
701 } |
652 */ |
712 */ |
653 |
713 |
654 function rollback($id) |
714 function rollback($id) |
655 { |
715 { |
656 global $db, $session, $paths, $template, $plugins; // Common objects |
716 global $db, $session, $paths, $template, $plugins; // Common objects |
657 if(!$session->get_permissions('history_rollback')) return('You are not authorized to perform rollbacks.'); |
717 if ( !$session->get_permissions('history_rollback') ) |
658 if(!preg_match('#^([0-9]+)$#', (string)$id)) return('The value "id" on the query string must be an integer.'); |
718 { |
659 $e = $db->sql_query('SELECT log_type,action,date_string,page_id,namespace,page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id.';'); |
719 return('You are not authorized to perform rollbacks.'); |
660 if(!$e) $db->_die('The rollback data could not be selected.'); |
720 } |
|
721 if ( !preg_match('#^([0-9]+)$#', (string)$id) ) |
|
722 { |
|
723 return('The value "id" on the query string must be an integer.'); |
|
724 } |
|
725 $e = $db->sql_query('SELECT log_type,action,date_string,page_id,namespace,page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE time_id=' . $id . ';'); |
|
726 if ( !$e ) |
|
727 { |
|
728 $db->_die('The rollback data could not be selected.'); |
|
729 } |
661 $rb = $db->fetchrow(); |
730 $rb = $db->fetchrow(); |
662 $db->free_result(); |
731 $db->free_result(); |
663 switch($rb['log_type']) { |
732 |
|
733 if ( $rb['log_type'] == 'page' && $rb['action'] != 'delete' ) |
|
734 { |
|
735 $pagekey = $paths->nslist[$rb['namespace']] . $rb['page_id']; |
|
736 if ( !isset($paths->pages[$pagekey]) ) |
|
737 { |
|
738 return "Page doesn't exist"; |
|
739 } |
|
740 $pagedata =& $paths->pages[$pagekey]; |
|
741 $protected = false; |
|
742 // Special case: is the page protected? if so, check for even_when_protected permissions |
|
743 if($pagedata['protected'] == 2) |
|
744 { |
|
745 // The page is semi-protected, determine permissions |
|
746 if($session->user_logged_in && $session->reg_time + 60*60*24*4 < time()) |
|
747 { |
|
748 $protected = false; |
|
749 } |
|
750 else |
|
751 { |
|
752 $protected = true; |
|
753 } |
|
754 } |
|
755 else |
|
756 { |
|
757 $protected = ( $pagedata['protected'] == 1 ); |
|
758 } |
|
759 |
|
760 $perms = $session->fetch_page_acl($rb['page_id'], $rb['namespace']); |
|
761 |
|
762 if ( $protected && !$perms->get_permissions('even_when_protected') ) |
|
763 { |
|
764 return "Because this page is protected, you need moderator rights to roll back changes."; |
|
765 } |
|
766 } |
|
767 else |
|
768 { |
|
769 $perms =& $session; |
|
770 } |
|
771 |
|
772 switch($rb['log_type']) |
|
773 { |
664 case "page": |
774 case "page": |
665 switch($rb['action']) { |
775 switch($rb['action']) |
|
776 { |
666 case "edit": |
777 case "edit": |
|
778 if ( !$perms->get_permissions('edit_page') ) |
|
779 return "You don't have permission to edit pages, so rolling back edits can't be allowed either."; |
667 $t = $db->escape($rb['page_text']); |
780 $t = $db->escape($rb['page_text']); |
668 $e = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\''.$t.'\',char_tag=\''.$rb['char_tag'].'\' WHERE page_id=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\''); |
781 $e = $db->sql_query('UPDATE ' . table_prefix.'page_text SET page_text=\'' . $t . '\',char_tag=\'' . $rb['char_tag'] . '\' WHERE page_id=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
669 if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
782 if ( !$e ) |
670 else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the state it was in on '.$rb['date_string'].'.'); |
783 { |
|
784 return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
|
785 } |
|
786 else |
|
787 { |
|
788 return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the state it was in on ' . $rb['date_string'] . '.'; |
|
789 } |
671 break; |
790 break; |
672 case "rename": |
791 case "rename": |
|
792 if ( !$perms->get_permissions('rename') ) |
|
793 return "You don't have permission to rename pages, so rolling back renames can't be allowed either."; |
673 $t = $db->escape($rb['edit_summary']); |
794 $t = $db->escape($rb['edit_summary']); |
674 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET name=\''.$t.'\' WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\''); |
795 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET name=\'' . $t . '\' WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
675 if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
796 if ( !$e ) |
676 else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the name it had ("'.$rb['edit_summary'].'") before '.$rb['date_string'].'.'); |
797 { |
|
798 return "An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
799 } |
|
800 else |
|
801 { |
|
802 return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been rolled back to the name it had ("' . $rb['edit_summary'] . '") before ' . $rb['date_string'] . '.'; |
|
803 } |
677 break; |
804 break; |
678 case "prot": |
805 case "prot": |
679 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=0 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\''); |
806 if ( !$perms->get_permissions('protect') ) |
680 if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
807 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
681 else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at '.$rb['date_string'].'.'); |
808 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
809 if ( !$e ) |
|
810 return "An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
811 else |
|
812 return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . $rb['date_string'] . '.'; |
682 break; |
813 break; |
683 case "semiprot": |
814 case "semiprot": |
684 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=0 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\''); |
815 if ( !$perms->get_permissions('protect') ) |
685 if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
816 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
686 else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at '.$rb['date_string'].'.'); |
817 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=0 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
818 if ( !$e ) |
|
819 return "An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
820 else |
|
821 return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been unprotected according to the log created at ' . $rb['date_string'] . '.'; |
687 break; |
822 break; |
688 case "unprot": |
823 case "unprot": |
689 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET protected=1 WHERE urlname=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\''); |
824 if ( !$perms->get_permissions('protect') ) |
690 if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
825 return "You don't have permission to protect pages, so rolling back protection can't be allowed either."; |
691 else return('The page "'.$paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been protected according to the log created at '.$rb['date_string'].'.'); |
826 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET protected=1 WHERE urlname=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\''); |
|
827 if ( !$e ) |
|
828 return "An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace(); |
|
829 else |
|
830 return 'The page "' . $paths->pages[$paths->nslist[$rb['namespace']].$rb['page_id']]['name'].'" has been protected according to the log created at ' . $rb['date_string'] . '.'; |
692 break; |
831 break; |
693 case "delete": |
832 case "delete": |
694 if(!$session->get_permissions('history_rollback_extra')) return('Administrative privileges are required for page undeletion.'); |
833 if ( !$perms->get_permissions('history_rollback_extra') ) |
695 if(isset($paths->pages[$paths->cpage['urlname']])) return('You cannot raise a dead page that is alive.'); |
834 return 'Administrative privileges are required for page undeletion.'; |
|
835 if ( isset($paths->pages[$paths->cpage['urlname']]) ) |
|
836 return 'You cannot raise a dead page that is alive.'; |
696 $name = str_replace('_', ' ', $rb['page_id']); |
837 $name = str_replace('_', ' ', $rb['page_id']); |
697 $e = $db->sql_query('INSERT INTO '.table_prefix.'pages(name,urlname,namespace) VALUES( \''.$name.'\', \''.$rb['page_id'].'\',\''.$rb['namespace'].'\' )');if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
838 $e = $db->sql_query('INSERT INTO ' . table_prefix.'pages(name,urlname,namespace) VALUES( \'' . $name . '\', \'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\' )');if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
698 $e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'logs WHERE page_id=\''.$rb['page_id'].'\' AND namespace=\''.$rb['namespace'].'\' AND log_type=\'page\' AND action=\'edit\' ORDER BY time_id DESC;'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
839 $e = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix.'logs WHERE page_id=\'' . $rb['page_id'] . '\' AND namespace=\'' . $rb['namespace'] . '\' AND log_type=\'page\' AND action=\'edit\' ORDER BY time_id DESC;'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
699 $r = $db->fetchrow(); |
840 $r = $db->fetchrow(); |
700 $e = $db->sql_query('INSERT INTO '.table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\''.$rb['page_id'].'\',\''.$rb['namespace'].'\',\''.$db->escape($r['page_text']).'\',\''.$r['char_tag'].'\')'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
841 $e = $db->sql_query('INSERT INTO ' . table_prefix.'page_text(page_id,namespace,page_text,char_tag) VALUES(\'' . $rb['page_id'] . '\',\'' . $rb['namespace'] . '\',\'' . $db->escape($r['page_text']) . '\',\'' . $r['char_tag'] . '\')'); if(!$e) return("An error occurred during the rollback operation.\nMySQL said: ".mysql_error()."\n\nSQL backtrace:\n".$db->sql_backtrace()); |
701 return('The page "'.$name.'" has been undeleted according to the log created at '.$rb['date_string'].'.'); |
842 return 'The page "' . $name . '" has been undeleted according to the log created at ' . $rb['date_string'] . '.'; |
702 break; |
843 break; |
703 case "reupload": |
844 case "reupload": |
704 if(!$session->get_permissions('history_rollbacks_extra')) return('Administrative privileges are required for file rollbacks.'); |
845 if ( !$session->get_permissions('history_rollbacks_extra') ) |
|
846 { |
|
847 return 'Administrative privileges are required for file rollbacks.'; |
|
848 } |
705 $newtime = time(); |
849 $newtime = time(); |
706 $newdate = date('d M Y h:i a'); |
850 $newdate = date('d M Y h:i a'); |
707 if(!$db->sql_query('UPDATE '.table_prefix.'logs SET time_id='.$newtime.',date_string=\''.$newdate.'\' WHERE time_id='.$id)) return('Error during query: '.mysql_error()); |
851 if(!$db->sql_query('UPDATE ' . table_prefix.'logs SET time_id=' . $newtime . ',date_string=\'' . $newdate . '\' WHERE time_id=' . $id)) |
708 if(!$db->sql_query('UPDATE '.table_prefix.'files SET time_id='.$newtime.' WHERE time_id='.$id)) return('Error during query: '.mysql_error()); |
852 return 'Error during query: '.mysql_error(); |
709 return('The file has been rolled back to the version uploaded on '.date('d M Y h:i a', (int)$id).'.'); |
853 if(!$db->sql_query('UPDATE ' . table_prefix.'files SET time_id=' . $newtime . ' WHERE time_id=' . $id)) |
|
854 return 'Error during query: '.mysql_error(); |
|
855 return 'The file has been rolled back to the version uploaded on '.date('d M Y h:i a', (int)$id).'.'; |
710 break; |
856 break; |
711 default: |
857 default: |
712 return('Rollback of the action "'.$rb['action'].'" is not yet supported.'); |
858 return('Rollback of the action "' . $rb['action'] . '" is not yet supported.'); |
713 break; |
859 break; |
714 } |
860 } |
715 break; |
861 break; |
716 case "security": |
862 case "security": |
717 case "login": |
863 case "login": |
718 return('A '.$rb['log_type'].'-related log entry cannot be rolled back.'); |
864 return('A ' . $rb['log_type'] . '-related log entry cannot be rolled back.'); |
719 break; |
865 break; |
720 default: |
866 default: |
721 return('Unknown log entry type: "'.$rb['log_type'].'"'); |
867 return('Unknown log entry type: "' . $rb['log_type'] . '"'); |
722 } |
868 } |
723 } |
869 } |
724 |
870 |
725 /** |
871 /** |
726 * Posts a comment. |
872 * Posts a comment. |
747 } |
893 } |
748 $text = RenderMan::preprocess_text($text); |
894 $text = RenderMan::preprocess_text($text); |
749 $name = $session->user_logged_in ? RenderMan::preprocess_text($session->username) : RenderMan::preprocess_text($name); |
895 $name = $session->user_logged_in ? RenderMan::preprocess_text($session->username) : RenderMan::preprocess_text($name); |
750 $subj = RenderMan::preprocess_text($subject); |
896 $subj = RenderMan::preprocess_text($subject); |
751 if(getConfig('approve_comments')=='1') $appr = '0'; else $appr = '1'; |
897 if(getConfig('approve_comments')=='1') $appr = '0'; else $appr = '1'; |
752 $q = 'INSERT INTO '.table_prefix.'comments(page_id,namespace,subject,comment_data,name,user_id,approved,time) VALUES(\''.$page_id.'\',\''.$namespace.'\',\''.$subj.'\',\''.$text.'\',\''.$name.'\','.$session->user_id.','.$appr.','.time().')'; |
898 $q = 'INSERT INTO ' . table_prefix.'comments(page_id,namespace,subject,comment_data,name,user_id,approved,time) VALUES(\'' . $page_id . '\',\'' . $namespace . '\',\'' . $subj . '\',\'' . $text . '\',\'' . $name . '\',' . $session->user_id . ',' . $appr . ','.time().')'; |
753 $e = $db->sql_query($q); |
899 $e = $db->sql_query($q); |
754 if(!$e) die('alert(unescape(\''.rawurlencode('Error inserting comment data: '.mysql_error().'\n\nQuery:\n'.$q).'\'))'); |
900 if(!$e) die('alert(unescape(\''.rawurlencode('Error inserting comment data: '.mysql_error().'\n\nQuery:\n' . $q) . '\'))'); |
755 else $_ob .= '<div class="info-box">Your comment has been posted.</div>'; |
901 else $_ob .= '<div class="info-box">Your comment has been posted.</div>'; |
756 return PageUtils::comments($page_id, $namespace, false, Array(), $_ob); |
902 return PageUtils::comments($page_id, $namespace, false, Array(), $_ob); |
757 } |
903 } |
758 |
904 |
759 /** |
905 /** |
779 { |
926 { |
780 switch($action) { |
927 switch($action) { |
781 case "delete": |
928 case "delete": |
782 if(isset($flags['id'])) |
929 if(isset($flags['id'])) |
783 { |
930 { |
784 $q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND comment_id='.intval($flags['id']).' LIMIT 1;'; |
931 $q = 'DELETE FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND comment_id='.intval($flags['id']).' LIMIT 1;'; |
785 } else { |
932 } else { |
786 $n = $db->escape($flags['name']); |
933 $n = $db->escape($flags['name']); |
787 $s = $db->escape($flags['subj']); |
934 $s = $db->escape($flags['subj']); |
788 $t = $db->escape($flags['text']); |
935 $t = $db->escape($flags['text']); |
789 $q = 'DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND name=\''.$n.'\' AND subject=\''.$s.'\' AND comment_data=\''.$t.'\' LIMIT 1;'; |
936 $q = 'DELETE FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND name=\'' . $n . '\' AND subject=\'' . $s . '\' AND comment_data=\'' . $t . '\' LIMIT 1;'; |
790 } |
937 } |
791 $e=$db->sql_query($q); |
938 $e=$db->sql_query($q); |
792 if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));'); |
939 if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n' . $q) . '\'));'); |
793 break; |
940 break; |
794 case "approve": |
941 case "approve": |
795 if(isset($flags['id'])) |
942 if(isset($flags['id'])) |
796 { |
943 { |
797 $where = 'comment_id='.intval($flags['id']); |
944 $where = 'comment_id='.intval($flags['id']); |
798 } else { |
945 } else { |
799 $n = $db->escape($flags['name']); |
946 $n = $db->escape($flags['name']); |
800 $s = $db->escape($flags['subj']); |
947 $s = $db->escape($flags['subj']); |
801 $t = $db->escape($flags['text']); |
948 $t = $db->escape($flags['text']); |
802 $where = 'name=\''.$n.'\' AND subject=\''.$s.'\' AND comment_data=\''.$t.'\''; |
949 $where = 'name=\'' . $n . '\' AND subject=\'' . $s . '\' AND comment_data=\'' . $t . '\''; |
803 } |
950 } |
804 $q = 'SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND '.$where.' LIMIT 1;'; |
951 $q = 'SELECT approved FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND ' . $where . ' LIMIT 1;'; |
805 $e = $db->sql_query($q); |
952 $e = $db->sql_query($q); |
806 if(!$e) die('alert(unesape(\''.rawurlencode('Error selecting approval status: '.mysql_error().'\n\nQuery:\n'.$q).'\'));'); |
953 if(!$e) die('alert(unesape(\''.rawurlencode('Error selecting approval status: '.mysql_error().'\n\nQuery:\n' . $q) . '\'));'); |
807 $r = $db->fetchrow(); |
954 $r = $db->fetchrow(); |
808 $db->free_result(); |
955 $db->free_result(); |
809 $a = ( $r['approved'] ) ? '0' : '1'; |
956 $a = ( $r['approved'] ) ? '0' : '1'; |
810 $q = 'UPDATE '.table_prefix.'comments SET approved='.$a.' WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND '.$where.';'; |
957 $q = 'UPDATE ' . table_prefix.'comments SET approved=' . $a . ' WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND ' . $where . ';'; |
811 $e=$db->sql_query($q); |
958 $e=$db->sql_query($q); |
812 if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n'.$q).'\'));'); |
959 if(!$e) die('alert(unesape(\''.rawurlencode('Error during query: '.mysql_error().'\n\nQuery:\n' . $q) . '\'));'); |
813 if($a=='1') $v = 'Unapprove'; |
960 if($a=='1') $v = $lang->get('comment_btn_mod_unapprove'); |
814 else $v = 'Approve'; |
961 else $v = $lang->get('comment_btn_mod_approve'); |
815 echo 'document.getElementById("mdgApproveLink'.$_GET['id'].'").innerHTML="'.$v.'";'; |
962 echo 'document.getElementById("mdgApproveLink'.intval($_GET['id']).'").innerHTML="' . $v . '";'; |
816 break; |
963 break; |
817 } |
964 } |
818 } |
965 } |
819 |
966 |
820 if(!defined('ENANO_TEMPLATE_LOADED')) |
967 if(!defined('ENANO_TEMPLATE_LOADED')) |
822 $template->load_theme($session->theme, $session->style); |
969 $template->load_theme($session->theme, $session->style); |
823 } |
970 } |
824 |
971 |
825 $tpl = $template->makeParser('comment.tpl'); |
972 $tpl = $template->makeParser('comment.tpl'); |
826 |
973 |
827 $e = $db->sql_query('SELECT * FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND approved=0;'); |
974 $e = $db->sql_query('SELECT * FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND approved=0;'); |
828 if(!$e) $db->_die('The comment text data could not be selected.'); |
975 if(!$e) $db->_die('The comment text data could not be selected.'); |
829 $num_unapp = $db->numrows(); |
976 $num_unapp = $db->numrows(); |
830 $db->free_result(); |
977 $db->free_result(); |
831 $e = $db->sql_query('SELECT * FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND approved=1;'); |
978 $e = $db->sql_query('SELECT * FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND approved=1;'); |
832 if(!$e) $db->_die('The comment text data could not be selected.'); |
979 if(!$e) $db->_die('The comment text data could not be selected.'); |
833 $num_app = $db->numrows(); |
980 $num_app = $db->numrows(); |
834 $db->free_result(); |
981 $db->free_result(); |
835 $lq = $db->sql_query('SELECT c.comment_id,c.subject,c.name,c.comment_data,c.approved,c.time,c.user_id,u.user_level,u.signature |
982 $lq = $db->sql_query('SELECT c.comment_id,c.subject,c.name,c.comment_data,c.approved,c.time,c.user_id,u.user_level,u.signature |
836 FROM '.table_prefix.'comments AS c |
983 FROM ' . table_prefix.'comments AS c |
837 LEFT JOIN '.table_prefix.'users AS u |
984 LEFT JOIN ' . table_prefix.'users AS u |
838 ON c.user_id=u.user_id |
985 ON c.user_id=u.user_id |
839 WHERE page_id=\''.$page_id.'\' |
986 WHERE page_id=\'' . $page_id . '\' |
840 AND namespace=\''.$namespace.'\' ORDER BY c.time ASC;'); |
987 AND namespace=\'' . $namespace . '\' ORDER BY c.time ASC;'); |
841 if(!$lq) _die('The comment text data could not be selected. '.mysql_error()); |
988 if(!$lq) _die('The comment text data could not be selected. '.mysql_error()); |
842 $_ob .= '<h3>Article Comments</h3>'; |
989 $_ob .= '<h3>' . $lang->get('comment_heading') . '</h3>'; |
|
990 |
843 $n = ( $session->get_permissions('mod_comments')) ? $db->numrows() : $num_app; |
991 $n = ( $session->get_permissions('mod_comments')) ? $db->numrows() : $num_app; |
844 if($n==1) $s = 'is '.$n.' comment'; else $s = 'are '.$n.' comments'; |
992 |
845 if($n < 1) |
993 $subst = array( |
846 { |
994 'num_comments' => $n, |
847 $_ob .= '<p>There are currently no comments on this '.strtolower($namespace).''; |
995 'page_type' => $template->namespace_string |
848 if($namespace != 'Article') $_ob .= ' page'; |
996 ); |
849 $_ob .= '.</p>'; |
997 |
850 } else $_ob .= '<p>There '.$s.' on this article.'; |
998 $_ob .= '<p>'; |
851 if($session->get_permissions('mod_comments') && $num_unapp > 0) $_ob .= ' <span style="color: #D84308">'.$num_unapp.' of those are unapproved.</span>'; |
999 $_ob .= ( $n == 0 ) ? $lang->get('comment_msg_count_zero', $subst) : ( $n == 1 ? $lang->get('comment_msg_count_one', $subst) : $lang->get('comment_msg_count_plural', $subst) ); |
852 elseif(!$session->get_permissions('mod_comments') && $num_unapp > 0) { $u = ($num_unapp == 1) ? "is $num_unapp comment" : "are $num_unapp comments"; $_ob .= ' However, there ' . $u . ' awating approval.'; } |
1000 |
|
1001 if ( $session->get_permissions('mod_comments') && $num_unapp > 0 ) |
|
1002 { |
|
1003 $_ob .= ' <span style="color: #D84308">' . $lang->get('comment_msg_count_unapp_mod', array( 'num_unapp' => $num_unapp )) . '</span>'; |
|
1004 } |
|
1005 else if ( !$session->get_permissions('mod_comments') && $num_unapp > 0 ) |
|
1006 { |
|
1007 $ls = ( $num_unapp == 1 ) ? 'comment_msg_count_unapp_one' : 'comment_msg_count_unapp_plural'; |
|
1008 $_ob .= ' <span>' . $lang->get($ls, array( 'num_unapp' => $num_unapp )) . '</span>'; |
|
1009 } |
853 $_ob .= '</p>'; |
1010 $_ob .= '</p>'; |
854 $list = 'list = { '; |
1011 $list = 'list = { '; |
855 // _die(htmlspecialchars($ttext)); |
1012 // _die(htmlspecialchars($ttext)); |
856 $i = -1; |
1013 $i = -1; |
857 while($row = $db->fetchrow($lq)) |
1014 while ( $row = $db->fetchrow($lq) ) |
858 { |
1015 { |
859 $i++; |
1016 $i++; |
860 $strings = Array(); |
1017 $strings = Array(); |
861 $bool = Array(); |
1018 $bool = Array(); |
862 if($session->get_permissions('mod_comments') || $row['approved']) { |
1019 if ( $session->get_permissions('mod_comments') || $row['approved'] ) |
|
1020 { |
863 $list .= $i . ' : { \'comment\' : unescape(\''.rawurlencode($row['comment_data']).'\'), \'name\' : unescape(\''.rawurlencode($row['name']).'\'), \'subject\' : unescape(\''.rawurlencode($row['subject']).'\'), }, '; |
1021 $list .= $i . ' : { \'comment\' : unescape(\''.rawurlencode($row['comment_data']).'\'), \'name\' : unescape(\''.rawurlencode($row['name']).'\'), \'subject\' : unescape(\''.rawurlencode($row['subject']).'\'), }, '; |
864 |
1022 |
865 // Comment ID (used in the Javascript apps) |
1023 // Comment ID (used in the Javascript apps) |
866 $strings['ID'] = (string)$i; |
1024 $strings['ID'] = (string)$i; |
867 |
1025 |
868 // Determine the name, and whether to link to the user page or not |
1026 // Determine the name, and whether to link to the user page or not |
869 $name = ''; |
1027 $name = ''; |
870 if($row['user_id'] > 0) $name .= '<a href="'.makeUrlNS('User', str_replace(' ', '_', $row['name'])).'">'; |
1028 if($row['user_id'] > 1) $name .= '<a href="'.makeUrlNS('User', str_replace(' ', '_', $row['name'])).'">'; |
871 $name .= $row['name']; |
1029 $name .= $row['name']; |
872 if($row['user_id'] > 0) $name .= '</a>'; |
1030 if($row['user_id'] > 1) $name .= '</a>'; |
873 $strings['NAME'] = $name; unset($name); |
1031 $strings['NAME'] = $name; unset($name); |
874 |
1032 |
875 // Subject |
1033 // Subject |
876 $s = $row['subject']; |
1034 $s = $row['subject']; |
877 if(!$row['approved']) $s .= ' <span style="color: #D84308">(Unapproved)</span>'; |
1035 if(!$row['approved']) $s .= ' <span style="color: #D84308">' . $lang->get('comment_msg_note_unapp') . '</span>'; |
878 $strings['SUBJECT'] = $s; |
1036 $strings['SUBJECT'] = $s; |
879 |
1037 |
880 // Date and time |
1038 // Date and time |
881 $strings['DATETIME'] = date('F d, Y h:i a', $row['time']); |
1039 $strings['DATETIME'] = date('F d, Y h:i a', $row['time']); |
882 |
1040 |
883 // User level |
1041 // User level |
884 switch($row['user_level']) |
1042 switch($row['user_level']) |
885 { |
1043 { |
886 default: |
1044 default: |
887 case USER_LEVEL_GUEST: |
1045 case USER_LEVEL_GUEST: |
888 $l = 'Guest'; |
1046 $l = $lang->get('user_type_guest'); |
889 break; |
1047 break; |
890 case USER_LEVEL_MEMBER: |
1048 case USER_LEVEL_MEMBER: |
891 $l = 'Member'; |
1049 case USER_LEVEL_CHPREF: |
|
1050 $l = $lang->get('user_type_member'); |
892 break; |
1051 break; |
893 case USER_LEVEL_MOD: |
1052 case USER_LEVEL_MOD: |
894 $l = 'Moderator'; |
1053 $l = $lang->get('user_type_mod'); |
895 break; |
1054 break; |
896 case USER_LEVEL_ADMIN: |
1055 case USER_LEVEL_ADMIN: |
897 $l = 'Administrator'; |
1056 $l = $lang->get('user_type_admin'); |
898 break; |
1057 break; |
899 } |
1058 } |
900 $strings['USER_LEVEL'] = $l; unset($l); |
1059 $strings['USER_LEVEL'] = $l; unset($l); |
901 |
1060 |
902 // The actual comment data |
1061 // The actual comment data |
903 $strings['DATA'] = RenderMan::render($row['comment_data']); |
1062 $strings['DATA'] = RenderMan::render($row['comment_data']); |
904 |
1063 |
905 if($session->get_permissions('edit_comments')) |
1064 if($session->get_permissions('edit_comments')) |
906 { |
1065 { |
907 // Edit link |
1066 // Edit link |
908 $strings['EDIT_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=editcomment&id='.$row['comment_id']).'" id="editbtn_'.$i.'">edit</a>'; |
1067 $strings['EDIT_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=editcomment&id=' . $row['comment_id']) . '" id="editbtn_' . $i . '">' . $lang->get('comment_btn_edit') . '</a>'; |
909 |
1068 |
910 // Delete link |
1069 // Delete link |
911 $strings['DELETE_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=deletecomment&id='.$row['comment_id']).'">delete</a>'; |
1070 $strings['DELETE_LINK'] = '<a href="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=deletecomment&id=' . $row['comment_id']) . '">' . $lang->get('comment_btn_delete') . '</a>'; |
912 } |
1071 } |
913 else |
1072 else |
914 { |
1073 { |
915 // Edit link |
1074 // Edit link |
916 $strings['EDIT_LINK'] = ''; |
1075 $strings['EDIT_LINK'] = ''; |
948 $_ob .= $tpl->run(); |
1107 $_ob .= $tpl->run(); |
949 } |
1108 } |
950 } |
1109 } |
951 if(getConfig('comments_need_login') != '2' || $session->user_logged_in) |
1110 if(getConfig('comments_need_login') != '2' || $session->user_logged_in) |
952 { |
1111 { |
953 if(!$session->get_permissions('post_comments')) |
1112 if($session->get_permissions('post_comments')) |
954 { |
1113 { |
955 $_ob .= '<h3>Got something to say?</h3><p>Access to post comments on this page is denied.</p>'; |
1114 $_ob .= '<h3>' . $lang->get('comment_postform_title') . '</h3>'; |
956 } |
1115 $_ob .= $lang->get('comment_postform_blurb'); |
957 else |
1116 if(getConfig('approve_comments')=='1') $_ob .= ' ' . $lang->get('comment_postform_blurb_unapp'); |
958 { |
1117 if(getConfig('comments_need_login') == '1' && !$session->user_logged_in) |
959 $_ob .= '<h3>Got something to say?</h3>If you have comments or suggestions on this article, you can shout it out here.'; |
1118 { |
960 if(getConfig('approve_comments')=='1') $_ob .= ' Before your comment will be visible to the public, a moderator will have to approve it.'; |
1119 $_ob .= ' ' . $lang->get('comment_postform_blurb_captcha'); |
961 if(getConfig('comments_need_login') == '1' && !$session->user_logged_in) $_ob .= ' Because you are not logged in, you will need to enter a visual confirmation before your comment will be posted.'; |
1120 } |
962 $sn = $session->user_logged_in ? $session->username . '<input name="name" id="mdgScreenName" type="hidden" value="'.$session->username.'" />' : '<input name="name" id="mdgScreenName" type="text" size="35" />'; |
1121 $sn = $session->user_logged_in ? $session->username . '<input name="name" id="mdgScreenName" type="hidden" value="' . $session->username . '" />' : '<input name="name" id="mdgScreenName" type="text" size="35" />'; |
963 $_ob .= ' <a href="#" id="mdgCommentFormLink" style="display: none;" onclick="document.getElementById(\'mdgCommentForm\').style.display=\'block\';this.style.display=\'none\';return false;">Leave a comment...</a> |
1122 $_ob .= ' <a href="#" id="mdgCommentFormLink" style="display: none;" onclick="document.getElementById(\'mdgCommentForm\').style.display=\'block\';this.style.display=\'none\';return false;">' . $lang->get('comment_postform_blurb_link') . '</a> |
964 <div id="mdgCommentForm"> |
1123 <div id="mdgCommentForm"> |
965 <h3>Comment form</h3> |
|
966 <form action="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=postcomment').'" method="post" style="margin-left: 1em"> |
1124 <form action="'.makeUrlNS($namespace, $page_id, 'do=comments&sub=postcomment').'" method="post" style="margin-left: 1em"> |
967 <table border="0"> |
1125 <table border="0"> |
968 <tr><td>Your name or screen name:</td><td>'.$sn.'</td></tr> |
1126 <tr><td>' . $lang->get('comment_postform_field_name') . '</td><td>' . $sn . '</td></tr> |
969 <tr><td>Comment subject:</td><td><input name="subj" id="mdgSubject" type="text" size="35" /></td></tr>'; |
1127 <tr><td>' . $lang->get('comment_postform_field_subject') . '</td><td><input name="subj" id="mdgSubject" type="text" size="35" /></td></tr>'; |
970 if(getConfig('comments_need_login') == '1' && !$session->user_logged_in) |
1128 if(getConfig('comments_need_login') == '1' && !$session->user_logged_in) |
971 { |
1129 { |
972 $session->kill_captcha(); |
1130 $session->kill_captcha(); |
973 $captcha = $session->make_captcha(); |
1131 $captcha = $session->make_captcha(); |
974 $_ob .= '<tr><td>Visual confirmation:<br /><small>Please enter the code you see on the right.</small></td><td><img src="'.makeUrlNS('Special', 'Captcha/'.$captcha).'" alt="Visual confirmation" style="cursor: pointer;" onclick="this.src = \''.makeUrlNS("Special", "Captcha/".$captcha).'/\'+Math.floor(Math.random() * 100000);" /><input name="captcha_id" id="mdgCaptchaID" type="hidden" value="'.$captcha.'" /><br />Code: <input name="captcha_input" id="mdgCaptchaInput" type="text" size="10" /><br /><small><script type="text/javascript">document.write("If you can\'t read the code, click on the image to generate a new one.");</script><noscript>If you can\'t read the code, please refresh this page to generate a new one.</noscript></small></td></tr>'; |
1132 $_ob .= '<tr><td>' . $lang->get('comment_postform_field_captcha_title') . '<br /><small>' . $lang->get('comment_postform_field_captcha_blurb') . '</small></td><td><img src="'.makeUrlNS('Special', 'Captcha/' . $captcha) . '" alt="Visual confirmation" style="cursor: pointer;" onclick="this.src = \''.makeUrlNS("Special", "Captcha/".$captcha).'/\'+Math.floor(Math.random() * 100000);" /><input name="captcha_id" id="mdgCaptchaID" type="hidden" value="' . $captcha . '" /><br />' . $lang->get('comment_postform_field_captcha_label') . ' <input name="captcha_input" id="mdgCaptchaInput" type="text" size="10" /><br /><small><script type="text/javascript">document.write("' . $lang->get('comment_postform_field_captcha_cantread_js') . '");</script><noscript>' . $lang->get('comment_postform_field_captcha_cantread_nojs') . '</noscript></small></td></tr>'; |
975 } |
1133 } |
976 $_ob .= ' |
1134 $_ob .= ' |
977 <tr><td valign="top">Comment text:<br />(most HTML will be stripped)</td><td><textarea name="text" id="mdgCommentArea" rows="10" cols="40"></textarea></td></tr> |
1135 <tr><td valign="top">' . $lang->get('comment_postform_field_comment') . '</td><td><textarea name="text" id="mdgCommentArea" rows="10" cols="40"></textarea></td></tr> |
978 <tr><td colspan="2" style="text-align: center;"><input type="submit" value="Submit Comment" /></td></tr> |
1136 <tr><td colspan="2" style="text-align: center;"><input type="submit" value="' . $lang->get('comment_postform_btn_submit') . '" /></td></tr> |
979 </table> |
1137 </table> |
980 </form> |
1138 </form> |
981 </div>'; |
1139 </div>'; |
982 } |
1140 } |
983 } else { |
1141 } else { |
984 $_ob .= '<h3>Got something to say?</h3><p>You need to be logged in to post comments. <a href="'.makeUrlNS('Special', 'Login/'.$pname.'%2523comments').'">Log in</a></p>'; |
1142 $_ob .= '<h3>Got something to say?</h3><p>You need to be logged in to post comments. <a href="'.makeUrlNS('Special', 'Login/' . $pname . '%2523comments').'">Log in</a></p>'; |
985 } |
1143 } |
986 $list .= '};'; |
1144 $list .= '};'; |
987 echo 'document.getElementById(\'ajaxEditContainer\').innerHTML = unescape(\''. rawurlencode($_ob) .'\'); |
1145 echo 'document.getElementById(\'ajaxEditContainer\').innerHTML = unescape(\''. rawurlencode($_ob) .'\'); |
988 ' . $list; |
1146 ' . $list; |
989 echo 'Fat.fade_all(); document.getElementById(\'mdgCommentForm\').style.display = \'none\'; document.getElementById(\'mdgCommentFormLink\').style.display="inline";'; |
1147 echo 'Fat.fade_all(); document.getElementById(\'mdgCommentForm\').style.display = \'none\'; document.getElementById(\'mdgCommentFormLink\').style.display="inline";'; |
1050 $old_subject = $db->escape($old_subject); |
1208 $old_subject = $db->escape($old_subject); |
1051 // Safety check - username/login |
1209 // Safety check - username/login |
1052 if(!$session->get_permissions('mod_comments')) // allow mods to edit comments |
1210 if(!$session->get_permissions('mod_comments')) // allow mods to edit comments |
1053 { |
1211 { |
1054 if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.'); |
1212 if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.'); |
1055 $q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_data=\''.$old_text.'\' AND subject=\''.$old_subject.'\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;'; |
1213 $q = 'SELECT c.name FROM ' . table_prefix.'comments c, ' . table_prefix.'users u WHERE comment_data=\'' . $old_text . '\' AND subject=\'' . $old_subject . '\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND u.user_id=c.user_id;'; |
1056 $s = $db->sql_query($q); |
1214 $s = $db->sql_query($q); |
1057 if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>'); |
1215 if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>'); |
1058 $r = $db->fetchrow($s); |
1216 $r = $db->fetchrow($s); |
1059 $db->free_result(); |
1217 $db->free_result(); |
1060 if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.'); |
1218 if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.'); |
1061 } |
1219 } |
1062 $s = RenderMan::preprocess_text($subject); |
1220 $s = RenderMan::preprocess_text($subject); |
1063 $t = RenderMan::preprocess_text($text); |
1221 $t = RenderMan::preprocess_text($text); |
1064 $sql = 'UPDATE '.table_prefix.'comments SET subject=\''.$s.'\',comment_data=\''.$t.'\' WHERE comment_data=\''.$old_text.'\' AND subject=\''.$old_subject.'\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''; |
1222 $sql = 'UPDATE ' . table_prefix.'comments SET subject=\'' . $s . '\',comment_data=\'' . $t . '\' WHERE comment_data=\'' . $old_text . '\' AND subject=\'' . $old_subject . '\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''; |
1065 $result = $db->sql_query($sql); |
1223 $result = $db->sql_query($sql); |
1066 if($result) |
1224 if($result) |
1067 { |
1225 { |
1068 return 'result="GOOD"; |
1226 return 'result="GOOD"; |
1069 list['.$id.'][\'subject\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $s))))).'\'); |
1227 list[' . $id . '][\'subject\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $s))))).'\'); |
1070 list['.$id.'][\'comment\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t))))).'\'); id = '.$id.'; |
1228 list[' . $id . '][\'comment\'] = unescape(\''.str_replace('%5Cn', '%0A', rawurlencode(str_replace('{{EnAnO:Newline}}', '\\n', stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t))))).'\'); id = ' . $id . '; |
1071 s = unescape(\''.rawurlencode($s).'\'); |
1229 s = unescape(\''.rawurlencode($s).'\'); |
1072 t = unescape(\''.str_replace('%5Cn', '<br \\/>', rawurlencode(RenderMan::render(str_replace('{{EnAnO:Newline}}', "\n", stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t)))))).'\');'; |
1230 t = unescape(\''.str_replace('%5Cn', '<br \\/>', rawurlencode(RenderMan::render(str_replace('{{EnAnO:Newline}}', "\n", stripslashes(str_replace('\\n', '{{EnAnO:Newline}}', $t)))))).'\');'; |
1073 } |
1231 } |
1074 else |
1232 else |
1075 { |
1233 { |
1076 return 'result="BAD"; error=unescape("'.rawurlencode('Enano encountered a problem whilst saving the comment. |
1234 return 'result="BAD"; error=unescape("'.rawurlencode('Enano encountered a problem whilst saving the comment. |
1077 Performed SQL: |
1235 Performed SQL: |
1078 '.$sql.' |
1236 ' . $sql . ' |
1079 |
1237 |
1080 Error returned by MySQL: '.mysql_error()).'");'; |
1238 Error returned by MySQL: '.mysql_error()).'");'; |
1081 } |
1239 } |
1082 } |
1240 } |
1083 |
1241 |
1099 return 'Access denied'; |
1257 return 'Access denied'; |
1100 // Safety check - username/login |
1258 // Safety check - username/login |
1101 if(!$session->get_permissions('mod_comments')) // allow mods to edit comments |
1259 if(!$session->get_permissions('mod_comments')) // allow mods to edit comments |
1102 { |
1260 { |
1103 if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.'); |
1261 if(!$session->user_logged_in) _die('AJAX comment save safety check failed because you are not logged in. Sometimes this can happen because you are using a browser that does not send cookies as part of AJAX requests.<br /><br />Please log in and try again.'); |
1104 $q = 'SELECT c.name FROM '.table_prefix.'comments c, '.table_prefix.'users u WHERE comment_id='.$id.' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\' AND u.user_id=c.user_id;'; |
1262 $q = 'SELECT c.name FROM ' . table_prefix.'comments c, ' . table_prefix.'users u WHERE comment_id=' . $id . ' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\' AND u.user_id=c.user_id;'; |
1105 $s = $db->sql_query($q); |
1263 $s = $db->sql_query($q); |
1106 if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>'); |
1264 if(!$s) _die('SQL error during safety check: '.mysql_error().'<br /><br />Attempted SQL:<br /><pre>'.htmlspecialchars($q).'</pre>'); |
1107 $r = $db->fetchrow($s); |
1265 $r = $db->fetchrow($s); |
1108 if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.'); |
1266 if($db->numrows() < 1 || $r['name'] != $session->username) _die('Safety check failed, probably due to a hacking attempt.'); |
1109 $db->free_result(); |
1267 $db->free_result(); |
1110 } |
1268 } |
1111 $s = RenderMan::preprocess_text($subject); |
1269 $s = RenderMan::preprocess_text($subject); |
1112 $t = RenderMan::preprocess_text($text); |
1270 $t = RenderMan::preprocess_text($text); |
1113 $sql = 'UPDATE '.table_prefix.'comments SET subject=\''.$s.'\',comment_data=\''.$t.'\' WHERE comment_id='.$id.' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''; |
1271 $sql = 'UPDATE ' . table_prefix.'comments SET subject=\'' . $s . '\',comment_data=\'' . $t . '\' WHERE comment_id=' . $id . ' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''; |
1114 $result = $db->sql_query($sql); |
1272 $result = $db->sql_query($sql); |
1115 if($result) |
1273 if($result) |
1116 return 'good'; |
1274 return 'good'; |
1117 else return 'Enano encountered a problem whilst saving the comment. |
1275 else return 'Enano encountered a problem whilst saving the comment. |
1118 Performed SQL: |
1276 Performed SQL: |
1119 '.$sql.' |
1277 ' . $sql . ' |
1120 |
1278 |
1121 Error returned by MySQL: '.mysql_error(); |
1279 Error returned by MySQL: '.mysql_error(); |
1122 } |
1280 } |
1123 |
1281 |
1124 /** |
1282 /** |
1204 */ |
1362 */ |
1205 |
1363 |
1206 function rename($page_id, $namespace, $name) |
1364 function rename($page_id, $namespace, $name) |
1207 { |
1365 { |
1208 global $db, $session, $paths, $template, $plugins; // Common objects |
1366 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1367 global $lang; |
1209 |
1368 |
1210 $pname = $paths->nslist[$namespace] . $page_id; |
1369 $pname = $paths->nslist[$namespace] . $page_id; |
1211 |
1370 |
1212 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
1371 $prot = ( ( $paths->pages[$pname]['protected'] == 2 && $session->user_logged_in && $session->reg_time + 60*60*24*4 < time() ) || $paths->pages[$pname]['protected'] == 1) ? true : false; |
1213 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
1372 $wiki = ( ( $paths->pages[$pname]['wiki_mode'] == 2 && getConfig('wiki_mode') == '1') || $paths->pages[$pname]['wiki_mode'] == 1) ? true : false; |
1214 |
1373 |
1215 if( empty($name)) |
1374 if( empty($name)) |
1216 { |
1375 { |
1217 die('Name is too short'); |
1376 return($lang->get('ajax_rename_too_short')); |
1218 } |
1377 } |
1219 if( ( $session->get_permissions('rename') && ( ( $prot && $session->get_permissions('even_when_protected') ) || !$prot ) ) && ( $paths->namespace != 'Special' && $paths->namespace != 'Admin' )) |
1378 if( ( $session->get_permissions('rename') && ( ( $prot && $session->get_permissions('even_when_protected') ) || !$prot ) ) && ( $paths->namespace != 'Special' && $paths->namespace != 'Admin' )) |
1220 { |
1379 { |
1221 $e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'rename\', \''.$db->escape($paths->cpage['urlname_nons']).'\', \''.$paths->namespace.'\', \''.$db->escape($session->username).'\', \''.$db->escape($paths->cpage['name']).'\')'); |
1380 $e = $db->sql_query('INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'rename\', \'' . $db->escape($paths->cpage['urlname_nons']) . '\', \'' . $paths->namespace . '\', \'' . $db->escape($session->username) . '\', \'' . $db->escape($paths->cpage['name']) . '\')'); |
1222 if ( !$e ) |
1381 if ( !$e ) |
1223 { |
1382 { |
1224 $db->_die('The page title could not be updated.'); |
1383 $db->_die('The page title could not be updated.'); |
1225 } |
1384 } |
1226 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET name=\''.$db->escape($name).'\' WHERE urlname=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';'); |
1385 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET name=\'' . $db->escape($name) . '\' WHERE urlname=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\';'); |
1227 if ( !$e ) |
1386 if ( !$e ) |
1228 { |
1387 { |
1229 $db->_die('The page title could not be updated.'); |
1388 $db->_die('The page title could not be updated.'); |
1230 } |
1389 } |
1231 else |
1390 else |
1232 { |
1391 { |
1233 return('The page "'.$paths->pages[$pname]['name'].'" has been renamed to "'.$name.'". You are encouraged to leave a comment explaining your action.' . "\n\n" . 'You will see the change take effect the next time you reload this page.'); |
1392 $subst = array( |
|
1393 'page_name_old' => $paths->pages[$pname]['name'], |
|
1394 'page_name_new' => $name |
|
1395 ); |
|
1396 return $lang->get('ajax_rename_success', $subst); |
1234 } |
1397 } |
1235 } |
1398 } |
1236 else |
1399 else |
1237 { |
1400 { |
1238 return('Access is denied.'); |
1401 return($lang->get('etc_access_denied')); |
1239 } |
1402 } |
1240 } |
1403 } |
1241 |
1404 |
1242 /** |
1405 /** |
1243 * Flushes (clears) the action logs for a given page |
1406 * Flushes (clears) the action logs for a given page |
1247 */ |
1410 */ |
1248 |
1411 |
1249 function flushlogs($page_id, $namespace) |
1412 function flushlogs($page_id, $namespace) |
1250 { |
1413 { |
1251 global $db, $session, $paths, $template, $plugins; // Common objects |
1414 global $db, $session, $paths, $template, $plugins; // Common objects |
1252 if(!$session->get_permissions('clear_logs')) die('Administrative privileges are required to flush logs, you loser.'); |
1415 global $lang; |
1253 $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';'); |
1416 if(!$session->get_permissions('clear_logs')) |
|
1417 { |
|
1418 return $lang->get('etc_access_denied'); |
|
1419 } |
|
1420 $e = $db->sql_query('DELETE FROM ' . table_prefix.'logs WHERE page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\';'); |
1254 if(!$e) $db->_die('The log entries could not be deleted.'); |
1421 if(!$e) $db->_die('The log entries could not be deleted.'); |
1255 |
1422 |
1256 // If the page exists, make a backup of it in case it gets spammed/vandalized |
1423 // If the page exists, make a backup of it in case it gets spammed/vandalized |
1257 // If not, the admin's probably deleting a trash page |
1424 // If not, the admin's probably deleting a trash page |
1258 if ( isset($paths->pages[ $paths->nslist[$namespace] . $page_id ]) ) |
1425 if ( isset($paths->pages[ $paths->nslist[$namespace] . $page_id ]) ) |
1259 { |
1426 { |
1260 $e = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
1427 $e = $db->sql_query('SELECT page_text,char_tag FROM ' . table_prefix.'page_text WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
1261 if(!$e) $db->_die('The current page text could not be selected; as a result, creating the backup of the page failed. Please make a backup copy of the page by clicking Edit this page and then clicking Save Changes.'); |
1428 if(!$e) $db->_die('The current page text could not be selected; as a result, creating the backup of the page failed. Please make a backup copy of the page by clicking Edit this page and then clicking Save Changes.'); |
1262 $row = $db->fetchrow(); |
1429 $row = $db->fetchrow(); |
1263 $db->free_result(); |
1430 $db->free_result(); |
1264 $q='INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \''.$page_id.'\', \''.$namespace.'\', \''.$db->escape($row['page_text']).'\', \''.$row['char_tag'].'\', \''.$session->username.'\', \''."Automatic backup created when logs were purged".'\', '.'false'.');'; |
1431 $q='INSERT INTO ' . table_prefix.'logs(log_type,action,time_id,date_string,page_id,namespace,page_text,char_tag,author,edit_summary,minor_edit) VALUES(\'page\', \'edit\', '.time().', \''.date('d M Y h:i a').'\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $db->escape($row['page_text']) . '\', \'' . $row['char_tag'] . '\', \'' . $session->username . '\', \''."Automatic backup created when logs were purged".'\', '.'false'.');'; |
1265 if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.'); |
1432 if(!$db->sql_query($q)) $db->_die('The history (log) entry could not be inserted into the logs table.'); |
1266 } |
1433 } |
1267 return('The logs for this page have been cleared. A backup of this page has been added to the logs table so that this page can be restored in case of vandalism or spam later.'); |
1434 return $lang->get('ajax_clearlogs_success'); |
1268 } |
1435 } |
1269 |
1436 |
1270 /** |
1437 /** |
1271 * Deletes a page. |
1438 * Deletes a page. |
1272 * @param string $page_id the condemned page ID |
1439 * @param string $page_id the condemned page ID |
1276 */ |
1443 */ |
1277 |
1444 |
1278 function deletepage($page_id, $namespace, $reason) |
1445 function deletepage($page_id, $namespace, $reason) |
1279 { |
1446 { |
1280 global $db, $session, $paths, $template, $plugins; // Common objects |
1447 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1448 global $lang; |
1281 $perms = $session->fetch_page_acl($page_id, $namespace); |
1449 $perms = $session->fetch_page_acl($page_id, $namespace); |
1282 $x = trim($reason); |
1450 $x = trim($reason); |
1283 if ( empty($x) ) |
1451 if ( empty($x) ) |
1284 { |
1452 { |
1285 return 'Invalid reason for deletion passed'; |
1453 return $lang->get('ajax_delete_need_reason'); |
1286 } |
1454 } |
1287 if(!$perms->get_permissions('delete_page')) return('Administrative privileges are required to delete pages, you loser.'); |
1455 if(!$perms->get_permissions('delete_page')) return('Administrative privileges are required to delete pages, you loser.'); |
1288 $e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'delete\', \''.$page_id.'\', \''.$namespace.'\', \''.$session->username.'\', \'' . $db->escape(htmlspecialchars($reason)) . '\')'); |
1456 $e = $db->sql_query('INSERT INTO ' . table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author,edit_summary) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'delete\', \'' . $page_id . '\', \'' . $namespace . '\', \'' . $session->username . '\', \'' . $db->escape(htmlspecialchars($reason)) . '\')'); |
1289 if(!$e) $db->_die('The page log entry could not be inserted.'); |
1457 if(!$e) $db->_die('The page log entry could not be inserted.'); |
1290 $e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
1458 $e = $db->sql_query('DELETE FROM ' . table_prefix.'categories WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''); |
1291 if(!$e) $db->_die('The page categorization entries could not be deleted.'); |
1459 if(!$e) $db->_die('The page categorization entries could not be deleted.'); |
1292 $e = $db->sql_query('DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
1460 $e = $db->sql_query('DELETE FROM ' . table_prefix.'comments WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''); |
1293 if(!$e) $db->_die('The page comments could not be deleted.'); |
1461 if(!$e) $db->_die('The page comments could not be deleted.'); |
1294 $e = $db->sql_query('DELETE FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
1462 $e = $db->sql_query('DELETE FROM ' . table_prefix.'page_text WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''); |
1295 if(!$e) $db->_die('The page text entry could not be deleted.'); |
1463 if(!$e) $db->_die('The page text entry could not be deleted.'); |
1296 $e = $db->sql_query('DELETE FROM '.table_prefix.'pages WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
1464 $e = $db->sql_query('DELETE FROM ' . table_prefix.'pages WHERE urlname=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\''); |
1297 if(!$e) $db->_die('The page entry could not be deleted.'); |
1465 if(!$e) $db->_die('The page entry could not be deleted.'); |
1298 $e = $db->sql_query('DELETE FROM '.table_prefix.'files WHERE page_id=\''.$page_id.'\''); |
1466 $e = $db->sql_query('DELETE FROM ' . table_prefix.'files WHERE page_id=\'' . $page_id . '\''); |
1299 if(!$e) $db->_die('The file entry could not be deleted.'); |
1467 if(!$e) $db->_die('The file entry could not be deleted.'); |
1300 return('This page has been deleted. Note that there is still a log of edits and actions in the database, and anyone with admin rights can raise this page from the dead unless the log is cleared. If the deleted file is an image, there may still be cached thumbnails of it in the cache/ directory, which is inaccessible to users.'); |
1468 return $lang->get('ajax_delete_success'); |
1301 } |
1469 } |
1302 |
1470 |
1303 /** |
1471 /** |
1304 * Increments the deletion votes for a page by 1, and adds the current username/IP to the list of users that have voted for the page to prevent dual-voting |
1472 * Increments the deletion votes for a page by 1, and adds the current username/IP to the list of users that have voted for the page to prevent dual-voting |
1305 * @param $page_id the page ID |
1473 * @param $page_id the page ID |
1548 ( !$page_perms->get_permissions('even_when_protected') && $page_data['protected'] == '1' ) ) |
1729 ( !$page_perms->get_permissions('even_when_protected') && $page_data['protected'] == '1' ) ) |
1549 $auth = false; |
1730 $auth = false; |
1550 if(!$auth) |
1731 if(!$auth) |
1551 { |
1732 { |
1552 // Find out if the page is currently in the category |
1733 // Find out if the page is currently in the category |
1553 $q = $db->sql_query('SELECT * FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
1734 $q = $db->sql_query('SELECT * FROM ' . table_prefix.'categories WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
1554 if(!$q) |
1735 if(!$q) |
1555 return 'MySQL error: '.$db->get_error(); |
1736 return 'MySQL error: ' . $db->get_error(); |
1556 if($db->numrows() > 0) |
1737 if($db->numrows() > 0) |
1557 { |
1738 { |
1558 $auth = true; |
1739 $auth = true; |
1559 $which_cats[$cat_all[$i]['urlname_nons']] = true; // Force the category to stay in its current state |
1740 $which_cats[$cat_all[$i]['urlname_nons']] = true; // Force the category to stay in its current state |
1560 } |
1741 } |
1561 $db->free_result(); |
1742 $db->free_result(); |
1562 } |
1743 } |
1563 if(isset($which_cats[$cat_all[$i]['urlname_nons']]) && $which_cats[$cat_all[$i]['urlname_nons']] == true /* for clarity ;-) */ && $auth ) $rowlist[] = '(\''.$page_id.'\', \''.$namespace.'\', \''.$cat_all[$i]['urlname_nons'].'\')'; |
1744 if(isset($which_cats[$cat_all[$i]['urlname_nons']]) && $which_cats[$cat_all[$i]['urlname_nons']] == true /* for clarity ;-) */ && $auth ) $rowlist[] = '(\'' . $page_id . '\', \'' . $namespace . '\', \'' . $cat_all[$i]['urlname_nons'] . '\')'; |
1564 } |
1745 } |
1565 if(sizeof($rowlist) > 0) |
1746 if(sizeof($rowlist) > 0) |
1566 { |
1747 { |
1567 $val = implode(',', $rowlist); |
1748 $val = implode(',', $rowlist); |
1568 $q = 'INSERT INTO '.table_prefix.'categories(page_id,namespace,category_id) VALUES' . $val . ';'; |
1749 $q = 'INSERT INTO ' . table_prefix.'categories(page_id,namespace,category_id) VALUES' . $val . ';'; |
1569 $e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
1750 $e = $db->sql_query('DELETE FROM ' . table_prefix.'categories WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
1570 if(!$e) $db->_die('The old category data could not be deleted.'); |
1751 if(!$e) $db->_die('The old category data could not be deleted.'); |
1571 $e = $db->sql_query($q); |
1752 $e = $db->sql_query($q); |
1572 if(!$e) $db->_die('The new category data could not be inserted.'); |
1753 if(!$e) $db->_die('The new category data could not be inserted.'); |
1573 return('GOOD'); |
1754 return('GOOD'); |
1574 } |
1755 } |
1575 else |
1756 else |
1576 { |
1757 { |
1577 $e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
1758 $e = $db->sql_query('DELETE FROM ' . table_prefix.'categories WHERE page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
1578 if(!$e) $db->_die('The old category data could not be deleted.'); |
1759 if(!$e) $db->_die('The old category data could not be deleted.'); |
1579 return('GOOD'); |
1760 return('GOOD'); |
1580 } |
1761 } |
1581 } |
1762 } |
1582 |
1763 |
1607 */ |
1794 */ |
1608 |
1795 |
1609 function setpass($page_id, $namespace, $pass) |
1796 function setpass($page_id, $namespace, $pass) |
1610 { |
1797 { |
1611 global $db, $session, $paths, $template, $plugins; // Common objects |
1798 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1799 global $lang; |
1612 // Determine permissions |
1800 // Determine permissions |
1613 if($paths->pages[$paths->nslist[$namespace].$page_id]['password'] != '') |
1801 if($paths->pages[$paths->nslist[$namespace].$page_id]['password'] != '') |
1614 $a = $session->get_permissions('password_reset'); |
1802 $a = $session->get_permissions('password_reset'); |
1615 else |
1803 else |
1616 $a = $session->get_permissions('password_set'); |
1804 $a = $session->get_permissions('password_set'); |
1617 if(!$a) |
1805 if(!$a) |
1618 return 'Access is denied'; |
1806 return $lang->get('etc_access_denied'); |
1619 if(!isset($pass)) return('Password was not set on URL'); |
1807 if(!isset($pass)) return('Password was not set on URL'); |
1620 $p = $pass; |
1808 $p = $pass; |
1621 if(!preg_match('#([0-9a-f]){40,40}#', $p)) $p = sha1($p); |
1809 if ( !preg_match('#([0-9a-f]){40,40}#', $p) ) |
1622 if($p=='da39a3ee5e6b4b0d3255bfef95601890afd80709') $p = ''; |
1810 { |
1623 $e = $db->sql_query('UPDATE '.table_prefix.'pages SET password=\''.$p.'\' WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\';'); |
1811 $p = sha1($p); |
1624 if(!$e) die('PageUtils::setpass(): Error during update query: '.mysql_error()."\n\nSQL Backtrace:\n".$db->sql_backtrace()); |
1812 } |
1625 if($p=='') return('The password for this page has been disabled.'); |
1813 if ( $p == 'da39a3ee5e6b4b0d3255bfef95601890afd80709' ) |
1626 else return('The password for this page has been set.'); |
1814 // sha1('') = da39a3ee5e6b4b0d3255bfef95601890afd80709 |
|
1815 $p = ''; |
|
1816 $e = $db->sql_query('UPDATE ' . table_prefix.'pages SET password=\'' . $p . '\' WHERE urlname=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';'); |
|
1817 if ( !$e ) |
|
1818 { |
|
1819 die('PageUtils::setpass(): Error during update query: '.mysql_error()."\n\nSQL Backtrace:\n".$db->sql_backtrace()); |
|
1820 } |
|
1821 // Is the new password blank? |
|
1822 if ( $p == '' ) |
|
1823 { |
|
1824 return $lang->get('ajax_password_disable_success'); |
|
1825 } |
|
1826 else |
|
1827 { |
|
1828 return $lang->get('ajax_password_success'); |
|
1829 } |
1627 } |
1830 } |
1628 |
1831 |
1629 /** |
1832 /** |
1630 * Generates some preview HTML |
1833 * Generates some preview HTML |
1631 * @param $text string the wikitext to use |
1834 * @param $text string the wikitext to use |
1632 * @return string |
1835 * @return string |
1633 */ |
1836 */ |
1634 |
1837 |
1635 function genPreview($text) |
1838 function genPreview($text) |
1636 { |
1839 { |
1637 $ret = '<div class="info-box"><b>Reminder:</b> This is only a preview - your changes to this page have not yet been saved.</div><div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: 250px; overflow: auto; margin: 1em 0 1em 1em;">'; |
1840 global $lang; |
|
1841 $ret = '<div class="info-box">' . $lang->get('editor_preview_blurb') . '</div><div style="background-color: #F8F8F8; padding: 10px; border: 1px dashed #406080; max-height: 250px; overflow: auto; margin: 1em 0 1em 1em;">'; |
1638 $text = RenderMan::render(RenderMan::preprocess_text($text, false, false)); |
1842 $text = RenderMan::render(RenderMan::preprocess_text($text, false, false)); |
1639 ob_start(); |
1843 ob_start(); |
1640 eval('?>' . $text); |
1844 eval('?>' . $text); |
1641 $text = ob_get_contents(); |
1845 $text = ob_get_contents(); |
1642 ob_end_clean(); |
1846 ob_end_clean(); |
1667 */ |
1871 */ |
1668 |
1872 |
1669 function pagediff($page_id, $namespace, $id1, $id2) |
1873 function pagediff($page_id, $namespace, $id1, $id2) |
1670 { |
1874 { |
1671 global $db, $session, $paths, $template, $plugins; // Common objects |
1875 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1876 global $lang; |
1672 if(!$session->get_permissions('history_view')) |
1877 if(!$session->get_permissions('history_view')) |
1673 return 'Access denied'; |
1878 return $lang->get('etc_access_denied'); |
1674 if(!preg_match('#^([0-9]+)$#', (string)$id1) || |
1879 if(!preg_match('#^([0-9]+)$#', (string)$id1) || |
1675 !preg_match('#^([0-9]+)$#', (string)$id2 )) return 'SQL injection attempt'; |
1880 !preg_match('#^([0-9]+)$#', (string)$id2 )) return 'SQL injection attempt'; |
1676 // OK we made it through security |
1881 // OK we made it through security |
1677 // Safest way to make sure we don't end up with the revisions in wrong columns is to make 2 queries |
1882 // Safest way to make sure we don't end up with the revisions in wrong columns is to make 2 queries |
1678 if(!$q1 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id1.' AND log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';')) return 'MySQL error: '.mysql_error(); |
1883 if(!$q1 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE time_id=' . $id1 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: '.mysql_error(); |
1679 if(!$q2 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM '.table_prefix.'logs WHERE time_id='.$id2.' AND log_type=\'page\' AND action=\'edit\' AND page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\';')) return 'MySQL error: '.mysql_error(); |
1884 if(!$q2 = $db->sql_query('SELECT page_text,char_tag,author,edit_summary FROM ' . table_prefix.'logs WHERE time_id=' . $id2 . ' AND log_type=\'page\' AND action=\'edit\' AND page_id=\'' . $page_id . '\' AND namespace=\'' . $namespace . '\';')) return 'MySQL error: '.mysql_error(); |
1680 $row1 = $db->fetchrow($q1); |
1885 $row1 = $db->fetchrow($q1); |
1681 $db->free_result($q1); |
1886 $db->free_result($q1); |
1682 $row2 = $db->fetchrow($q2); |
1887 $row2 = $db->fetchrow($q2); |
1683 $db->free_result($q2); |
1888 $db->free_result($q2); |
1684 if(sizeof($row1) < 1 || sizeof($row2) < 2) return 'Couldn\'t find any rows that matched the query. The time ID probably doesn\'t exist in the logs table.'; |
1889 if(sizeof($row1) < 1 || sizeof($row2) < 2) return 'Couldn\'t find any rows that matched the query. The time ID probably doesn\'t exist in the logs table.'; |
1685 $text1 = $row1['page_text']; |
1890 $text1 = $row1['page_text']; |
1686 $text2 = $row2['page_text']; |
1891 $text2 = $row2['page_text']; |
1687 $time1 = date('F d, Y h:i a', $id1); |
1892 $time1 = date('F d, Y h:i a', $id1); |
1688 $time2 = date('F d, Y h:i a', $id2); |
1893 $time2 = date('F d, Y h:i a', $id2); |
1689 $_ob = " |
1894 $_ob = " |
1690 <p>Comparing revisions: {$time1} → {$time2}</p> |
1895 <p>" . $lang->get('history_lbl_comparingrevisions') . " {$time1} → {$time2}</p> |
1691 "; |
1896 "; |
1692 // Free some memory |
1897 // Free some memory |
1693 unset($row1, $row2, $q1, $q2); |
1898 unset($row1, $row2, $q1, $q2); |
1694 |
1899 |
1695 $_ob .= RenderMan::diff($text1, $text2); |
1900 $_ob .= RenderMan::diff($text1, $text2); |
1696 return $_ob; |
1901 return $_ob; |
1697 } |
1902 } |
1698 |
1903 |
1699 /** |
1904 /** |
1700 * Gets ACL information about the selected page for target type X and target ID Y. |
1905 * Gets ACL information about the selected page for target type X and target ID Y. |
1701 * @param string $page_id The page ID |
|
1702 * @param string $namespace The namespace |
|
1703 * @param array $parms What to select. This is an array purely for JSON compatibility. It should be an associative array with keys target_type and target_id. |
1906 * @param array $parms What to select. This is an array purely for JSON compatibility. It should be an associative array with keys target_type and target_id. |
1704 * @return array |
1907 * @return array |
1705 */ |
1908 */ |
1706 |
1909 |
1707 function acl_editor($parms = Array()) |
1910 function acl_editor($parms = Array()) |
1708 { |
1911 { |
1709 global $db, $session, $paths, $template, $plugins; // Common objects |
1912 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1913 global $lang; |
|
1914 |
1710 if(!$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN) |
1915 if(!$session->get_permissions('edit_acl') && $session->user_level < USER_LEVEL_ADMIN) |
1711 { |
1916 { |
1712 return Array( |
1917 return Array( |
1713 'mode' => 'error', |
1918 'mode' => 'error', |
1714 'error' => 'You are not authorized to view or edit access control lists.' |
1919 'error' => $lang->get('acl_err_access_denied') |
1715 ); |
1920 ); |
1716 } |
1921 } |
1717 $parms['page_id'] = ( isset($parms['page_id']) ) ? $parms['page_id'] : false; |
1922 $parms['page_id'] = ( isset($parms['page_id']) ) ? $parms['page_id'] : false; |
1718 $parms['namespace'] = ( isset($parms['namespace']) ) ? $parms['namespace'] : false; |
1923 $parms['namespace'] = ( isset($parms['namespace']) ) ? $parms['namespace'] : false; |
1719 $page_id =& $parms['page_id']; |
1924 $page_id =& $parms['page_id']; |
1720 $namespace =& $parms['namespace']; |
1925 $namespace =& $parms['namespace']; |
1721 $page_where_clause = ( empty($page_id) || empty($namespace) ) ? 'AND a.page_id IS NULL AND a.namespace IS NULL' : 'AND a.page_id=\''.$db->escape($page_id).'\' AND a.namespace=\''.$db->escape($namespace).'\''; |
1926 $page_where_clause = ( empty($page_id) || empty($namespace) ) ? 'AND a.page_id IS NULL AND a.namespace IS NULL' : 'AND a.page_id=\'' . $db->escape($page_id) . '\' AND a.namespace=\'' . $db->escape($namespace) . '\''; |
1722 $page_where_clause_lite = ( empty($page_id) || empty($namespace) ) ? 'AND page_id IS NULL AND namespace IS NULL' : 'AND page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\''; |
1927 $page_where_clause_lite = ( empty($page_id) || empty($namespace) ) ? 'AND page_id IS NULL AND namespace IS NULL' : 'AND page_id=\'' . $db->escape($page_id) . '\' AND namespace=\'' . $db->escape($namespace) . '\''; |
1723 //die(print_r($page_id,true)); |
1928 //die(print_r($page_id,true)); |
1724 $template->load_theme(); |
1929 $template->load_theme(); |
1725 // $perms_obj = $session->fetch_page_acl($page_id, $namespace); |
1930 // $perms_obj = $session->fetch_page_acl($page_id, $namespace); |
1726 $perms_obj =& $session; |
1931 $perms_obj =& $session; |
1727 $return = Array(); |
1932 $return = Array(); |
1728 if ( !file_exists(ENANO_ROOT . '/themes/' . $session->theme . '/acledit.tpl') ) |
1933 if ( !file_exists(ENANO_ROOT . '/themes/' . $session->theme . '/acledit.tpl') ) |
1729 { |
1934 { |
1730 return Array( |
1935 return Array( |
1731 'mode' => 'error', |
1936 'mode' => 'error', |
1732 'error' => 'It seems that (a) the file acledit.tpl is missing from these theme, and (b) the JSON response is working.', |
1937 'error' => $lang->get('acl_err_missing_template'), |
1733 ); |
1938 ); |
1734 } |
1939 } |
1735 $return['template'] = $template->extract_vars('acledit.tpl'); |
1940 $return['template'] = $template->extract_vars('acledit.tpl'); |
1736 $return['page_id'] = $page_id; |
1941 $return['page_id'] = $page_id; |
1737 $return['namespace'] = $namespace; |
1942 $return['namespace'] = $namespace; |
1773 $return['target_type'] = $parms['target_type']; |
1978 $return['target_type'] = $parms['target_type']; |
1774 $return['target_id'] = $parms['target_id']; |
1979 $return['target_id'] = $parms['target_id']; |
1775 switch($parms['target_type']) |
1980 switch($parms['target_type']) |
1776 { |
1981 { |
1777 case ACL_TYPE_USER: |
1982 case ACL_TYPE_USER: |
1778 $q = $db->sql_query('SELECT a.rules,u.user_id FROM '.table_prefix.'users AS u |
1983 $q = $db->sql_query('SELECT a.rules,u.user_id FROM ' . table_prefix.'users AS u |
1779 LEFT JOIN '.table_prefix.'acl AS a |
1984 LEFT JOIN ' . table_prefix.'acl AS a |
1780 ON a.target_id=u.user_id |
1985 ON a.target_id=u.user_id |
1781 WHERE a.target_type='.ACL_TYPE_USER.' |
1986 WHERE a.target_type='.ACL_TYPE_USER.' |
1782 AND u.username=\''.$db->escape($parms['target_id']).'\' |
1987 AND u.username=\'' . $db->escape($parms['target_id']) . '\' |
1783 '.$page_where_clause.';'); |
1988 ' . $page_where_clause . ';'); |
1784 if(!$q) |
1989 if(!$q) |
1785 return(Array('mode'=>'error','error'=>mysql_error())); |
1990 return(Array('mode'=>'error','error'=>mysql_error())); |
1786 if($db->numrows() < 1) |
1991 if($db->numrows() < 1) |
1787 { |
1992 { |
1788 $return['type'] = 'new'; |
1993 $return['type'] = 'new'; |
1789 $q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE username=\''.$db->escape($parms['target_id']).'\';'); |
1994 $q = $db->sql_query('SELECT user_id FROM ' . table_prefix.'users WHERE username=\'' . $db->escape($parms['target_id']) . '\';'); |
1790 if(!$q) |
1995 if(!$q) |
1791 return(Array('mode'=>'error','error'=>mysql_error())); |
1996 return(Array('mode'=>'error','error'=>mysql_error())); |
1792 if($db->numrows() < 1) |
1997 if($db->numrows() < 1) |
1793 return Array('mode'=>'error','error'=>'The username you entered was not found.'); |
1998 return Array('mode'=>'error','error'=>$lang->get('acl_err_user_not_found')); |
1794 $row = $db->fetchrow(); |
1999 $row = $db->fetchrow(); |
1795 $return['target_name'] = $return['target_id']; |
2000 $return['target_name'] = $return['target_id']; |
1796 $return['target_id'] = intval($row['user_id']); |
2001 $return['target_id'] = intval($row['user_id']); |
1797 $return['current_perms'] = $session->acl_types; |
2002 $return['current_perms'] = $session->acl_types; |
1798 } |
2003 } |
1820 } |
2025 } |
1821 } |
2026 } |
1822 } |
2027 } |
1823 break; |
2028 break; |
1824 case ACL_TYPE_GROUP: |
2029 case ACL_TYPE_GROUP: |
1825 $q = $db->sql_query('SELECT a.rules,g.group_name,g.group_id FROM '.table_prefix.'groups AS g |
2030 $q = $db->sql_query('SELECT a.rules,g.group_name,g.group_id FROM ' . table_prefix.'groups AS g |
1826 LEFT JOIN '.table_prefix.'acl AS a |
2031 LEFT JOIN ' . table_prefix.'acl AS a |
1827 ON a.target_id=g.group_id |
2032 ON a.target_id=g.group_id |
1828 WHERE a.target_type='.ACL_TYPE_GROUP.' |
2033 WHERE a.target_type='.ACL_TYPE_GROUP.' |
1829 AND g.group_id=\''.intval($parms['target_id']).'\' |
2034 AND g.group_id=\''.intval($parms['target_id']).'\' |
1830 '.$page_where_clause.';'); |
2035 ' . $page_where_clause . ';'); |
1831 if(!$q) |
2036 if(!$q) |
1832 return(Array('mode'=>'error','error'=>mysql_error())); |
2037 return(Array('mode'=>'error','error'=>mysql_error())); |
1833 if($db->numrows() < 1) |
2038 if($db->numrows() < 1) |
1834 { |
2039 { |
1835 $return['type'] = 'new'; |
2040 $return['type'] = 'new'; |
1836 $q = $db->sql_query('SELECT group_id,group_name FROM '.table_prefix.'groups WHERE group_id=\''.intval($parms['target_id']).'\';'); |
2041 $q = $db->sql_query('SELECT group_id,group_name FROM ' . table_prefix.'groups WHERE group_id=\''.intval($parms['target_id']).'\';'); |
1837 if(!$q) |
2042 if(!$q) |
1838 return(Array('mode'=>'error','error'=>mysql_error())); |
2043 return(Array('mode'=>'error','error'=>mysql_error())); |
1839 if($db->numrows() < 1) |
2044 if($db->numrows() < 1) |
1840 return Array('mode'=>'error','error'=>'The group ID you submitted is not valid.'); |
2045 return Array('mode'=>'error','error'=>$lang->get('acl_err_bad_group_id')); |
1841 $row = $db->fetchrow(); |
2046 $row = $db->fetchrow(); |
1842 $return['target_name'] = $row['group_name']; |
2047 $return['target_name'] = $row['group_name']; |
1843 $return['target_id'] = intval($row['group_id']); |
2048 $return['target_id'] = intval($row['group_id']); |
1844 $return['current_perms'] = $session->acl_types; |
2049 $return['current_perms'] = $session->acl_types; |
1845 } |
2050 } |
1877 break; |
2082 break; |
1878 case 'save_new': |
2083 case 'save_new': |
1879 case 'save_edit': |
2084 case 'save_edit': |
1880 if ( defined('ENANO_DEMO_MODE') ) |
2085 if ( defined('ENANO_DEMO_MODE') ) |
1881 { |
2086 { |
1882 return Array('mode'=>'error','error'=>'Editing access control lists is disabled in the administration demo.'); |
2087 return Array('mode'=>'error','error'=>$lang->get('acl_err_demo')); |
1883 } |
2088 } |
1884 $q = $db->sql_query('DELETE FROM '.table_prefix.'acl WHERE target_type='.intval($parms['target_type']).' AND target_id='.intval($parms['target_id']).' |
2089 $q = $db->sql_query('DELETE FROM ' . table_prefix.'acl WHERE target_type='.intval($parms['target_type']).' AND target_id='.intval($parms['target_id']).' |
1885 '.$page_where_clause_lite.';'); |
2090 ' . $page_where_clause_lite . ';'); |
1886 if(!$q) |
2091 if(!$q) |
1887 return Array('mode'=>'error','error'=>mysql_error()); |
2092 return Array('mode'=>'error','error'=>mysql_error()); |
1888 $rules = $session->perm_to_string($parms['perms']); |
2093 $rules = $session->perm_to_string($parms['perms']); |
1889 if ( sizeof ( $rules ) < 1 ) |
2094 if ( sizeof ( $rules ) < 1 ) |
1890 { |
2095 { |
1891 return array( |
2096 return array( |
1892 'mode' => 'error', |
2097 'mode' => 'error', |
1893 'error' => 'Supplied rule list has a length of zero' |
2098 'error' => $lang->get('acl_err_zero_list') |
1894 ); |
2099 ); |
1895 } |
2100 } |
1896 $q = ($page_id && $namespace) ? 'INSERT INTO '.table_prefix.'acl ( target_type, target_id, page_id, namespace, rules ) |
2101 $q = ($page_id && $namespace) ? 'INSERT INTO ' . table_prefix.'acl ( target_type, target_id, page_id, namespace, rules ) |
1897 VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \''.$db->escape($page_id).'\', \''.$db->escape($namespace).'\', \''.$db->escape($rules).'\' )' : |
2102 VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \'' . $db->escape($page_id) . '\', \'' . $db->escape($namespace) . '\', \'' . $db->escape($rules) . '\' )' : |
1898 'INSERT INTO '.table_prefix.'acl ( target_type, target_id, rules ) |
2103 'INSERT INTO ' . table_prefix.'acl ( target_type, target_id, rules ) |
1899 VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \''.$db->escape($rules).'\' )'; |
2104 VALUES( '.intval($parms['target_type']).', '.intval($parms['target_id']).', \'' . $db->escape($rules) . '\' )'; |
1900 if(!$db->sql_query($q)) return Array('mode'=>'error','error'=>mysql_error()); |
2105 if(!$db->sql_query($q)) return Array('mode'=>'error','error'=>mysql_error()); |
1901 return Array( |
2106 return Array( |
1902 'mode' => 'success', |
2107 'mode' => 'success', |
1903 'target_type' => $parms['target_type'], |
2108 'target_type' => $parms['target_type'], |
1904 'target_id' => $parms['target_id'], |
2109 'target_id' => $parms['target_id'], |
1975 { |
2181 { |
1976 case 'debug': |
2182 case 'debug': |
1977 echo '<pre>' . htmlspecialchars($response['text']) . '</pre>'; |
2183 echo '<pre>' . htmlspecialchars($response['text']) . '</pre>'; |
1978 break; |
2184 break; |
1979 case 'stage1': |
2185 case 'stage1': |
1980 echo '<h3>Manage page access</h3> |
2186 echo '<h3>' . $lang->get('acl_lbl_welcome_title') . '</h3> |
1981 <p>Please select who should be affected by this access rule.</p>'; |
2187 <p>' . $lang->get('acl_lbl_welcome_body') . '</p>'; |
1982 echo $formstart; |
2188 echo $formstart; |
1983 echo '<p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_GROUP . '" checked="checked" /> A usergroup</label></p> |
2189 echo '<p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_GROUP . '" checked="checked" /> ' . $lang->get('acl_radio_usergroup') . '</label></p> |
1984 <p><select name="data[target_id_grp]">'; |
2190 <p><select name="data[target_id_grp]">'; |
1985 foreach ( $response['groups'] as $group ) |
2191 foreach ( $response['groups'] as $group ) |
1986 { |
2192 { |
1987 echo '<option value="' . $group['id'] . '">' . $group['name'] . '</option>'; |
2193 echo '<option value="' . $group['id'] . '">' . $group['name'] . '</option>'; |
1988 } |
2194 } |
|
2195 |
1989 // page group selector |
2196 // page group selector |
1990 $groupsel = ''; |
2197 $groupsel = ''; |
1991 if ( count($response['page_groups']) > 0 ) |
2198 if ( count($response['page_groups']) > 0 ) |
1992 { |
2199 { |
1993 $groupsel = '<p><label><input type="radio" name="data[scope]" value="page_group" /> A group of pages</label></p> |
2200 $groupsel = '<p><label><input type="radio" name="data[scope]" value="page_group" /> ' . $lang->get('acl_radio_scope_pagegroup') . '</label></p> |
1994 <p><select name="data[pg_id]">'; |
2201 <p><select name="data[pg_id]">'; |
1995 foreach ( $response['page_groups'] as $grp ) |
2202 foreach ( $response['page_groups'] as $grp ) |
1996 { |
2203 { |
1997 $groupsel .= '<option value="' . $grp['id'] . '">' . htmlspecialchars($grp['name']) . '</option>'; |
2204 $groupsel .= '<option value="' . $grp['id'] . '">' . htmlspecialchars($grp['name']) . '</option>'; |
1998 } |
2205 } |
1999 $groupsel .= '</select></p>'; |
2206 $groupsel .= '</select></p>'; |
2000 } |
2207 } |
2001 |
2208 |
2002 echo '</select></p> |
2209 echo '</select></p> |
2003 <p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_USER . '" /> A specific user</label></p> |
2210 <p><label><input type="radio" name="data[target_type]" value="' . ACL_TYPE_USER . '" /> ' . $lang->get('acl_radio_user') . '</label></p> |
2004 <p>' . $template->username_field('data[target_id_user]') . '</p> |
2211 <p>' . $template->username_field('data[target_id_user]') . '</p> |
2005 <p>What should this access rule control?</p> |
2212 <p>' . $lang->get('acl_lbl_scope') . '</p> |
2006 <p><label><input name="data[scope]" value="only_this" type="radio" checked="checked" /> Only this page</p> |
2213 <p><label><input name="data[scope]" value="only_this" type="radio" checked="checked" /> ' . $lang->get('acl_radio_scope_thispage') . '</p> |
2007 ' . $groupsel . ' |
2214 ' . $groupsel . ' |
2008 <p><label><input name="data[scope]" value="entire_site" type="radio" /> The entire site</p> |
2215 <p><label><input name="data[scope]" value="entire_site" type="radio" /> ' . $lang->get('acl_radio_scope_wholesite') . '</p> |
2009 <div style="margin: 0 auto 0 0; text-align: right;"> |
2216 <div style="margin: 0 auto 0 0; text-align: right;"> |
2010 <input name="data[mode]" value="seltarget" type="hidden" /> |
2217 <input name="data[mode]" value="seltarget" type="hidden" /> |
2011 <input type="hidden" name="data[page_id]" value="' . $paths->cpage['urlname_nons'] . '" /> |
2218 <input type="hidden" name="data[page_id]" value="' . $paths->cpage['urlname_nons'] . '" /> |
2012 <input type="hidden" name="data[namespace]" value="' . $paths->namespace . '" /> |
2219 <input type="hidden" name="data[namespace]" value="' . $paths->namespace . '" /> |
2013 <input type="submit" value="Next >" /> |
2220 <input type="submit" value="' . htmlspecialchars($lang->get('etc_wizard_next')) . '" /> |
2014 </div>'; |
2221 </div>'; |
2015 echo $formend; |
2222 echo $formend; |
2016 break; |
2223 break; |
2017 case 'success': |
2224 case 'success': |
2018 echo '<div class="info-box"> |
2225 echo '<div class="info-box"> |
2019 <b>Permissions updated</b><br /> |
2226 <b>' . $lang->get('acl_lbl_save_success_title') . '</b><br /> |
2020 The permissions for ' . $response['target_name'] . ' on this page have been updated successfully.<br /> |
2227 ' . $lang->get('acl_lbl_save_success_body', array( 'target_name' => $response['target_name'] )) . '<br /> |
2021 ' . $formstart . ' |
2228 ' . $formstart . ' |
2022 <input type="hidden" name="data[mode]" value="seltarget" /> |
2229 <input type="hidden" name="data[mode]" value="seltarget" /> |
2023 <input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" /> |
2230 <input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" /> |
2024 <input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2231 <input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2025 <input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2232 <input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2026 <input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" /> |
2233 <input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" /> |
2027 <input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" /> |
2234 <input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" /> |
2028 <input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" /> |
2235 <input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" /> |
2029 <input type="submit" value="Return to ACL editor" /> <input type="submit" name="data[act_go_stage1]" value="Return to user/scope selection" /> |
2236 <input type="submit" value="' . $lang->get('acl_btn_returnto_editor') . '" /> <input type="submit" name="data[act_go_stage1]" value="' . $lang->get('acl_btn_returnto_userscope') . '" /> |
2030 ' . $formend . ' |
2237 ' . $formend . ' |
2031 </div>'; |
2238 </div>'; |
2032 break; |
2239 break; |
2033 case 'delete': |
2240 case 'delete': |
2034 echo '<div class="info-box"> |
2241 echo '<div class="info-box"> |
2035 <b>Rule deleted</b><br /> |
2242 <b>' . $lang->get('acl_lbl_delete_success_title') . '</b><br /> |
2036 The selected access rule has been successfully deleted.<br /> |
2243 ' . $lang->get('acl_lbl_delete_success_body', array('target_name' => $response['target_name'])) . '<br /> |
2037 ' . $formstart . ' |
2244 ' . $formstart . ' |
2038 <input type="hidden" name="data[mode]" value="seltarget" /> |
2245 <input type="hidden" name="data[mode]" value="seltarget" /> |
2039 <input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" /> |
2246 <input type="hidden" name="data[target_type]" value="' . $response['target_type'] . '" /> |
2040 <input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2247 <input type="hidden" name="data[target_id_user]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2041 <input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2248 <input type="hidden" name="data[target_id_grp]" value="' . ( ( intval($response['target_type']) == ACL_TYPE_USER ) ? $response['target_name'] : $response['target_id'] ) .'" /> |
2042 <input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" /> |
2249 <input type="hidden" name="data[scope]" value="' . ( ( $response['page_id'] ) ? 'only_this' : 'entire_site' ) . '" /> |
2043 <input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" /> |
2250 <input type="hidden" name="data[page_id]" value="' . ( ( $response['page_id'] ) ? $response['page_id'] : 'false' ) . '" /> |
2044 <input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" /> |
2251 <input type="hidden" name="data[namespace]" value="' . ( ( $response['namespace'] ) ? $response['namespace'] : 'false' ) . '" /> |
2045 <input type="submit" value="Return to ACL editor" /> <input type="submit" name="data[act_go_stage1]" value="Return to user/scope selection" /> |
2252 <input type="submit" value="' . $lang->get('acl_btn_returnto_editor') . '" /> <input type="submit" name="data[act_go_stage1]" value="' . $lang->get('acl_btn_returnto_userscope') . '" /> |
2046 ' . $formend . ' |
2253 ' . $formend . ' |
2047 </div>'; |
2254 </div>'; |
2048 break; |
2255 break; |
2049 case 'seltarget': |
2256 case 'seltarget': |
2050 if ( $response['type'] == 'edit' ) |
2257 if ( $response['type'] == 'edit' ) |
2051 { |
2258 { |
2052 echo '<h3>Editing permissions</h3>'; |
2259 echo '<h3>' . $lang->get('acl_lbl_editwin_title_edit') . '</h3>'; |
2053 } |
2260 } |
2054 else |
2261 else |
2055 { |
2262 { |
2056 echo '<h3>Create new rule</h3>'; |
2263 echo '<h3>' . $lang->get('acl_lbl_editwin_title_create') . '</h3>'; |
2057 } |
2264 } |
2058 $type = ( $response['target_type'] == ACL_TYPE_GROUP ) ? 'group' : 'user'; |
2265 $type = ( $response['target_type'] == ACL_TYPE_GROUP ) ? $lang->get('acl_target_type_group') : $lang->get('acl_target_type_user'); |
2059 $scope = ( $response['page_id'] ) ? ( $response['namespace'] == '__PageGroup' ? 'this group of pages' : 'this page' ) : 'this entire site'; |
2266 $scope = ( $response['page_id'] ) ? ( $response['namespace'] == '__PageGroup' ? $lang->get('acl_scope_type_pagegroup') : $lang->get('acl_scope_type_thispage') ) : $lang->get('acl_scope_type_wholesite'); |
2060 echo 'This panel allows you to edit what the '.$type.' "'.$response['target_name'].'" can do on <b>'.$scope.'</b>. Unless you set a permission to "Deny", these permissions may be overridden by other rules.'; |
2267 $subs = array( |
|
2268 'target_type' => $type, |
|
2269 'target' => $response['target_name'], |
|
2270 'scope_type' => $scope |
|
2271 ); |
|
2272 echo $lang->get('acl_lbl_editwin_body', $subs); |
2061 echo $formstart; |
2273 echo $formstart; |
2062 $parser = $template->makeParserText( $response['template']['acl_field_begin'] ); |
2274 $parser = $template->makeParserText( $response['template']['acl_field_begin'] ); |
2063 echo $parser->run(); |
2275 echo $parser->run(); |
2064 $parser = $template->makeParserText( $response['template']['acl_field_item'] ); |
2276 $parser = $template->makeParserText( $response['template']['acl_field_item'] ); |
2065 $cls = 'row2'; |
2277 $cls = 'row2'; |