From e909ec901f4043e5e73f629e3fcdd67006834ab8 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 10 Aug 2010 18:50:34 +0000 Subject: [PATCH] Rewrite trackback.php so it looks like it was written sometime in the last 5 years. Use cool things like WebRequest too! --- trackback.php | 102 +++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 39 deletions(-) diff --git a/trackback.php b/trackback.php index 398cc794be..b996ba6aeb 100644 --- a/trackback.php +++ b/trackback.php @@ -7,55 +7,79 @@ require_once( './includes/WebStart.php' ); -function XMLsuccess() { - header( "Content-Type: application/xml; charset=utf-8" ); - echo " +class TrackBack { + + private $r, $url, $title = null; + + private function XMLsuccess() { + header( "Content-Type: application/xml; charset=utf-8" ); + echo << -0 + 0 - "; - exit; -} +XML; + exit; + } -function XMLerror( $err = "Invalid request." ) { - header( "HTTP/1.0 400 Bad Request" ); - header( "Content-Type: application/xml; charset=utf-8" ); - echo " + private function XMLerror( $err = "Invalid request." ) { + header( "HTTP/1.0 400 Bad Request" ); + header( "Content-Type: application/xml; charset=utf-8" ); + echo << -1 -Invalid request: $err + 1 + Invalid request: $err -"; - exit; -} +XML; + exit; + } -if( !$wgUseTrackbacks ) - XMLerror("Trackbacks are disabled."); + public function __construct() { + global $wgUseTrackbacks, $wgRequest; -if( !isset( $_POST['url'] ) - || !isset( $_REQUEST['article'] ) ) - XMLerror("Required field not specified"); + if( !$wgUseTrackbacks && false ) + $this->XMLerror( "Trackbacks are disabled" ); -$dbw = wfGetDB( DB_MASTER ); + $this->r = $wgRequest; -$tbtitle = strval( @$_POST['title'] ); -$tbex = strval( @$_POST['excerpt'] ); -$tburl = strval( $_POST['url'] ); -$tbname = strval( @$_POST['blog_name'] ); -$tbarticle = strval( $_REQUEST['article'] ); + if( !$this->r->wasPosted() ) { + $this->XMLerror( "Must be posted" ); + } -$title = Title::newFromText($tbarticle); -if( !$title || !$title->exists() ) - XMLerror( "Specified article does not exist." ); + $this->url = $wgRequest->getText( 'url' ); + $article = $wgRequest->getText( 'article' ); -$dbw->insert('trackbacks', array( - 'tb_page' => $title->getArticleID(), - 'tb_title' => $tbtitle, - 'tb_url' => $tburl, - 'tb_ex' => $tbex, - 'tb_name' => $tbname -)); + if( !$this->url || !$article ) { + $this->XMLerror( "Required field not specified" ); + } -$dbw->commit(); + $this->title = Title::newFromText( $article ); + if( !$this->title || !$this->title->exists() ) { + $this->XMLerror( "Specified article does not exist." ); + } + } + + public function write() { + $dbw = wfGetDB( DB_MASTER ); + + $tbtitle = $this->r->getText( 'title' ); + $tbex = $this->r->getText( 'excerpt' ); + $tbname = $this->r->getText( 'blog_name' ); + + $dbw->insert('trackbacks', array( + 'tb_page' => $this->title->getArticleID(), + 'tb_title' => $tbtitle, + 'tb_url' => $this->url, + 'tb_ex' => $tbex, + 'tb_name' => $tbname + )); + + $dbw->commit(); + + $this->XMLsuccess(); + } +} -XMLsuccess(); +$tb = new TrackBack(); +$tb->write(); -- 2.20.1