Extension:CorporateContact
From MediaWiki.org
|
CorporateContact Release status: stable |
|
|---|---|
| Implementation | Special page |
| Description | Configurable contact page |
| Author(s) | Cédric Chantepie (Cchantep Talk) |
| Version | 0.1-SNAPSHOT |
| MediaWiki | 1.8.x - 1.12.0 |
| Download | Download page |
| Example | http://www.nozicaa.com/en/page.content/Special:Contact |
Contents |
[edit] What can this extension do?
Provides a special page Special:Contact so that people can contact you without you to expose some email (no spam). Form allow to gather some basic information about people like name, email, company or organisation ...
This extension is highly configurable so that you can add custom wiki texts before and/or after contact form (according parameters), display custom suject (with i18n used). You can also make a custom mail content according values (according subject, according user type ...) in form providing your own mail rendering function. It is possible to provide a custom dispatch function so that you can choose according form values where mail should be sent.
[edit] Usage
[edit] Installation
To install this extensions, put files given in code section in your MediaWiki extensions folder and then add the following to LocalSettings.php:
# Include yours custom functions require_once("$IP/extensions/ContactPage/MyContact.php"); # Include Special:Contact setup (required) require_once("$IP/extensions/ContactPage/ContactPage.setup.php");
[edit] Runtime (HTTP) parameters
Special:Contact page can be called with some parameters, separated by / character :
- before:value Value of before parameter is used to specify custom text displayed before contact form. It should be a short value, such as identifier or key. If $wikiGetterFunc is given in configuration, this value is passed to this function to obtain final wiki text displayed before contact form, otherwise value is directly displayed.
- after:value Value of after parameter is used to specify custom text displayed before contact form. It should be a short value, such as identifier or key. If $wikiGetterFunc is given in configuration, this value is passed to this function to obtain final wiki text displayed after contact form, otherwise value is directly displayed.
- subject:value Value of subject is used to specify which subject should be selected when page is loaded. Should match a value of $subjects array in configuration (if subject:foo, foo should be found on $subjects, and so it will be selected when page is loaded).
Usage samples :
- /Special:Contact/after:aaa/subject:foo/before:bbb
- /Special:Contact/subject:foo
- /Special:Contact/subject:foo/after:bbb
[edit] Configuration parameters
Configuration is mainly done in ContactSettings.php. They are not global variables so you should not have to prevent conflict with other variable in your system.
- $subjects array of subject identifier, used as value in form for the subject popup menu. You have to localized it by adding in ContactPage.i18n.YOUR_LANG.php a key-value pair in messages array. Message key should match "contactpage-subject-$subject" (for "other" in $subjects array parameter you should have a "contactpage-subject-other" in i18n messages array).
- $dispatcherFunc (required) name of function (provided in by your own) used to know where to send mail (see MyContact.php).
- $subjectFunc (optional) name of custom function to determine subject of mail to be sent, given form values. If not provided localized value of wpSubject field is used (see $subjects).
- $renderFunc (optional) name of custom function to render content of mail to be sent, given form values. If not provided value of wpContent textarea in form will only be sent as mail content.
- $validateFunc (optional) name of custom function to perform custom validation upon form values. If not provided no extra validation is performed.
- $defaultSenderName (required) name used as sender one when he does not provide it in form.
- $defaultSenderEmail (required) email address used as sender one when he does not provide it in form.
- $wikiGetterFunc (optional) name of custom function used to get wiki text for before and/or after runtime parameters. If not provided parameter values are used directly.
- $formTabIndexes (optional) associative array (dictionary) used to specify tab index for form field. Very useful if you change display position of form field with CSS, so with ajusting tab indexes user can navigation through form field in a coherent way given what is displayed (if in your form subject is after first name you should add entries 'wpFirstName' => x and 'wpSubject' => x+1 in this array parameter).
[edit] Code
File ContactPage.setup.php : extension setup (should not be modified)
<?php if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); die( 1 ); } $wgExtensionCredits['specialpage'][] = array( 'name' => 'Contact', 'author' => 'Cedric Chantepie', 'url' => 'http://www.mediawiki.org/wiki/Extension:CorporateContact' 'description' => 'contact form for visitors', ); $wgAutoloadClasses['SpecialContact'] = dirname( __FILE__ ) . '/ContactPage.body.php'; $wgSpecialPages['Contact'] = 'SpecialContact'; $wgHooks['LoadAllMessages'][] = 'loadContactPageI18n'; /** * load the ContactPage internationalization file */ function loadContactPageI18n() { global $wgLang, $wgMessageCache; static $initialized = false; if ( $initialized ) return true; $messages= array(); $f= dirname( __FILE__ ) . '/ContactPage.i18n.' . $wgLang->getCode() . '.php'; if ( file_exists( $f ) ) include( $f ); $initialized = true; $wgMessageCache->addMessages( $messages ); return true; }
File ContactPage.body.php : extension implementation (should not be modified)
<?php /** * Speclial:Contact, a contact form for visitors. * Based on SpecialEmailUser.php * * @addtogroup SpecialPage * @copyright from the autoloader require_once("$IP/includes/UserMailer.php"); /** * */ class SpecialContact extends SpecialPage { /** * Constructor */ function __construct() { global $wgOut; SpecialPage::SpecialPage( 'Contact', '', true ); #inject messages loadContactPageI18n(); } /** * Main execution function * @param $par Parameters passed to the page */ function execute( $par ) { global $wgUser, $wgOut, $wgRequest; $fname = "SpecialContact::execute"; $action = $wgRequest->getVal( 'action' ); $f = new EmailContactForm($par); if ("success" == $action) { wfDebug( "$fname: success.\n" ); $f->showSuccess(); } else if ("submit" == $action && $wgRequest->wasPosted()) { $token = $wgRequest->getVal( 'wpEditToken' ); if ($wgUser->isAnon()) { // Anonymous users may not have a session // open. Check for suffix anyway. $tokenOk = ( EDIT_TOKEN_SUFFIX == $token ); } else { $tokenOk = $wgUser->matchEditToken( $token ); } if ( !$tokenOk ) { wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" ); $wgOut->addWikiText( wfMsg( 'sessionfailure' ) ); $f->showForm(); } else if ( !$f->passCaptcha() ) { wfDebug( "$fname: captcha failed" ); $wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this! $f->showForm(); } else { wfDebug( "$fname: submit\n" ); $f->doSubmit(); } } else { wfDebug( "$fname: form\n" ); $f->showForm(); } } } /** * @todo document * @addtogroup SpecialPage */ class EmailContactForm { var $queryString; var $subject; var $gender; var $company; var $firstName; var $lastName; var $address; var $postalCode; var $city; var $country; var $phone; var $fax; var $email; var $content; var $subjects; var $dispatcher; var $renderer; var $subjectRenderer; var $customValidation; var $errors; var $messages; // settings var $defaultSenderEmail; var $defaultSenderName; /** * Uninterpreted identifier for wiki text before form */ var $before; /** * Uninterpreted identifier for wiki text after form */ var $after; /** * Rendered wiki text before form */ var $wikiTextBefore; /** * Rendered wiki text before form */ var $wikiTextAfter; var $tabindexes; /** */ function EmailContactForm($aQueryString) { global $wgRequest, $wgUser; global $wgCaptcha, $wgCaptchaTriggers; $this->queryString = $aQueryString; $this->subject = $wgRequest->getText( 'wpSubject' ); $this->gender = $wgRequest->getText( 'wpGender' ); $this->company = $wgRequest->getText( 'wpCompany' ); $this->firstName = $wgRequest->getText( 'wpFirstName' ); $this->lastName = $wgRequest->getText( 'wpLastName' ); $this->address = $wgRequest->getText( 'wpAddress' ); $this->postalCode = $wgRequest->getText( 'wpPostalCode' ); $this->city = $wgRequest->getText( 'wpCity' ); $this->country = $wgRequest->getText( 'wpCountry' ); $this->phone = $wgRequest->getText( 'wpPhone' ); $this->fax = $wgRequest->getText( 'wpFax' ); $this->email = $wgRequest->getText( 'wpEmail' ); $this->content = $wgRequest->getText( 'wpContent' ); $this->errors = array(); $this->messages = array(); $this->before = $wgRequest->getText( 'wpBefore' ); $this->after = $wgRequest->getText( 'wpAfter' ); $this->wikiTextBefore = NULL; $this->wikiTextAfter = NULL; $pos1 = strpos($this->queryString, "subject:"); if ($pos1 !== false) { $pos1 += 8; $pos2 = strpos($this->queryString, "/", $pos1); if ($pos2 === false) { $this->subject = substr($this->queryString, $pos1); } else { $this->subject = substr($this->queryString, $pos1, $pos2-$pos1); } } // Wiki text before $pos1 = strpos($this->queryString, "before:"); if ($pos1 !== false) { $pos1 += 7; $pos2 = strpos($this->queryString, "/", $pos1); if ($pos2 === false) { $this->wikiTextBefore = substr($this->queryString, $pos1); } else { $this->wikiTextBefore = substr($this->queryString, $pos1, $pos2-$pos1); } $this->before = $this->wikiTextBefore; } else { $this->wikiTextBefore = $this->before; } // Get identifier for wiki text // to be put after contact form // (should not be directly wiki text value, // just identified) $pos1 = strpos($this->queryString, "after:"); if ($pos1 !== false) { $pos1 += 6; $pos2 = strpos($this->queryString, "/", $pos1); if ($pos2 === false) { $this->wikiTextAfter = substr($this->queryString, $pos1); } else { $this->wikiTextAfter = substr($this->queryString, $pos1, $pos2-$pos1); } $this->after = $this->wikiTextAfter; } else { $this->wikiTextAfter = $this->after; } //prepare captcha if applicable if ( $wgCaptcha && @$wgCaptchaTriggers['contactpage'] ) { $wgCaptcha->trigger = 'contactpage'; $wgCaptcha->action = 'contact'; } $f= dirname( __FILE__ ) . '/ContactSettings.php'; if ( file_exists( $f ) ) include( $f ); $this->subjects = $subjects; $this->dispatcher = $dispatcherFunc; $this->defaultSenderName = $defaultSenderName; $this->defaultSenderEmail = $defaultSenderEmail; // Optional functions $this->renderer = NULL; $this->subjectRenderer = NULL; $this->customValidation = NULL; $this->tabindexes = NULL; if (isset($formTabindexes)) { $this->tabindexes = $formTabindexes; } if (isset($renderFunc)) { $this->renderer = $renderFunc; } if (isset($subjectFunc)) { $this->subjectRenderer = $subjectFunc; } if (isset($validateFunc)) { $this->customValidation = $validateFunc; } if (isset($wikiGetterFunc)) { if ($this->wikiTextBefore != NULL) { $this->wikiTextBefore = $wikiGetterFunc($this->wikiTextBefore); } if ($this->wikiTextAfter != NULL) { $this->wikiTextAfter = $wikiGetterFunc($this->wikiTextAfter); } } } function showForm() { global $wgOut, $wgUser; $pageTitle = wfMsg("contactpage-pagetitle"); $wgOut->setPagetitle($pageTitle); // Labels $subjectLabel = wfMsg( "contactpage-subject" ); $genderLabel = wfMsg( "contactpage-gender" ); $genderMale = wfMsg( "contactpage-gender-male" ); $genderFemale = wfMsg( "contactpage-gender-female" ); $firstNameLabel = wfMsg( "contactpage-firstname" ); $lastNameLabel = wfMsg( "contactpage-lastname" ); $companyLabel = wfMsg( "contactpage-company" ); $addressLabel = wfMsg( "contactpage-address" ); $postalCodeLabel = wfMsg( "contactpage-postalcode" ); $cityLabel = wfMsg( "contactpage-city" ); $countryLabel = wfMsg( "contactpage-country" ); $phoneLabel = wfMsg( "contactpage-phone" ); $faxLabel = wfMsg( "contactpage-fax" ); $emailLabel = wfMsg( "contactpage-email" ); $contentLabel = wfMsg( "contactpage-content" ); $submitLabel = wfMsg( "contactpage-submit" ); $encGender = htmlspecialchars( $this->gender); $encFirstName = htmlspecialchars( $this->firstName ); $encLastName = htmlspecialchars( $this->lastName ); $encCompany = htmlspecialchars( $this->company ); $encAddress = htmlspecialchars( $this->address ); $encPostalCode = htmlspecialchars( $this->postalCode ); $encCity = htmlspecialchars( $this->city ); $encCountry = htmlspecialchars( $this->country ); $encPhone = htmlspecialchars( $this->phone ); $encFax = htmlspecialchars( $this->fax ); $encEmail = htmlspecialchars( $this->email ); $encContent = htmlspecialchars( $this->content ); $titleObj = SpecialPage::getTitleFor( "Contact" ); $action = $titleObj->escapeLocalURL( "action=submit" ); $token = $wgUser->isAnon() ? EDIT_TOKEN_SUFFIX : $wgUser->editToken(); //this kind of sucks, really... $token = htmlspecialchars( $token ); $wgOut->addHTML( "<h1>{$pageTitle}</h1>" ); if (count($this->errors) > 0) { $wgOut->addHTML("<ul class=\"errorbox\">"); foreach ($this->errors as $err) { $wgOut->addHTML("<li>{$err}.</li>"); } $wgOut->addHTML("</ul>"); } if (count($this->messages) > 0) { $wgOut->addHTML("<ul class=\"successbox\">"); foreach ($this->messages as $msg) { $wgOut->addHTML("<li>{$msg}</li>"); } $wgOut->addHTML("</ul>"); } if ($this->wikiTextBefore != NULL) { $wgOut->addSecondaryWikiText($this->wikiTextBefore); } $wgOut->addHTML("<div id=\"contactPanel\"> <form id=\"emailuser\" method=\"post\" action=\"{$action}\"> <input type=\"hidden\" name=\"wpBefore\" value=\"{$this->before}\" /> <input type=\"hidden\" name=\"wpAfter\" value=\"{$this->after}\" /> <div id=\"subjectGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpSubject\">{$subjectLabel}</label></div> <div class=\"fieldWidget\"> <select id=\"wpSubject\" name=\"wpSubject\""); if ($this->tabindexes != NULL && $this->tabindexes['wpSubject']) { $wgOut->addHTML(" tabindex=\"{$this->tabindexes['wpSubject']}\""); } $wgOut->addHTML(">"); foreach ($this->subjects as $val) { $label = wfMsg("contactpage-subject-" . $val); $wgOut->addHTML("<option value=\"{$val}\"" . ($this->subject == $val ? " selected=\"true\"" : "") . ">{$label}</option>"); } $wgOut->addHTML(" </select> </div> </div> <div id=\"genderGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpGender\">{$genderLabel}</label></div> <div class=\"fieldWidget\"> <select id=\"wpGender\" name=\"wpGender\""); if ($this->tabindexes != NULL && $this->tabindexes['wpGender']) { $wgOut->addHTML(" tabindex=\"{$this->tabindexes['wpGender']}\""); } $wgOut->addHTML("> <option value=\"{$genderFemale}\"" . ($encGender == $genderFemale ? " selected=\"true\"" : "") . ">{$genderFemale}</option> <option value=\"{$genderMale}\"" . ($encGender == $genderMale ? " selected=\"true\"" : "") . ">{$genderMale}</option> </select> </div> </div> <div id=\"firstNameGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpFirstName\">{$firstNameLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpFirstName\" name=\"wpFirstName\" value=\"{$encFirstName}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpFirstName']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpFirstName']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"lastNameGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpLastName\">{$lastNameLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpLastName\" name=\"wpLastName\" value=\"{$encLastName}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpLastName']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpLastName']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"companyGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpCompany\">{$companyLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpCompany\" name=\"wpCompany\" value=\"{$encCompany}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpCompany']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpCompany']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"emailGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpEmail\">{$emailLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpEmail\" name=\"wpEmail\" value=\"{$encEmail}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpEmail']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpEmail']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"phoneGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpPhone\">{$phoneLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpPhone\" name=\"wpPhone\" value=\"{$encPhone}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpPhone']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpPhone']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"faxGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpFax\">{$faxLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpFax\" name=\"wpFax\" value=\"{$encFax}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpFax']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpFax']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"addressGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpAddress\">{$addressLabel}</label></div> <div class=\"fieldWidget\"> <textarea id=\"wpAddress\" name=\"wpAddress\""); if ($this->tabindexes != NULL && $this->tabindexes['wpAddress']) { $wgOut->addHTML(" tabindex=\"{$this->tabindexes['wpAddress']}\""); } $wgOut->addHTML(">{$encAddress}</textarea> </div> </div> <div id=\"postalCodeGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpPostalCode\">{$postalCodeLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpPostalCode\" name=\"wpPostalCode\" value=\"{$encPostalCode}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpPostalCode']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpPostalCode']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"cityGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpCity\">{$cityLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpCity\" name=\"wpCity\" value=\"{$encCity}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpCity']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpCity']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"countryGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpCountry\">{$countryLabel}</label></div> <div class=\"fieldWidget\"> <input type=\"text\" id=\"wpCountry\" name=\"wpCountry\" value=\"{$encCountry}\" "); if ($this->tabindexes != NULL && $this->tabindexes['wpCountry']) { $wgOut->addHTML("tabindex=\"{$this->tabindexes['wpCountry']}\" "); } $wgOut->addHTML("/> </div> </div> <div id=\"contentGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpContent\">{$contentLabel}</label></div> <div class=\"fieldWidget\"> <textarea id=\"wpContent\" name=\"wpContent\""); if ($this->tabindexes != NULL && $this->tabindexes['wpContent']) { $wgOut->addHTML(" tabindex=\"{$this->tabindexes['wpContent']}\""); } $wgOut->addHTML(">{$encContent}</textarea> </div> </div> " . $this->getCaptcha() . "<div id=\"formControls\"> <input type=\"submit\" name=\"wpSend\" value=\"{$submitLabel}\" /> <input type=\"hidden\" name=\"wpEditToken\" value=\"$token\" /> </div></form></div>\r\n" ); if ($this->wikiTextAfter != NULL) { $wgOut->addSecondaryWikiText($this->wikiTextAfter); } } function getCaptcha() { global $wgCaptcha, $wgCaptchaTriggers; if ( !$wgCaptcha ) return ""; //no captcha installed if ( !@$wgCaptchaTriggers['contactpage'] ) return ""; //don't trigger on contact form $captchaLabel = wfMsg( "contactpage-captcha" ); $text = " <div id=\"captchaGroup\" class=\"formGroup\"> <div class=\"fieldLabel\"><label for=\"wpCaptcha\">{$captchaLabel}</label></ div> <div class=\"fieldWidget\"> " . $wgCaptcha->getForm() . " </div> </div>\n"; return $text; } function passCaptcha() { global $wgCaptcha, $wgCaptchaTriggers; if ( !$wgCaptcha ) return true; //no captcha installed if ( !@$wgCaptchaTriggers['contactpage'] ) return true; //don't trigger on contact form return $wgCaptcha->passCaptcha(); } function doSubmit( ) { global $wgOut, $wgContactSender, $wgContactSenderName; $fname = 'EmailContactForm::doSubmit'; wfDebug( "$fname: start\n" ); $dispatcherFunc = $this->dispatcher; $toAddr = $dispatcherFunc($this); // emails addresses $to = new MailAddress( $toAddr ); $from = new MailAddress( $this->defaultSenderEmail, $this->defaultSenderName ); $replyto = NULL; $subject = $this->subject = trim( $this->subject ); $gender = $this->gender = trim( $this->gender ); $firstName = $this->firstName = trim( $this->firstName ); $lastName = $this->lastName = trim( $this->lastName ); $company = $this->company = trim( $this->company ); $address = $this->address = trim( $this->address ); $postalCode = $this->postalCode = trim( $this->postalCode ); $city = $this->city = trim( $this->city ); $country = $this->country = trim( $this->country ); $phone = $this->phone = trim( $this->phone ); $fax = $this->fax = trim( $this->fax ); $email = $this->email = trim( $this->email ); $content = $this->content = trim( $this->content ); if ( $subject === "" ) { $this->errors['subject'] = wfMsgForContent( "contactpage-defsubject" ); } if ( $gender === "" ) { $this->errors['gender'] = wfMsgForContent( "contactpage-defgender" ); } if ( $firstName === "" ) { $this->errors['firstName'] = wfMsgForContent( "contactpage-deffirstname" ); } if ( $lastName === "" ) { $this->errors['lastName'] = wfMsgForContent( "contactpage-deflastname" ); } if ( $content === "" ) { $this->errors['content'] = wfMsgForContent( "contactpage-defcontent" ); } if ( $email !== "" && strpos($email, "@") === false ) { $this->errors['email-invalid'] = wfMsgForContent( "contactpage-defvalidemail" ); } if ($this->customValidation != NULL) { $validateFunc = $this->customValidation; $validateFunc($this); } if (count($this->errors) > 0) { $this->showForm(); return; } // --- if ($this->subjectRenderer != NULL) { $subjectFunc = $this->subjectRenderer; $subject = $subjectFunc($this); } else { $subject = wfMsg( "contactpage-subject-$subject" ); } if ($this->renderer != NULL) { $renderFunc = $this->renderer; $content = $renderFunc($this); } $mailOpts = array(&$to, &$replyto, &$subject, &$content); if (!wfRunHooks( 'ContactForm', $mailOpts) ) { return; } // --- if ( $email !== "" ) { $from = new MailAddress( $email, "$firstName $lastName" ); $replyto = $from; } wfDebug( "$fname: sending mail from " . $from->toString() . " to " . $to->toString() . " replyto " . ($replyto == null ? '-/-' : $replyto->toString()) . "\n" ); // HACK: in MW 1.9, replyto must be a string, // in MW 1.0, it must be an object! $ver = preg_replace( '![^\d._+]!', '', $GLOBALS['wgVersion'] ); $replyaddr = $replyto == null ? NULL : version_compare( $ver, '1.10', '<' ) ? $replyto->toString() : $replyto; $mailResult = userMailer( $to, $from, $subject, $content, $replyto ); if (WikiError::isError( $mailResult )) { $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult); return; } // --- wfDebug( "$fname: success\n" ); $titleObj = SpecialPage::getTitleFor( "Contact" ); $wgOut->redirect( $titleObj->getFullURL( "action=success&wpBefore={$this->before}&wpAfter={$this->after}" ) ); wfRunHooks( 'ContactFromComplete', array($to, $replyto, $subject, $this->text) ); wfDebug( "$fname: end\n" ); } function showSuccess( ) { $this->messages['success'] = wfMsg( "emailsenttext" ); $this->showForm(); } function addError($aErrorKey, $aMessageKey) { $this->errors[$aErrorKey] = wfMsgForContent($aMessageKey); } }
File ContactPage.i18n.en.php : <a name="ContactPage.i18n.YOUR_LANG.php">English i18n</a>
<?php $messages = array( 'contactpage-captcha-failed' => 'Captcha check failed', 'contactpage-captcha', 'Captcha', 'contactpage-pagetitle' => 'Contact', 'contactpage-defsubject' => 'Choose your subject', 'contactpage-subject' => 'Subject', 'contactpage-defgender' => 'Choose your gender', 'contactpage-gender' => 'Gender', 'contactpage-deffirstname' => 'Type your first name', 'contactpage-firstname' => 'First name', 'contactpage-deflastname' => 'Type your last name', 'contactpage-lastname' => 'Last name', 'contactpage-company' => 'Company / Organisation', 'contactpage-address' => 'Address', 'contactpage-postalcode' => 'Postal code', 'contactpage-city' => 'City', 'contactpage-country' => 'Country', 'contactpage-phone' => 'Phone', 'contactpage-fax' => 'Fax', 'contactpage-email' => 'Email', 'contactpage-defvalidemail' => 'Correct your email address', 'contactpage-defcontent' => 'Type your message', 'contactpage-content' => 'Message', 'contactpage-submit' => 'Send', 'contactpage-gender-male' => 'Mr', 'contactpage-gender-female' => 'Ms' , // subject i18n (optional) 'contactpage-subject-support' => 'Support', 'contactpage-subject-other' => 'Other' , // Used by renderer 'contactpage-sender' => 'Sender', 'contactpage-fullname' => 'Name', 'contactpage-fulladdress' => 'Address' , // Used by custom validation 'contactpage-deffulladdress' => 'Complete your address' );
File ContactPage.i18n.fr.php : French i18n
$messages = array( 'contactpage-captcha-failed' => 'Code de vérification incorrect', 'contactpage-captcha', 'Veuillez saisir le code ci-dessous', 'contactpage-pagetitle' => 'Contact', 'contactpage-defsubject' => 'Veuillez choisir l\'objet du message', 'contactpage-subject' => 'Objet', 'contactpage-defgender' => 'Veuillez choisir votre civilité', 'contactpage-gender' => 'Civilité', 'contactpage-deffirstname' => 'Veuillez saisir un prénom', 'contactpage-firstname' => 'Prénom', 'contactpage-deflastname' => 'Veuillez saisir un nom', 'contactpage-lastname' => 'Nom', 'contactpage-company' => 'Société / Organisme', 'contactpage-address' => 'Adresse', 'contactpage-postalcode' => 'Code postal', 'contactpage-city' => 'Ville', 'contactpage-country' => 'Pays', 'contactpage-phone' => 'Téléphone', 'contactpage-fax' => 'Fax', 'contactpage-email' => 'Email', 'contactpage-defvalidemail' => 'Veuillez saisir une adresse email valide', 'contactpage-defcontent' => 'Veuillez saisir votre message', 'contactpage-content' => 'Message', 'contactpage-submit' => 'Envoyer', 'contactpage-gender-male' => 'Mr', 'contactpage-gender-female' => 'Mme' , // subject i18n (optional) 'contactpage-subject-support' => 'Support', 'contactpage-subject-other' => 'Autre', 'contactpage-subject-ipage_info' => 'Demande d\'information sur iPage' , // Used by renderer 'contactpage-sender' => 'Expéditeur', 'contactpage-fullname' => 'Nom', 'contactpage-fulladdress' => 'Adresse' , // Used by custom validation 'contactpage-deffulladdress' => 'Veuillez définir une adresse complète' );
File ContactSettings.php : extension settings (should be modified)
<?php // Normalized subjects $subjects = array( 'support', 'other', 'ipage_info' ); // Dispatcher function $dispatcherFunc = "contactDispatcher"; // Main subject renderer (optional) $subjectFunc = "contactSubject"; // Mail content renderer function (optional) $renderFunc = "contactRenderer"; // Custom validate function (optional) $validateFunc = "contactValidate"; // Default sender $defaultSenderName = "Contact page"; $defaultSenderEmail = "contact@foo.com"; // Wiki texts (optional) $wikiGetterFunc = "contactWikiGetter"; // get wiki text value from parameter 'before' or 'after' /** * Allow to override tabindex for some (or all) form fields. * By default order is : "wpSubject", "wpGender", "wpFirstName", * "wpLastName", "wpCompany", "wpEmail", "wpPhone", "wpFax", * "wpAddress", "wpPostalCode", "wpCity", "wpCountry", * "wpContent". */ $formTabindexes = array( "wpSubject" => 1, "wpGender" => 2, "wpLastName" => 3, "wpFirstName" => 4, "wpCompany" => 5, "wpAddress" => 6, "wpPostalCode" => 7, "wpCity" => 8, "wpCountry" => 9, "wpPhone" => 10, "wpFax" => 11, "wpEmail" => 12, "wpContent" => 13 );
File MyContact.php : custom functions (should be provided)
<?php /** * @brief Custom function to determine where to sent mail (required). * @param aContactForm Form for which recipient should be determined. * @return Recipient of mail for |aContactForm|. */ function contactDispatcher($aContactForm) { return "cchantep"; } /** * @brief Custom function to determine mail subject according form (optional). * @param aContactForm Form for which subject should be determined. * @return Subject of mail to sent for |aContactForm|. */ function contactSubject($aContactForm) { $subject = wfMsg("contactpage-subject-" . $aContactForm->subject); return "[www.nozicaa.com/Contact] $subject"; } /** * @brief Custom content rendering function (optional). * @param aContactForm Form for which content should be determined. * @return Content to be send in mail according |aContactForm|. */ function contactRenderer($aContactForm) { $senderLabel = wfMsg( "contactpage-sender" ); $nameLabel = wfMsg( "contactpage-fullname" ); $gender = $aContactForm->gender; $firstName = $aContactForm->firstName; $lastName = $aContactForm->lastName; $company = $aContactForm->company; $phone = $aContactForm->phone; $fax = $aContactForm->fax; $email = $aContactForm->email; $address = $aContactForm->address; $postalCode = $aContactForm->postalCode; $city = $aContactForm->city; $country = $aContactForm->country; $subject = wfMsg( "contactpage-subject-" . $aContactForm->subject ); $content = $aContactForm->content; $text = "== {$senderLabel} == {$nameLabel} : ({$gender}) {$firstName} {$lastName}"; if ($company !== "") { $companyLabel = wfMsg( "contactpage-company" ); $text .= " {$companyLabel} : {$company}"; } if ($email !== "") { $emailLabel = wfMsg( "contactpage-email" ); $text .= " {$emailLabel} : {$email}"; } if ($phone !== "") { $phoneLabel = wfMsg( "contactpage-phone" ); $text .= " {$phoneLabel} : {$phone}"; } if ($fax !== "") { $faxLabel = wfMsg( "contactpage-fax" ); $text .= " {$faxLabel} : {$fax}"; } if ($address !== "" && $postalCode !== "" && $city !== "" && $country !== "") { $addressLabel = wfMsg( "contactpage-fulladdress" ); $text .= " {$addressLabel} : {$address} {$postalCode} {$city} {$country}"; } $text .= " == Message : {$subject} == {$content}"; return $text; } /** * @brief Custom validation function. * @param aContactForm Form to be validated. */ function contactValidate($aContactForm) { $address = $aContactForm->address; $city = $aContactForm->city; $postalCode = $aContactForm->postalCode; $country = $aContactForm->country; $c = 0; if ($address !== "") { $c++; } if ($postalCode !== "") { $c++; } if ($city !== "") { $c++; } if ($country !== "") { $c++; } if ($c > 0 && $c != 4) { $aContactForm->addError('address', 'contactpage-deffulladdress'); } } /** * @brief Get wiki text for value passed as 'before' and/or 'after' runtime parameters. * @param Parameter value for which matching wiki text should be get. * @return Wiki text matching |aWikiTextId|. */ function contactWikiGetter($aWikiTextId) { $contactWikiRegistry = array( 'contactMenu' => '{{Menu|module=contact}}', 'supportMenu' => '{{Menu|module=support}}', ); return $contactWikiRegistry[$aWikiTextId]; }
[edit] Captcha
This extension support captcha. In order to enable that you should add following line in your LocalSettings.php file :
$wgCaptchaTriggers['contactpage'] = true

