X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=trackback.php;h=b996ba6aeb0d0fb780f07a86b735809030793759;hb=af3c4d8bf6234ceb3e25012e629de49769a2d384;hp=398503098c226e0957ada5ec04fc7b4b7aa7baa1;hpb=dcd152a83fd256a88fba7ae0a01587dfd1783889;p=lhc%2Fweb%2Fwiklou.git diff --git a/trackback.php b/trackback.php index 398503098c..b996ba6aeb 100644 --- a/trackback.php +++ b/trackback.php @@ -1,65 +1,85 @@ +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; + } + + public function __construct() { + global $wgUseTrackbacks, $wgRequest; + + if( !$wgUseTrackbacks && false ) + $this->XMLerror( "Trackbacks are disabled" ); + + $this->r = $wgRequest; -if (!$wgUseTrackbacks) - XMLerror("Trackbacks are disabled."); + if( !$this->r->wasPosted() ) { + $this->XMLerror( "Must be posted" ); + } -if ( !isset($_POST['url']) - || !isset($_POST['blog_name']) - || !isset($_REQUEST['article'])) - XMLerror("Required field not specified"); + $this->url = $wgRequest->getText( 'url' ); + $article = $wgRequest->getText( 'article' ); -$dbw = wfGetDB(DB_MASTER); + if( !$this->url || !$article ) { + $this->XMLerror( "Required field not specified" ); + } -$tbtitle = $_POST['title']; -$tbex = $_POST['excerpt']; -$tburl = $_POST['url']; -$tbname = $_POST['blog_name']; -$tbarticle = $_REQUEST['article']; + $this->title = Title::newFromText( $article ); + if( !$this->title || !$this->title->exists() ) { + $this->XMLerror( "Specified article does not exist." ); + } + } -$title = Title::newFromText($tbarticle); -if (!isset($title) || !$title->exists()) - XMLerror("Specified article does not exist."); + public function write() { + $dbw = wfGetDB( DB_MASTER ); -$dbw->insert('trackbacks', array( - 'tb_page' => $title->getArticleID(), - 'tb_title' => $tbtitle, - 'tb_url' => $tburl, - 'tb_ex' => $tbex, - 'tb_name' => $tbname -)); -$dbw->commit(); + $tbtitle = $this->r->getText( 'title' ); + $tbex = $this->r->getText( 'excerpt' ); + $tbname = $this->r->getText( 'blog_name' ); -XMLsuccess(); + $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(); + } +} -?> +$tb = new TrackBack(); +$tb->write();