MediaWiki/Special/LogPost

From HTYP, the free directory anyone can edit

Jump to: navigation, search

[edit] Overview

Special:LogPost is a MediaWiki extension which displays and logs any data sent to it via HTTP POST. It was written primarily for capturing sample data from PayPal Instant Payment Notification, but could also be useful in any other situation where POSTed data needs to be checked.

[edit] Code

 
/*
 NAME: SpecialMakePage
 PURPOSE: Special page for creating a new page from a form
	Other extensions can do this, but they don't make it at all easy
	to base the title on variables which are substituted from fields on the form.
 AUTHOR: Woozle Staddon
 VERSION:
	2008-12-31 0.0 (Wzl) Writing started - using SpecialMakePage as a skeleton
	2009-01-02 1.0 (Wzl) It does what I need it to do; no need to start with small version numbers...
*/
$wgSpecialPages['LogPost'] = 'SpecialLogPost'; # Let MediaWiki know about your new special page.
$wgExtensionCredits['other'][] = array(
        'name' => 'Special:LogPost',
        'description' => 'special page for logging POSTed form data',
        'author' => 'Woozle Staddon',
	'version' => '1.0 2009-01-02'
);
 
 
function wfSpecialLogPost() {
// This registers the page's class. I think.
	global $wgRequest;
 
	$app = new SpecialLogPost($wgRequest);
 
	$app->doLog();
}
 
require_once( $wgScriptPath.'includes/SpecialPage.php' );
require_once( $wgScriptPath.'includes/EditPage.php' );
 
class SpecialLogPost extends SpecialPage {
  public function __construct() {
	global $wgMessageCache;
 
	parent::__construct( 'LogPost' );
	$this->includable( false );
        $wgMessageCache->addMessage('logpost', 'Log POSTed data');
  }
  public function doLog() {
	global $wgRequest, $wgOut;
 
	$this->setHeaders();
 
	$out = date('Y-m-d H:i:s')."\n";
	$out .= $this->EnvLine('REQUEST_METHOD');
	$out .= $this->EnvLine('HTTP_USER_AGENT');
	$out .= $this->EnvLine('REMOTE_ADDR');
	$out .= "\tPOSTed form data:\n";
// display results on screen
	foreach ($_POST AS $key => $value) {
		$wgOut->AddWikiText("* '''$key''': $value");
		$out .= "\t\t$key\t$value\n";
	}
// write more complete data to log file:
	$fh = fopen('SpecialLogPost.log', 'a');
	$qb = fwrite($fh, $out);
	fclose($fh);
	$wgOut->AddWikiText($qb.' bytes logged');
  }
  private function EnvLine($iName) {
	return "\t".$iName."\t".$_ENV[$iName]."\n";
  }
}
 
Personal tools