trackback.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Provide functions to handle article trackbacks.
  4. * @file
  5. * @ingroup SpecialPage
  6. */
  7. require_once( './includes/WebStart.php' );
  8. function XMLsuccess() {
  9. header( "Content-Type: application/xml; charset=utf-8" );
  10. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
  11. <response>
  12. <error>0</error>
  13. </response>
  14. ";
  15. exit;
  16. }
  17. function XMLerror( $err = "Invalid request." ) {
  18. header( "HTTP/1.0 400 Bad Request" );
  19. header( "Content-Type: application/xml; charset=utf-8" );
  20. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
  21. <response>
  22. <error>1</error>
  23. <message>Invalid request: $err</message>
  24. </response>
  25. ";
  26. exit;
  27. }
  28. if( !$wgUseTrackbacks )
  29. XMLerror("Trackbacks are disabled.");
  30. if( !isset( $_POST['url'] )
  31. || !isset( $_REQUEST['article'] ) )
  32. XMLerror("Required field not specified");
  33. $dbw = wfGetDB( DB_MASTER );
  34. $tbtitle = strval( @$_POST['title'] );
  35. $tbex = strval( @$_POST['excerpt'] );
  36. $tburl = strval( $_POST['url'] );
  37. $tbname = strval( @$_POST['blog_name'] );
  38. $tbarticle = strval( $_REQUEST['article'] );
  39. $title = Title::newFromText($tbarticle);
  40. if( !$title || !$title->exists() )
  41. XMLerror( "Specified article does not exist." );
  42. $dbw->insert('trackbacks', array(
  43. 'tb_page' => $title->getArticleID(),
  44. 'tb_title' => $tbtitle,
  45. 'tb_url' => $tburl,
  46. 'tb_ex' => $tbex,
  47. 'tb_name' => $tbname
  48. ));
  49. $dbw->commit();
  50. XMLsuccess();