Extension:Donation gets email address

From MediaWiki.org

Jump to: navigation, search
Wikimedia-logo-meta.png

This page was recently moved from MetaWiki.
It probably requires cleanup – please feel free to help out. In addition, some links on the page may be red; respective pages might be found at Meta. Remove this template once cleanup is complete.

I wanted to offer YourName@MyWiki.org email addresses to folks if they wanted them when they donated to my wiki. I created this extension for that reason. It is a bit messy in the coding as I'm VERY new to PHP but it works.

To use this extension, you need to create a new table called "mw_email" to your database. It will need at least a field named "mail_name" field to store the "yourName" part of yourName@MyWiki.org

I found that also, the cache needs to be disabled so that the form can be validated. I'm using MediaWiki 1.5.8 and none of the instructions on disabling the page cache worked so edited [page] and added


Note I am running version 1.5.8 and could not get any of the above to work. You can see the following code functioning properly [1]. I had to use the following code in the second function of the extension (not the "setHook" function):

 global $wgTitle;
 	$dbw =& wfGetDB( DB_MASTER );
 	$dbw->update( 'page', array( 'page_touched' => $dbw->timestamp( time() + 120 ) ), 
     	array( 
        	'page_namespace' => $wgTitle->getNamespace(), 
        	'page_title' => $wgTitle->getDBkey() 
    	), 'name of your Extension as defined in $wgExtensionFunctions[] =' 
 	);
  }

You can view a working version of this extension on my http://wikimoto.org site here.

The code for the extension is implemented in the [usual way]

 <?php

		#################################################################################################
		#################################################################################################
		#####	 																					#####
		##### THIS EXTENSION WAS CREATED 05/14/06 BY ERIK MERMAGEN FOR HIS http://WikiMoto.org WEBSITE		#####
		#####																						#####
		##### 			THIS PROGRAM CREATES AN EXTENSION FOR MEDIAWIKI BASED SITES 				#####
		##### IT CREATES A VALIDATING FORM TO SIGN UP FOR AN EMAIL NAME BASED ON YOUR WIKI DOMAIN 	#####
		#####	 																					#####
		##### 									Example Code	 									#####
		#####							<emaildonation></emaildonation>								#####
		#####																						#####
		#################################################################################################
		#################################################################################################

$wgExtensionFunctions[] = "wfEmailDonationExtension";


/* DO NOT EDIT BEYOND THIS LINE */

function wfEmailDonationExtension() {
    global $wgParser;  

    $wgParser->setHook( "emaildonation", "createmwEmailDonation" );
}

# The callback function for converting the input text to HTML output
function createmwEmailDonation( $input, $argv ){

	########## CHANGE THIS DEFENITION ############################
	$nameOfYourSite = 'WikiMoto.org';
	global $wgTitle;
	$dbw =& wfGetDB( DB_MASTER );
	$dbw->update( 'page', array( 'page_touched' => $dbw->timestamp( time() + 120 ) ), 
    	array( 
        	'page_namespace' => $wgTitle->getNamespace(), 
        	'page_title' => $wgTitle->getDBkey() 
    	), 'wfEmailDonationExtension' 
	); 

 
$beginningTable = '<table border="0" align="center" cellpadding="0" cellspacing="0" class="mailbox">
  <tr>
    <td width="60%"><strong>We have a wonderful way for you to show your  support for '.$nameOfYourSite.'</strong><br />
For a donation of $10 or more, you can have "yourName@'.$nameOfYourSite.'" as an email address.<br />
The server is set up to simply forward your '.$nameOfYourSite.' email to your existing email address for a year. 
      <p>Simply enter the name you desire in the field below to check it for availability.<br />
      </p>';
$emptyEntry = '<p><span class="alert">Sorry. Neither field below may be left empty. </span></p>';
$noMatchEntry = '<p><span class="alert">Sorry. Both entries below must match. </span></p>';
$entryExists = '<p><span class="alert">Sorry. That name has been taken. </span></p>';
	

$defaultDesired = '';
$defaultForward = '';

	
$submit = '<input name="theButton" type="submit" value="Is This Name Already Taken?" /><input type="hidden" name="_submit_emailtest2" value="1">
	</form>';
	
$endTable = '    </td>
	 <td valign="top"><center>Or You can simply donate what you like to help us out.<br />'.
	 
		#################################################################################################
		#####	 																					#####
		##### 			CHANGE THE CODE IN HERE TO INCLUDE ¡YOUR PAYPAL BUTTON VARIABLES!			#####
		##### 							OR I WILL GET ALL YOUR DONATIONS							#####
		#####																						#####
		#################################################################################################
	
	'<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="donations@'.$nameOfYourSite.'">
<input type="hidden" name="item_name" value="Help '.$nameOfYourSite.' keep the servers up and running. Thank you kindly.">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="bn" value="PP-DonationsBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form></center>
	 </td>
  </tr>
</table>';

########### THIS IS THE INITIAL QUERY AND SHIT - THE CHECKING FOR EXISTING NAMES ETC ##########################


		#################################################################################################
		#####	 																					#####
		##### 			YOU WILL NEED TO CREATE A NEW DATABASE TABLE TO STORE STUFF IN				#####
		##### 					TO USE THIS CODE, IT NEEDS TO BE NAMED "mw_email"					#####
		##### 			and contain a field named "mail_name" where you will store the				#####
		##### 						"yourName" part of yourName@yourSite.org						#####
		#####																						#####
		#################################################################################################
		
$query1='SELECT mail_name FROM mw_email';  //what are we looking for
$result = mysql_query($query1);  // the query we call later in a "while" statement


############## if emailtest AND forwardEmail BOTH have a missing field ########################################
if ((isset($_POST['_submit_emailtest2'])) && ((htmlentities(strtolower($_POST['emailTest'])) == "") | (htmlentities(strtolower($_POST['emailTest2'])) == ""))&&((htmlentities(strtolower($_POST['forwardEmail1'])) == "") | (htmlentities(strtolower($_POST['forwardEmail2'])) == ""))){
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$emptyEntry.$checkForName.$emptyEntry.$forwardTo.$submit.$endTable; 

############## if emailtest has a missing field AND forwardEmail fields don't match ############################
}elseif ((isset($_POST['_submit_emailtest2'])) && ((htmlentities(strtolower($_POST['emailTest'])) == "") | (htmlentities(strtolower($_POST['emailTest2'])) == ""))&&(!(htmlentities($_POST['forwardEmail1'])==(htmlentities($_POST['forwardEmail2']))))){
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = '';
	$mailVar2 = '';
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$emptyEntry.$checkForName.$noMatchEntry.$forwardTo.$submit.$endTable;
	
############## if emailtest fields don't match AND forwardEmail has a missing field ############################
}elseif ((isset($_POST['_submit_emailtest2'])) && ((htmlentities(strtolower($_POST['forwardEmail1'])) == "") | (htmlentities(strtolower($_POST['forwardEmail2'])) == ""))&&(!(htmlentities($_POST['emailTest'])==(htmlentities($_POST['emailTest2']))))){
	$nameVar1 = '';
	$nameVar2 = '';
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$noMatchEntry.$checkForName.$emptyEntry.$forwardTo.$submit.$endTable;
	
############## if emailtest fields don't match AND if forwardEmail fields don't match ##########################
}elseif ((!(htmlentities($_POST['forwardEmail1'])==(htmlentities($_POST['forwardEmail2']))))&&(!(htmlentities($_POST['emailTest'])==(htmlentities($_POST['emailTest2']))))){
	$nameVar1 = '';
	$nameVar2 = '';
	$mailVar1 = '';
	$mailVar2 = '';
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$noMatchEntry.$checkForName.$noMatchEntry.$forwardTo.$submit.$endTable;

############## if emailTest has and empty field ################################################################
}elseif ((isset($_POST['_submit_emailtest2'])) && ((htmlentities(strtolower($_POST['emailTest'])) == "") | (htmlentities(strtolower($_POST['emailTest2'])) == ""))){
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$emptyEntry.$checkForName.$forwardTo.$submit.$endTable; 

############## if forwadEmail has and empty field ##############################################################
}elseif ((isset($_POST['_submit_emailtest2'])) && ((htmlentities(strtolower($_POST['forwardEmail1'])) == "") | (htmlentities(strtolower($_POST['forwardEmail2'])) == ""))){
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$checkForName.$emptyEntry.$forwardTo.$submit.$endTable;

############## if emailTest fields don't match #################################################################
}elseif (!(htmlentities($_POST['emailTest'])==(htmlentities($_POST['emailTest2'])))){// if the 2 submitted values are different say so
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$noMatchEntry.$checkForName.$forwardTo.$submit.$endTable; 
	
############## if forwardEmail fields don't match###############################################################
}elseif (!(htmlentities($_POST['forwardEmail1'])==(htmlentities($_POST['forwardEmail2'])))){// if the 2 submitted values are different say so
	$nameVar1 = $_POST['emailTest'];
	$nameVar2 = $_POST['emailTest2'];
	$mailVar1 = '';
	$mailVar2 = '';
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$checkForName.$noMatchEntry.$forwardTo.$input.$endTable;
	
}else{// if they are same do this
	
##  get every frigging record in mail_name but stop looking if you find one that matches what you want ##
	while(($row = mysql_fetch_array($result, MYSQL_ASSOC))&&(!($desiredEmail == htmlentities(strtolower($_POST['emailTest']))))){

## keep changing value of variable and testing it to see if it matches what we're looking for
		$desiredEmail = "{$row['mail_name']}";
		if ($desiredEmail == htmlentities(strtolower($_POST['emailTest']))){
## if the results of the query match what you want then you can't have that name
			$found = "sorry, that one already exists";
		}
	}
	if ($found == "sorry, that one already exists"){
	$nameVar1 = '';
	$nameVar2 = '';
	$mailVar1 = $_POST['forwardEmail1'];
	$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$entryExists.$checkForName.$forwardTo.$submit.$endTable; 
	
## if record not found and button was pressed (not just page load) and form filled correctly, then say it's available
		}else if (isset($_POST['_submit_emailtest2'])){
		$nameVar1 = $_POST['emailTest'];
		$nameVar2 = $_POST['emailTest2'];
		$mailVar1 = $_POST['forwardEmail1'];
		$mailVar2 = $_POST['forwardEmail2'];
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
		$output = $beginningTable.'<table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFAAAC" class="greenalert">
        <tr>
          <td>Congratulations!<br /><span class="importantMail">'.$nameVar1.'@'.$nameOfYourSite.'</span> is available!<br />
		Simply click on the "DONATE" button below and any email sent to <span class="importantMail">'.$nameVar1.'@'.$nameOfYourSite.'</span> will go straight to your current <span class="importantMail">'.$_POST['forwardEmail2'].'</span> email address! <br /><br />'.
		
	
		#################################################################################################
		#####	 																					#####
		##### 			CHANGE THE CODE IN HERE TO INCLUDE ¡YOUR PAYPAL BUTTON VARIABLES!			#####
		##### 							OR I WILL GET ALL YOUR DONATIONS							#####
		#####																						#####
		#################################################################################################
		
		'<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
		<input type="hidden" name="cmd" value="_xclick">
		<input type="hidden" name="business" value="donations@'.$nameOfYourSite.'">
		<input type="hidden" name="item_name" value="'.$nameOfYourSite.' will forward all email sent to '.$nameVar1.'@'.$nameOfYourSite.' to your current '.$mailVar1.' email address. Thank you very much for your support.  ">
		<input type="hidden" name="item_number" value="1">
		<input type="hidden" name="amount" value="">
		<input type="hidden" name="no_note" value="0">
		<input type="hidden" name="currency_code" value="USD">
		<input type="hidden" name="tax" value="0">
		<input type="hidden" name="bn" value="PP-DonationsBF">
		<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
		<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
		  You will be taken to PayPal, where you can choose your donation amount.
		
		</td>
			</tr>
    		  </table></form><br />'.$endTable;
	}
}
####### THIS IS THE INITIAL CHECK FOR NAME FORM WHEN YOU PRESS THE BUTTON IT SETS _submit_emailtest2 TO "2"
if (!($_POST['_submit_emailtest2'])==2){
$checkForName = '<form name="queryForm" method="POST" action=" '. $HTTP_SERVER_VARS['PHP_SELF'] .'">
	<p><input type="text" name="emailTest" style="text-align:right" value="'.$nameVar1.'" />@'.$nameOfYourSite.'<br />
	<input type="text" name="emailTest2" style="text-align:right" value="'.$nameVar2.'" />@'.$nameOfYourSite.'<br /></p>';
	
$forwardTo = '<p><input name="forwardEmail1" type="text" value="'.$mailVar1.'" />forward email to this, my current address <br />
	<input type="text" name="forwardEmail2" value="'.$mailVar2.'" />confirm email address </p>';
	$output = $beginningTable.$checkForName.$forwardTo.$submit.$endTable; 
} 




return $output;
}


?>
 
<style type="text/css">
<!--
.alert {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #990000;
	background-color: #ffaaaa;
	padding: 5px 10px;
	border: 1px solid #666666;
}
.greenalert {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #003300;
	background-color: #aeffae;
	padding: 5px 10px;
	border: 1px solid #666666;
}
.mailbox {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
	color: #000099;
	background-color: #e9e9e9;
	padding: 5px 10px;
	border: 1px solid #666666;
	width: 95%;
}
.importantMail{
	color: #000099;
}
-->
</style>

enjoy