Jump to content

Extension talk:CorporateContact

Add topic
From mediawiki.org

It's a good Extension, but there's a lot of problem with the code and explainations.
There's a lot of error on listing, some tag (like <?php, semicolon, etc...) are missing and generate some problem on displaying page.
the errors corrected, there no technical problem.

After check I think you've used an obselete version of that extension. Distribution hosted as NOZICAA [1] works without any mentioned trouble, in XHTML strict compliance. In order to avoid future trouble, I've removed code from extension page, as now it will be provided as distribution archive (tarball). Cchantep 16:30, 17 November 2008 (UTC)Reply

To use Captcha, you need to install captcha module (ie : ReCaptcha)

VisualMathCaptcha also work, as on sample contact page [2] (see also extension captch section). Cchantep 16:30, 17 November 2008 (UTC)Reply

Good Job for the original developper

Bug

[edit]

After correcting the code, there's one bug (not critical) :
the style of the left menu when the contact form is displayed is changed : Charactere size are reduce. I don't find the problem, if some have an Idea ...

What do you mean exactly ? If you talk about "Search" or "Other languages" box I can't reproduced such font trouble with example page under Firefox. Cchantep 16:30, 17 November 2008 (UTC)Reply

Debugged Sources with more comments

[edit]

ContactSetting.php

[edit]
Comment included in distribution file. Cchantep 16:30, 17 November 2008 (UTC)Reply
  <?php
  // Normalized subjects
  // the name between comma will be ''translated'' to 'contactpage-subject-' and the name between comma
  // ex : contact ==> contactpage-subject-contact
  // YOU NEED to DEFINE THIS Variable in you Langage file ContactPage.i18n.xx.php with the text to be display for this variables
  $subjects = array(
  'contact',
  'support',
  '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 = "SendName";  // and sender name to be display
  $defaultSenderEmail = "email@isp.com";  // the email of the sender
   
  // 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
  );

ContactPage.i18n.fa.php

[edit]
  • Language file for Persian (Farsi)
Thanks, I just included it in distribution tarball. Cchantep 16:30, 17 November 2008 (UTC)Reply
<?php
// This language file translated to Persian by Saeed Moaddeli,
// Send comments to <s.moaddeli> at Gmail 
$messages = array(
'contactpage-captcha-failed' => 'آزمون کپچا موفقیت‌آمیز نبود.',
'contactpage-captcha' => 'نتیجهٔ این محاسبه را وارد کنید',
'contactpage-pagetitle' => 'تماس با ما',
'contactpage-defsubject' => 'یک موضوع را انتخاب کنید',
'contactpage-subject' => 'موضوع',
'contactpage-defgender' => 'جنسیا خود را انتخاب کنید', 
'contactpage-gender' => 'جنسیت',
'contactpage-deffirstname' => 'نام‌تان را وارد کنید',
'contactpage-firstname' => 'نام',
'contactpage-deflastname' => 'نام خانوادگی‌تان را وارد کنید',
'contactpage-lastname' => 'نام خانوادگی',
'contactpage-company' => 'سازمان',
'contactpage-address' => 'نشانی',
'contactpage-postalcode' => 'کد پستی',
'contactpage-city' => 'شهر',
'contactpage-country' => 'کشور',
'contactpage-phone' => 'تلفن',
'contactpage-fax' => 'نمابر',
'contactpage-email' => 'پست الکترونیکی',
'contactpage-defvalidemail' => 'نشانی پست الکترونیکی‌تان را تصحیح کنید',
'contactpage-defcontent' => 'پیغامتان را تایپ کنید',
'contactpage-content' => 'پیغام',
'contactpage-submit' => 'بفرست',
'contactpage-gender-male' => 'آقا',
'contactpage-gender-female' => 'خانم',
'contactpage-subject-support' => 'پشتیبانی',
'contactpage-subject-other' => 'دیگر',
'contactpage-subject-zpage_info' => 'iPage information',
'contactpage-subject-messageit_info' => 'MessageiT information',
'contactpage-subject-employment' => 'مشاغل'
, // Used by renderer

'contactpage-sender' => 'فرستنده',
'contactpage-fullname' => 'نام',
'contactpage-fulladdress' => 'نشانی'

, // Used by custom validation
'contactpage-deffulladdress' => 'نشانی خود را تکمیل کنید'
);
?>

ContactPage.i18n.fr.php

[edit]
  • Some characters are appears strange displayed in french version.
  <?php
  $messages = array(
  'contactpage-captcha-failed' => 'Code de v&eacute;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&eacute;', 
  'contactpage-gender' => 'Civilit&eacute;',
  'contactpage-deffirstname' => 'Veuillez saisir un pr&eacute;nom',
  'contactpage-firstname' => 'Pr&eacute;nom',
  'contactpage-deflastname' => 'Veuillez saisir un nom',
  'contactpage-lastname' => 'Nom',
  'contactpage-company' => 'Soci&eacute;t&eacute; / Organisme',
  'contactpage-address' => 'Adresse',
  'contactpage-postalcode' => 'Code postal',
  'contactpage-city' => 'Ville',
  'contactpage-country' => 'Pays',
  'contactpage-phone' => 'T&eacute;l&eacute;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-contact' => 'Contact',
  'contactpage-subject-ipage_info' => 'Demande d\'information sur iPage'
   
  , // Used by renderer
   
  'contactpage-sender' => 'Expediteur',
  'contactpage-fullname' => 'Nom',
  'contactpage-fulladdress' => 'Adresse'
   
  , // Used by custom validation
  'contactpage-deffulladdress' => 'Veuillez d&eacute;finir une adresse complète'
  );

ContactPage.i18n.en.php

[edit]
  <?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'
  );

ContactPage.body.php

[edit]
  <?php
  /**
   * Speclial:Contact, a contact form for visitors.
   * Based on SpecialEmailUser.php
   * 
   * @addtogroup SpecialPage
   * @copyright from the autoloader*/
  require_once("includes/UserMailer.php");
  
  /**
   *
   */
  class SpecialContact extends SpecialPage {
   
      /**
       * Constructor
       */
      function __construct() {
          global $wgOut;
          SpecialPage::SpecialPage( 'Contact', '', false );
   
          #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);
        }
  	  $wgOut->addHTML("</div></div>");
   
      }
   
      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);
      }
  }

ContactPage.setup.php

[edit]
<?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;
}

MyContact.php

[edit]
<?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 "email@isp.com";  // specify your email to send where
}
 
/**
 * @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 "FirstText $subject";  // FirstText will be replace by your own text (title) of your subject email
}
 
/**
 * @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];
}

XHTML compliance (15:21, 20 November 2008 (UTC))

[edit]

Fix some XHTML issues. Adds configuration parameters for wpAddress and wpContent textareas HTML rows and cols attributes from ContentSettings.php : addressCols, addressRows, contentCols, contentRows. Cchantep 15:21, 20 November 2008 (UTC)Reply