Extension:BuddyPressActivity

From MediaWiki.org

Jump to: navigation, search


           

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
BuddyPressActivity

Release status: beta

Implementation  Notify, Database
Description In environments where MediaWiki user authentication has been merged with WPMu/BuddyPress signin, this extension adds wiki edits to the BuddyPress activity feeds.
Author(s)  Boone B. Gorges (boonebgorgesTalk)
Last Version  0.2
MediaWiki  1.13.4
License GPL
Download Extension:BuddyPressActivity#Code
Extension:BuddyPressActivity#Readme

check usage (experimental)

Contents

[edit] What can this extension do?

This extension writes page edits within MediaWiki to the activity feeds in BuddyPress. To use this plugin, you must enabled single signon across MediaWiki and Wordpress MU/Buddypress (as described on the dev blog of the CUNY Academic Commons).

[edit] Usage

Once the plugin is configured correctly, it work automatically with every MW page save.

Please note that a page save will only be written to the BP activity streams if that page has not been edited by the same user within the last 24 hours. This is to prevent the frequent saving of a wiki page from cluttering up the activity streams. This time period can be changed by altering $seconds_between > 86400 to a different number. In the future I will try to make this more easily configurable.

Depending on how fussy you are about the way that your activity streams look, you might want to make some changes to BuddyPress to streamline the way that MW activity items appear. For instance, in /[buddypress-directory]/bp-activity/bp-activity-templatetags.php, adding the following line

$content = preg_replace('|(edited the wiki page.+?</a>)(.+?ago)|', '$1<span class="time-since">$2</span>', $content);

to the end of each case of bp_get_activity_content(), will insert the "time-since" CSS selector to the activity sections of your BP profiles.

Version 0.2 fixes a few bugs related to the 24-hour filter.

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/buddypress-activity/buddypress-activity.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/buddypress-activity/buddypress-activity.php");

[edit] Configuration parameters

You will need to change the value of $wpmudp (in the code below) to match the name of your WPMu database.

[edit] User rights

[edit] Code

 <?php
/*
 * buddypress-activity -- In environments where MediaWiki user authentication has been merged with WPMu/BuddyPress signin, this extension adds wiki edits to the BuddyPress activity feeds.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @author Boone Gorges <boonebgorges@gmail.com>
 * @addtogroup Extensions
 */
 
 
if( !defined( 'MEDIAWIKI' ) ) {
	echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
	die( 1 );
}
 
 
 
 
 
$wgHooks['ArticleSaveComplete'][] = 'writeToBPActivity';
 
function writeToBPActivity($article, &$user, $text, $summary) {
 
 
$wpmudp = 'yourwpmudatabasename'; // Replace this with the name of your WPMu database
 
$docRoot = 'http://' . $_SERVER['HTTP_HOST'];
 
 
$time1 = time();
$time2 = time();
 
 
$page = $article->getTitle();
$rawtitle = $page->getPrefixedText();
$articleURL  = $page->getFullUrl();
 
 
 
$titleUS = str_replace(" ", "_", $rawtitle);
$titleUS = str_replace("&", "%26", $titleUS); 
 
$articleURL = $docRoot . '/wiki/index.php/' . $titleUS;
 
$userNameMW = strtolower($user->mName); // This block uses the MW login name to find the correct BP user ID for the DB entry
mysql_select_db($wpmudp) or die(mysql_error());
$result = mysql_query( "SELECT * FROM `wp_users` WHERE `user_nicename`='$userNameMW' LIMIT 0, 1" );
$resultarray = mysql_fetch_array($result);
$user_id = $resultarray['ID'];
 
$profileURL = $docRoot . '/members/' . $userNameMW;
 
mysql_select_db($wpmudp) or die(mysql_error()); // Gets the user's full name from the BP fields
$bpquery = mysql_query( "SELECT * FROM `wp_bp_xprofile_data` WHERE `user_id`='$user_id' AND `field_id`='1' LIMIT 0, 1" );
$bpresultarray = mysql_fetch_array($bpquery);
$bpname = $bpresultarray['value'];
 
$contentdesc = '<a href="' . $profileURL . '">' . $bpname . '</a> edited the wiki page <a href="' . $articleURL . '">' . $rawtitle . '</a>';
 
mysql_select_db($wpmudp) or die(mysql_error()); // checks to see if the same page has been edited by the same person in the last 24 hrs
$checkrecent = mysql_query( "SELECT * FROM `wp_bp_activity_sitewide` WHERE `content`='$contentdesc' ORDER BY `id` DESC LIMIT 0, 1" );
$checkRecentArray = mysql_fetch_array($checkrecent);
$checkRecentDate = $checkRecentArray['date_recorded'];
$checkRecentDateUNIX = strtotime($checkRecentDate);
$seconds_between = $time1 - $checkRecentDateUNIX;
 
if ($seconds_between > 86400) {
	mysql_select_db($wpmudp) or die(mysql_error());
	mysql_query( "INSERT INTO `wp_bp_activity_sitewide` (`user_id`,`content`, `date_cached`, `date_recorded`, `component_name`, `component_action`, `primary_link`, `secondary_item_id`) VALUES ( '$user_id', '$contentdesc', FROM_UNIXTIME('$time1'), FROM_UNIXTIME('$time2'), 'blogs', 'new_blog_post', '$articleURL', '0' )") or die(mysql_error()); // insert into sitewide feed
	mysql_query( "INSERT INTO `wp_bp_activity_user_activity` (`item_id`, `secondary_item_id`, `user_id`, `component_name`, `component_action`, `date_recorded`, `is_private`, `no_sitewide_cache`) VALUES ( '46', '0', '$user_id', 'blogs', 'new_blog_post', FROM_UNIXTIME('$time1'), '0', '0' )") or die(mysql_error()); // insert into user_activity
	mysql_query( "INSERT INTO `wp_bp_activity_user_activity_cached` (`user_id`,`content`, `date_cached`, `date_recorded`, `component_name`, `component_action`, `primary_link`, `secondary_item_id`, `is_private`) VALUES ( '$user_id', '$contentdesc', FROM_UNIXTIME('$time1'), FROM_UNIXTIME('$time2'), 'blogs', 'new_blog_post', '$articleURL', '0', '0' )") or die(mysql_error()); // insert into user activity cache	
}	
 
 
return true;
}
 
$wgExtensionCredits['other'][] = array(
        'path' => __FILE__,
	'name' => 'BuddyPressActivity',
	'version' => 0.1,
	'author' => 'Boone Gorges',
	'url' => 'http://www.mediawiki.org/wiki/Extension:BuddyPressActivity',
	'description' => 'Adds MW page edits to BuddyPress activity streams.',
	'descriptionmsg' => 'foobar-desc',
);