Menu Close

New Page Notification In Mediawiki

In trying to make my team aware of what’s in our team’s wiki (based on Mediawiki), I wanted a simple notification to go out to the team daily listing the new wiki pages created on the previous day. This may be achieved with a simple shell script that queries the Mediawiki recentchanges table.

STEP 1: Deploy Shell Script

The following script queries the recentchanges table and fetches data for pages created (rc_type = 1) the previous day in the Main namespace (rc_namespace = 0).

#!/bin/bash
# Author         :       Cybergavin (http://www.cybergav.in)
# Date Created   :       31st March 2012
# Description    :       This simple script queries the Wiki database and sends a notification to specific users regarding page creation. Reminds users about the existence of the wiki and what's in there.
#####################################################################################
#
# Variables
#
EMAIL_RECIPIENTS="wikiusers@abc.com"
REPORT_DATE=$(date '+%Y%m%d' --date="yesterday")
REPORT_DATE_FORMAIL=$(date '+%d-%b-%Y' --date="yesterday")
WIKI_BASEURL="http://wiki.abc.com/wiki/index.php/"
#
# Functions
#
getDBdata()
{
mysql -u wiki -p'xxxxx' --skip-column-names wiki <<EOSQL
connect wiki;
select rc_title, rc_user_text from recentchanges
where rc_timestamp like '$REPORT_DATE%'
and rc_type = 1
and rc_namespace=0;
quit
EOSQL
}
#
# Main
#
mail -s "Tech Ops Wiki : New Page Notification For $REPORT_DATE_FORMAIL" $EMAIL_RECIPIENTS <<EOMAIL
Hi

Given below are Pages created on the ABC Wiki ( http://wiki.abc.com ) yesterday ($REPORT_DATE_FORMAIL) along with their authors:

`getDBdata | awk -v a="$WIKI_BASEURL" '{printf "%-70s %s %s\n", a$1,"-", $2}'`

EOMAIL
#
##################################### T H E     E N D ###############################

NOTE:
(1) You must change certain variables and the body of the email as per your requirements.
(2) If your wiki isn’t updated with new pages very often, you may send this notification weekly. To do so, simply replace “yesterday” by “last week” on lines 11 and 12 and replace “where rc_timestamp like ‘$REPORT_DATE%'” by “where rc_timestamp > $REPORT_DATE0000”

STEP 2: Cron the Shell Script

Set up a cron job to send a daily notification. The example below executes the script daily at 9 AM.

0 9 * * * /opt/support/wikiPCnotify.sh > /opt/support/wikiPCnotify.out 2> /opt/support/wikiPCnotify.err 
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Print Friendly, PDF & Email
(Visited 50 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *