r70057 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70056‎ | r70057 | r70058 >
Date:23:00, 27 July 2010
Author:nimishg
Status:ok
Tags:
Comment:
authentication to prevent tons of spurious data
Modified paths:
  • /trunk/extensions/SimpleSurvey/SpecialSimpleSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SimpleSurvey/SpecialSimpleSurvey.php
@@ -16,9 +16,28 @@
1717 private $originLink = '';
1818 private $originLinkUrl = '';
1919 private $originFullUrl = '';
 20+ private $tokenToCheck = '';
2021
2122 /* Functions */
2223
 24+ /**
 25+ * Quick token matching wrapper for form processing
 26+ */
 27+ public function checkToken() {
 28+ global $wgRequest;
 29+ $this->tokenToCheck = $_SESSION['wsSimpleSurveyToken'];
 30+ if($this->tokenToCheck != "" &&
 31+ ( $wgRequest->getVal( 'token' ) == $this->tokenToCheck ) ){
 32+ return true;
 33+ }
 34+ else return false;
 35+ }
 36+
 37+ public function setToken(){
 38+ $this->tokenToCheck = wfGenerateToken( array( $this, time() ) );
 39+ $_SESSION['wsSimpleSurveyToken'] = $this->tokenToCheck;
 40+ }
 41+
2342 public function __construct() {
2443 parent::__construct( 'SimpleSurvey' );
2544 wfLoadExtensionMessages( 'SimpleSurvey' );
@@ -33,7 +52,7 @@
3453 $surveyName = $wgRequest->getVal("survey");
3554
3655 if($wgRequest->wasPosted()){
37 - if($surveyName && in_array($surveyName,$wgValidSurveys )){
 56+ if($surveyName && in_array($surveyName,$wgValidSurveys ) && $this->checkToken() ){
3857 SimpleSurvey::save( $surveyName, $wgPrefSwitchSurveys[$surveyName] );
3958 $wgOut->addHtml("<b>" . wfMsg( 'simple-survey-confirm' ). "</b>");
4059 }
@@ -45,6 +64,7 @@
4665 return;
4766 }
4867
 68+ $this->setToken();
4969 // Get the origin from the request
5070 $par = $wgRequest->getVal( 'from', $par );
5171 $this->originTitle = Title::newFromText( $par );
@@ -104,6 +124,7 @@
105125 )
106126 );
107127 $html .= Xml::hidden( 'survey', $mode );
 128+ $html .= Xml::hidden( 'token', $this->tokenToCheck);
108129 // Render a survey
109130 $html .= SimpleSurvey::render(
110131 $wgPrefSwitchSurveys[$mode]['questions']

Status & tagging log