Follow up to r99307, with some inline comment documentation on why these !important...
[mediawiki.git] / trackback.php
blob0e2036a92c25063842f47e4ad178c0a6bb0dee31
1 <?php
2 /**
3 * Provide functions to handle article trackbacks.
4 * @file
5 * @ingroup SpecialPage
6 */
8 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
9 require ( 'phase3/includes/WebStart.php' );
10 } else {
11 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
14 class TrackBack {
16 private $r, $url, $title = null;
18 private function XMLsuccess() {
19 header( "Content-Type: application/xml; charset=utf-8" );
20 echo <<<XML
21 <?xml version="1.0" encoding="utf-8"?>
22 <response>
23 <error>0</error>
24 </response>
25 XML;
26 exit;
29 private function XMLerror( $err = "Invalid request." ) {
30 header( "HTTP/1.0 400 Bad Request" );
31 header( "Content-Type: application/xml; charset=utf-8" );
32 echo <<<XML
33 <?xml version="1.0" encoding="utf-8"?>
34 <response>
35 <error>1</error>
36 <message>Invalid request: $err</message>
37 </response>
38 XML;
39 exit;
42 public function __construct() {
43 global $wgUseTrackbacks, $wgRequest;
45 if( !$wgUseTrackbacks )
46 $this->XMLerror( "Trackbacks are disabled" );
48 $this->r = $wgRequest;
50 if( !$this->r->wasPosted() ) {
51 $this->XMLerror( "Must be posted" );
54 $this->url = $wgRequest->getText( 'url' );
55 $article = $wgRequest->getText( 'article' );
57 if( !$this->url || !$article ) {
58 $this->XMLerror( "Required field not specified" );
61 $this->title = Title::newFromText( $article );
62 if( !$this->title || !$this->title->exists() ) {
63 $this->XMLerror( "Specified article does not exist." );
67 public function write() {
68 $dbw = wfGetDB( DB_MASTER );
70 $tbtitle = $this->r->getText( 'title' );
71 $tbex = $this->r->getText( 'excerpt' );
72 $tbname = $this->r->getText( 'blog_name' );
74 $dbw->insert('trackbacks', array(
75 'tb_page' => $this->title->getArticleID(),
76 'tb_title' => $tbtitle,
77 'tb_url' => $this->url,
78 'tb_ex' => $tbex,
79 'tb_name' => $tbname
80 ));
82 $dbw->commit();
84 $this->XMLsuccess();
88 $tb = new TrackBack();
89 $tb->write();