Difference between revisions of "Extension:EmailPage"

From Organic Design wiki
m
(start form)
Line 33: Line 33:
 
}
 
}
  
# Override SpecialPage::execute()
+
# Override SpecialPage::execute($param = '')
 
wfSpecialEmailArticle($param,&$specialpage) {
 
wfSpecialEmailArticle($param,&$specialpage) {
global $wgOut;
+
global $wgOut,$wgUser,$wgEmailArticleContactsCat;
 
$title = Title::makeTitle(NS_SPECIAL,'EmailArticle');
 
$title = Title::makeTitle(NS_SPECIAL,'EmailArticle');
$wgOut->addWikiText(wfMsg('example-message','exampleParameter'));
+
if ($param == '') return $wgOut->addWikiText(wfMsg('ea_noarticle'));
$wgOut->addHTML(
+
 
wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'post'),null)
+
# Create a select list of all categories in $wgEmailArticleContactsCat
 +
$db =& wfGetDB(DB_SLAVE);
 +
$cl = $db->tableName('categorylinks');
 +
$result = $db->query("SELECT cl_from FROM $cl WHERE cl_to = '$wgEmailArticleContactsCat' ORDER BY cl_sortkey");
 +
while ($row = mysql_fetch_row($result)) {
 +
$t = Title::newFromDBkey($row[0]);
 +
$cats .= "<option>$t</option>";
 +
}
 +
 
 +
$wgOut->addWikiText(wfMsg('ea_selectrecipients'));
 +
if ($wgOut->addHTML(
 +
wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'POST'),null)
 +
. "From category: <select name=\"period\">$cats</select>"
 +
. wfElement('input',array('type' => 'submit'))
 
. '<textarea name="target" cols=25 rows=10></textarea>'
 
. '<textarea name="target" cols=25 rows=10></textarea>'
 
. wfElement('input',array('type' => 'submit'))
 
. wfElement('input',array('type' => 'submit'))
Line 55: Line 68:
 
if ($wgLanguageCode == 'en') {
 
if ($wgLanguageCode == 'en') {
 
$wgMessageCache->addMessages(array(
 
$wgMessageCache->addMessages(array(
'emailarticle' => 'Example Specialpage',        # The friendly page title
+
'emailarticle'       => 'EmailArticle',
'exampleMessage' => "Example message: <tt>$1</tt>",
+
'ea_noarticle'       => "Please specify an article to send, for example [[Special:EmailArticle/Main Page]].",
 +
'ea_error'           => "Error: '''$1'''",
 +
'ea_ok'              => "Article [[$1]] sent successfully to '''$2''' recipient$3",
 +
'ea_selectrecipients' => "Select the recipients"
 
));
 
));
 
}
 
}

Revision as of 03:30, 28 May 2007

<?php

  1. Extension:EmailArticle
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:SpecialPage
  3. - See http://www.mediawiki.org/wiki/Extension:EmailArticle for installation and usage details

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('EMAILARTICLE_VERSION','0.0.0, 2007-05-25');

$wgEmailArticleGroup = 'postmaster'; # Users must belong to this group to send emails (empty string means anyone can send) $wgEmailArticleContactsCat = 'Contacts'; # This specifies the name of a category containing categories of contact articles

$wgExtensionFunctions[] = 'wfSetupEmailArticle';

$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:EmailArticle', 'author' => 'User:Nad', 'description' => 'Send rendered article to an email address or list of addresses', 'url' => 'http://www.mediawiki.org/wiki/Extension:EmailArticle', 'version' => EMAILARTICLE_VERSION );

require_once "$IP/includes/SpecialPage.php";

  1. Define a new class based on the SpecialPage class

class SpecialEmailArticle extends SpecialPage {

# Constructor function SpecialSearchLog() { global $wgEmailArticleGroup; SpecialPage::SpecialPage('EmailArticle',$wgEmailArticleGroup); }

# Override SpecialPage::execute($param = ) wfSpecialEmailArticle($param,&$specialpage) { global $wgOut,$wgUser,$wgEmailArticleContactsCat; $title = Title::makeTitle(NS_SPECIAL,'EmailArticle'); if ($param == ) return $wgOut->addWikiText(wfMsg('ea_noarticle'));

# Create a select list of all categories in $wgEmailArticleContactsCat $db =& wfGetDB(DB_SLAVE); $cl = $db->tableName('categorylinks'); $result = $db->query("SELECT cl_from FROM $cl WHERE cl_to = '$wgEmailArticleContactsCat' ORDER BY cl_sortkey"); while ($row = mysql_fetch_row($result)) { $t = Title::newFromDBkey($row[0]); $cats .= "<option>$t</option>"; }

$wgOut->addWikiText(wfMsg('ea_selectrecipients')); if ($wgOut->addHTML( wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'POST'),null) . "From category: <select name=\"period\">$cats</select>" . wfElement('input',array('type' => 'submit')) . '<textarea name="target" cols=25 rows=10></textarea>' . wfElement('input',array('type' => 'submit')) . '</form>' ); }

}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupEmailArticle() { global $wgLanguageCode,$wgMessageCache;

# Add the messages used by the specialpage if ($wgLanguageCode == 'en') { $wgMessageCache->addMessages(array( 'emailarticle' => 'EmailArticle', 'ea_noarticle' => "Please specify an article to send, for example Special:EmailArticle/Main Page.", 'ea_error' => "Error: $1", 'ea_ok' => "Article $1 sent successfully to $2 recipient$3", 'ea_selectrecipients' => "Select the recipients" )); }

# Add the specialpage to the environment SpecialPage::addPage(new SpecialEmailArticle()); } ?>