Extension:Events

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
Events

Release status: stable

Implementation Tag, Special page
Description Provides the ability to create events on any page of your MediaWiki
Author(s) Aran Deltac, Sylvain Machefert and Stéphane GALLAND
Latest version 3.1
License GPLv2+
Download see below for version prior to 2.0, or http://www.arakhne.org/mediawiki/Events/ since version 2.0

Translate the Events extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

This extension provides the ability to create events on any page of your MediaWiki. Also included is a highly configurable Special page for aggregating events on your site by various criteria. All events are stored in MySQL or pgSQL, so the Special page is extremely fast.

Original author is Aran Deltac but he decided to no longer maintain it. Thanks to Google cache I've found the instructions, I copy them here, because Aran's wiki has changed. Iubito 16:51, 10 February 2006 (UTC)

Since August 2010, version 2.0 is released on Arakhnê.org website. Major contribution is the support of PostgreSQL database.

News[edit | edit source]

  • 2010-08-26: Version 3.1 available on Arakhnê.org website.
  • 2010-08-25: Version 3.0 available on Arakhnê.org website.
  • 2010-08-09: Version 2.0 available on Arakhnê.org website.
  • 2007-03-06: Added a version for mediaWiki 1.9
  • 2006-03-12: Added code snipped to make it compatible with Christof Damian's Calendar extension.
  • 2006-02-10: Released version 0.2. Aran no longer maintain code, instructions copied here by Iubito with slight changes that make this extension work on MediaWiki 1.4 but no tested.
  • 2005-11-02: Released version 0.1.
  • 2005-11-02: First version of MediaWiki Events released.

Version 2.0 and higher[edit | edit source]

Version 2.0 of Events introduces the following changes:

  • Add pgSQL support.
  • Add automatic creation of the event tables in pgSQL and MySQL databases.
  • Add visibility level for events.
  • Apply recent Mediawiki extension writing rules.
  • Add output customization with CSS classes.

Usage[edit | edit source]

Each event must be on its own line and start with a date and separator. All the tasks must be grouped with a <events>...</events>. This tag must be put in a wiki page.

The separator character should be one of:

  • '!' for important events which are visible to every one (not yet rendered in a special way),
  • ':' for standard events which are visible to every one,
  • '#' for standard events which are visible only to connected users,
  • '-' for events which are invisible.


Example:

  <events>
  2062-02-14 ! This is a very important public event.
  1453-07-12 : This is a public event.
  1423-12-25 # This is an event for connected guys.
  1423-12-25 - This is an event which is never rendered.
  </events>

Remember: the <events/> tags must be put inside the wiki text of an article.

Configuration[edit | edit source]

Events extension provides several configuration variables. these variables should be defined in your LocalSettings.php.

  • $wgEventsOldAge: Number of days in the past before which events are discarted. null means default value ie. 30.
  • $wgEventsYoungAge: Number of days in the future after which events are discarted. null means default value ie. 365.
  • $wgEventExtensionRenderImportantEventBox: Indicates if the box for important events should be rendered. To enable this event box, this global variable must be true, AND the current skin must implement a function named isEventsExtensionImportantEventEnabled() which replies a boolean value indicating if the skin support the event box CSS style or not.
  • $wgEventsCloseButtonIcon: Is the URL to the icon which is displayed to close the event popup box. Expected sizes: 12x12 or 16x16.

Special Page to List the Events[edit | edit source]

As for previous version, all the events of the site are visible on the special page Special:Events.

Special Page to Clear the Database[edit | edit source]

Since version 3.0, all the event related tables in the database could be removed by the special page Special:ClearEvents.

Database Schema[edit | edit source]

Events extension is now supporting pgSQL and MySQL. The 'events' table is automatically created for both databases.

PostgreSQL Schema[edit | edit source]

DROP TYPE IF EXISTS eventVisibility CASCADE;
DROP TABLE IF EXISTS events CASCADE;
DROP TABLE IF EXISTS eventglobal CASCADE;
CREATE TYPE eventVisibility AS ENUM ('public', 'connected', 'invisible');
CREATE TABLE events (
   page_id integer NOT NULL DEFAULT 0,
   date date NOT NULL,
   description text NOT NULL,
   visibility eventVisibility DEFAULT 'invisible' NOT NULL
);
CREATE TABLE eventglobal (
   popuphtml text NOT NULL
);

MySQL Schema[edit | edit source]

DROP TABLE IF EXISTS events CASCADE;
DROP TABLE IF EXISTS eventglobal CASCADE;
CREATE TABLE events (
   page_id INT UNSIGNED NOT NULL DEFAULT 0,
   date DATE NOT NULL DEFAULT '0000-00-00',
   description TEXT NOT NULL,
   visibility ENUM('public','connected','invisible') DEFAULT 'invisible' NOT NULL,
   KEY date_idx (page_id,date)
);
CREATE TABLE eventglobal (
   popuphtml TEXT NOT NULL
);

Previous versions[edit | edit source]

Compatibility[edit | edit source]

Aran has only tested this on MediaWiki 1.5.1. Iubito and has applied changes to be compatible with MediaWiki 1.4, but it is not tested. Use at your own risk.

Note I tested this on my MediaWiki installation version 1.9.1 and it didn't work. - Random user

I had the same problem on MediaWiki version 1.9.3. Will there probably be an update? Events are shown on the pages but there are no entries on the special page.

Cstehly 06:47, 24 August 2007 (UTC) Tested with 1.7, it works with following update on Events.php (<1.9) : Replace

Parser::extractTagsAndParams( 'events', $text, $content, $tags, $params );
        foreach($tags as $marker => $markerVal)
                eventsHook( $content[$marker], $params[$marker] );

with

Parser::extractTagsAndParams( array('events'), $text, $matches );
        foreach($matches as  $marker => $data) {
                list( $element, $content, $params, $tag ) = $data;
                eventsHook( $content);
                 }

Usage[edit | edit source]

Each event must be on its own line and start with a date and colon. All the tasks must be grouped with a <events>..</events>

<events>
2062-02-14: When I buy my first hover car.
1453-07-12: Joe was born.
</events>

Events Special Page[edit | edit source]

This page finds all events on all pages of your site and displays them all on one page: Special:Events. You can provide an argument to limit the number of events that are returned:

  • limit - Maximum number of events to list.

Installation[edit | edit source]

Copy/paste codes below in files.


Version < 1.9[edit | edit source]

extensions/events/Events.php[edit | edit source]
<?php
# MediaWiki Events version 0.2
# Copyright (c) 2005 Aran Clary Deltac
# http://arandeltac.com/MediaWiki_Events
# Modified by Sylvain Machefert
# http://meta.wikimedia.org/w/index.php?title=Events_Extension
# Distributed under that same terms as MediaWiki itself.

$wgExtensionFunctions[] = "wfEventsExtension";
$wgHooks['ArticleSave'][] = 'clearEvents' ;
$wgHooks['ArticleSaveComplete'][] = 'saveEvents' ;
global $events_buffer;
 
#-----------------------------------------------#
# Purpose   : Declare parser extensions.
function wfEventsExtension() {
	global $wgParser;
	$wgParser->setHook( "events", "eventsHook" );
 
        global $wgMessageCache;
        $wgMessageCache->addMessages(array('events' => 'Events'));        
}
 
#-----------------------------------------------#
# Purpose   : Display a list of events.
# Parameters: content, A list of events, one per line.
# Returns   : Events HTML.
function eventsHook( $content, $args = null ) {
	global $events_buffer;
	$events = preg_split("/[\n\r]+/", $content);
	$output = '';
	foreach ($events as $event) {
		if (preg_match('/^\s*([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}):\s*(.+)$/',$event,$matches)) {
			$date = $matches[1];
			$description = $matches[2];
 
			$output .= formatEvent( $date, $description );
 
			$events_buffer[] = array(
				'date' => $date,
				'description' => $description
			);
		}
	}
	return $output;
}
 
#-----------------------------------------------#
# Purpose   : HTML format an event.
function formatEvent( $date, $description, $page='' ) {
	global $wgOut;
 
	$date_ary = explode( '-', $date );
	$date = sprintf( '%04d-%02d-%02d', $date_ary[0], $date_ary[1], $date_ary[2] );
	$description = "'''".$date.":'''&nbsp; ".$description;
 
	if ($page) { $description .= ' ([['. $page .']])'; }
	$output .= $wgOut->parse($description,false) .'<br />';
 
	return $output;
}
 
#-----------------------------------------------#
# Purpose   : Used before saveing a page to clear the events buffer.
function clearEvents() {    
	global $events_buffer;
	$events_buffer = array();
	return 1;
}
 
#-----------------------------------------------#
# Purpose   : Used after a page is saved to first delete 
#             all events and then save the new ones created 
#             in the events buffer.
# Parameters: article, The article object.
function saveEvents( $article, $user, $text ) {
	global $events_buffer;
	$page_id = $article->getID();
 
	$dbr =& wfGetDB( DB_MASTER );
	$dbr->delete(
		'events',
		array( 'page_id' => $page_id )
	);
 
	# Rebuild the $events_buffer array (in case we're on a <calendar> page)
	clearEvents();
	$content = array(); $tags = array(); $params = array();
 
	Parser::extractTagsAndParams( 'events', $text, $content, $tags, $params );
	foreach($tags as $marker => $markerVal)
		eventsHook( $content[$marker], $params[$marker] );
 
	foreach ($events_buffer as $event) {
		$event['page_id'] = $page_id;
		$dbr->insert(
			'events',
			$event
		);
	}
	$events_buffer = array();
	return 1;
}
?>
includes/SpecialEvents.php[edit | edit source]
<?php
# MediaWiki Events version 0.2
# Copyright (c) 2005 Aran Clary Deltac
# http://arandeltac.com/MediaWiki_Events
# Modified by Sylvain Machefert
# http://meta.wikimedia.org/w/index.php?title=Events_Extension
# Distributed under that same terms as MediaWiki itself.

require_once('SpecialPage.php');
$wgSpecialPages['Events'] = new SpecialPage ( 'Events' );
 
function wfSpecialEvents( $args_string = '' ) {
	global $wgOut;
	$page_titles = array();
	$dbr =& wfGetDB( DB_MASTER );
	# Parse arguments.
	$args = array();
	foreach (explode('&',$args_string) as $pair) {
		$pair = explode('=',$pair);
		$args[$pair[0]] = $pair[1];
	}
	# Define options for the SQL.
	$options = array( 'ORDER BY'=>'date DESC' );
	if ($args['limit']) {
		$options['LIMIT'] = $args['limit'];
	}
	# Run the SQL.
	$res = $dbr->select(
		'events', 
		array('page_id','date','description'), 
		'', 'Database::select',
		$options
	);
	if (!$res) { return; }
 
	# Set the title for this page.
	$wgOut->setPageTitle( 'Events' );
 
	# Generate HTML list of events.
	$count = 0;
	$last_year = '0000';
	$last_month = '00';
	while ($event = $dbr->fetchRow( $res )) {
		$page_title = $page_titles[$event['page_id']];
		if (!$page_title) {
			$page_titles[$event['page_id']] = Title::nameOf($event['page_id']);
			$page_title = $page_titles[$event['page_id']];
		}
		$date_ary = explode( '-', $event['date'] );
		if ( $last_year!=$date_ary[0] or $last_month!=$date_ary[1] ) {
			$last_year = $date_ary[0];
			$last_month = $date_ary[1];
			$wgOut->addWikiText('== '.$last_year.'-'.$last_month.' ==');
		}
	$wgOut->addHTML(
			formatEvent( $event['date'], $event['description'], $page_title )
		);
		$count++;
	}
	$dbr->freeResult( $res );
	# Display a message if there are no events.
	if (!$count) {
		$wgOut->addWikiText('No events found!');
	}
}
?>
LocalSettings.php[edit | edit source]

Add these lines at the end of LocalSettings.php :

include("extensions/events/Events.php");
include("includes/SpecialEvents.php");

Version >= 1.9.0[edit | edit source]

extensions/events/Events.php[edit | edit source]

--Mchansy 19:44, 6 March 2007 (UTC)

<?php
# MediaWiki Events version 0.2
# Copyright (c) 2005 Aran Clary Deltac
# http://arandeltac.com/MediaWiki_Events
# Modified by Sylvain Machefert
# http://meta.wikimedia.org/w/index.php?title=Events_Extension
# Distributed under that same terms as MediaWiki itself.

$wgExtensionFunctions[] = "wfEventsExtension";
$wgHooks['ArticleSave'][] = 'clearEvents' ;
$wgHooks['ArticleSaveComplete'][] = 'saveEvents' ;
global $events_buffer;
 
#-----------------------------------------------#
# Purpose   : Declare parser extensions.
function wfEventsExtension() {
        global $wgParser;
        $wgParser->setHook( "events", "eventsHook" );
}
 
#-----------------------------------------------#
# Purpose   : Display a list of events.
# Parameters: content, A list of events, one per line.
# Returns   : Events HTML.
function eventsHook( $content, $args = null, &$parser ) {
        global $events_buffer;
        $output = '';
        $local_parser = new Parser;
 
        clearEvents();
 	      addToEventBuffer($content);
 
        foreach ($events_buffer as $event) {
                $output .= formatEvent( 
                             $event['date'],
                             $event['description'],
                             '',
                             $parser
                             );
 
        }
        return $output;
}
 
#-----------------------------------------------#
# Purpose   : Add event to Buffer.
function addToEventBuffer( $content) {
 
        global $events_buffer;
 
        $events = preg_split("/[\n\r]+/", $content);
        foreach ($events as $event) {
        	if (preg_match('/^\s*([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}):\s*(.+)$/',$event,$matches)) {
                        $date = $matches[1];
                        $description = $matches[2];
 
                        $events_buffer[] = array(
                                'date' => $date,
                                'description' => $description,
                        );
                }
        }
}
 
#-----------------------------------------------#
# Purpose   : HTML format an event.
function formatEvent( $date, $description, $page='', &$parser) {
        global $wgOut;
        global $wgLang;
 
        $date_ary = explode( '-', $date );
        $date_out = $wgLang->date($date_ary[0] . $date_ary[1] . $date_ary[2], true);
        $date_daynum = date("w", mktime(0, 0, 0, $date_ary[1], $date_ary[2], $date_ary[0]));
        $date_day = $wgLang->getWeekdayName( $date_daynum + 1);
        $description = $date_day." '''".$date_out."'''  ".$description;
 
        if ($page) { 
        	$description .= ' ([['. $page .']])'; 
        }
 
        $parserOutput = $parser->parse($description, $parser->mTitle, $parser->mOptions, true, false);
        $output = $parserOutput->getText();
 
        return $output;
}
 
#-----------------------------------------------#
# Purpose   : Used before saveing a page to clear the events buffer.
function clearEvents() {    
        global $events_buffer;
        $events_buffer = array();
        return 1;
}
 
#-----------------------------------------------#
# Purpose   : Used after a page is saved to first delete 
#             all events and then save the new ones created 
#             in the events buffer.
# Parameters: article, The article object.
function saveEvents( &$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags) {
        global $events_buffer, $wgOut;
 
        $page_id = $article->getID();
        $wgOut->addHTML($output_item);
 
        $dbr =& wfGetDB( DB_SLAVE );
        $dbr->delete(
                'events',
                array( 'page_id' => $page_id )
        );
 
        # Rebuild the $events_buffer array (in case we're on a <calendar> page)
        clearEvents();
        $content = array(); $tags = array(); $params = array();
 
 
        $matches = array();
        $elements[] = 'Events';
 
        $text = Parser::extractTagsAndParams( $elements, $text, $matches );
        foreach( $matches as $marker => $data ) {
                list( $element, $content, $params, $tag ) = $data;
                addToEventBuffer($content);
        }
 
        foreach ($events_buffer as $event) {
                $event['page_id'] = $page_id;
                $dbr->insert(
                        'mw_events',
                        $event
                );
        }
        $events_buffer = array();
        return 1;
}
?>
includes/SpecialEvents.php[edit | edit source]

--Mchansy 19:44, 6 March 2007 (UTC)

<?php
# MediaWiki Events version 0.2
# Copyright (c) 2005 Aran Clary Deltac
# http://arandeltac.com/MediaWiki_Events
# Modified by Sylvain Machefert
# http://meta.wikimedia.org/w/index.php?title=Events_Extension
# Distributed under that same terms as MediaWiki itself.

require_once('SpecialPage.php');
$wgSpecialPages['Events'] = new SpecialPage ( 'Events' );
 
function wfSpecialEvents( $args_string = '' ) {
        global $wgOut;
	global $wgParser;
	global $wgLang;
 
        $page_titles = array();
        $dbr =& wfGetDB( DB_SLAVE );
        # Parse arguments.
        $args = array();
        foreach (explode('&',$args_string) as $pair) {
                $pair = explode('=',$pair);
                $args[$pair[0]] = $pair[1];
        }
        # Define options for the SQL.
        $options = array( 'ORDER BY'=>'date ASC' );
        if ($args['limit']) {
                $options['LIMIT'] = $args['limit'];
        }
        # Run the SQL.
        $res = $dbr->select(
                'events', 
                array('page_id','date','description'), 
                '(DATEDIFF(date,CURDATE()) <= 365 ) and (DATEDIFF(date,CURDATE()) >= 0)',
                'Database::select',
                $options
        );
        if (!$res) { return; }
 
        # Set the title for this page.
        $wgOut->setPageTitle( 'Ereignisse' );
 
        # Generate HTML list of events.
        $count = 0;
        $last_year = '0000';
        $last_month = '00';
        while ($event = $dbr->fetchRow( $res )) {
                $page_title = $page_titles[$event['page_id']];
                if (!$page_title) {
                        $page_titles[$event['page_id']] = Title::nameOf($event['page_id']);
                        $page_title = $page_titles[$event['page_id']];
                }
                $date_ary = explode( '-', $event['date'] );
                if ( $last_year!=$date_ary[0] or $last_month!=$date_ary[1] ) {
                        $last_year = $date_ary[0];
                        $last_month = $date_ary[1];
                        $last_month_name = $wgLang->getMonthName($last_month);
                        $wgOut->addWikiText('== '.$last_month_name.' '.$last_year.' ==');
                }
 
                $output_item = formatEvent( $event['date'], $event['description'], $page_title, $wgParser);
 
                $wgOut->addHTML($output_item);
                $count++;
        }
        $dbr->freeResult( $res );
        # Display a message if there are no events.
        if (!$count) {
                $wgOut->addWikiText('No events found!');
        }
}
?>
LocalSettings.php[edit | edit source]

--Mchansy 19:44, 6 March 2007 (UTC)

Add these lines at the end of LocalSettings.php :

require_once("extensions/events/Events.php");
require_once("includes/SpecialEvents.php");

Create the SQL table[edit | edit source]

Do not forget to add the prefixe to the table name !

Not quite clear what the warning in the previous line means; do you mean:

If you use a prefix for your MediaWiki MySQL tables, such as

mw_

then replace the line

CREATE TABLE events (

with

CREATE TABLE mw_events (

If this is what is meant, do you also need to change the code in the above php snippets? I'd be more accurate, but I'm not sufficiently familiar with PHP/MySQL

No, this isn't necessary because the prefix is specified during installation. so operating on a table in the database via medawiki-db-functions always appends the prefix in front of the tablename. 85.125.245.194 14:45, 12 July 2006 (UTC)


CREATE TABLE events (
    page_id INT(8) UNSIGNED NOT NULL DEFAULT 0,
    date DATE NOT NULL DEFAULT '0000-00-00',
    description TEXT NOT NULL,
    KEY date_idx (DATE)
);


All done !

License[edit | edit source]

This code is distributed under GPLv2 or higher.