Location: PHPKode > projects > BusinessWiki > extensions/Dashboard/RecentChanges.php
<?php

/**
 * MediaWiki RecentChanges extension
 */

if ( ! defined( 'MEDIAWIKI' ) )
	die( 1 );
	
$wgAutoloadClasses['RecentChangesDashboardTemplate'] = dirname(__FILE__) . '/RecentChangesDashboardTemplate.php';

$wgExtensionFunctions[] = 'wfRecentChangesBox';
$wgHooks['LanguageGetMagic'][] = 'wfRecentChangesBoxMagic';

function wfRecentChangesBox() {
	global $wgParser, $wgFavoritesMessages, $wgMessageCache;
	
	$wgParser->setHook( 'RecentChangesBox', 'RecentChangesBox' );
	
	$wgParser->setFunctionHook( 'rcbox', 'wfRecentChangesBoxGetHTML' );
	
	foreach ( $wgFavoritesMessages as $lang => $messages) {
		$wgMessageCache->addMessages( $messages, $lang );
	}	
}
 
function wfRecentChangesBoxMagic( &$magicWords, $langCode ) {
	$magicWords['rcbox'] = array( 0, 'rcbox' );

	return true;
}

function wfRecentChangesBoxGetHTML() {
    global $wgUser;
    
    $skin = $wgUser->getSkin();
    
    $data = RecentChangesBox::getData();
	
    $items = array();
	if ( !empty( $data ) ) {
	    foreach ( $data as $item ) {
			$namespace = $item['ns'];
			$type = $item['type']; /* edit, log, new etc.. */
			$logaction = ( $type == 'log' ) ? $item['logaction'] : '';
			$comment = isset( $item['comment'] ) ? $item['comment'] : '';
			
			$icon = RecentChangesBox::getChangeIcon( $namespace, $type, $logaction, $comment );
						
			$text = ( mb_strlen( $item['title'] ) > 14 )
			    ? mb_substr( $item['title'], 0, 13 ) . "&hellip;"
			    : $item['title'];
			    
			$items[] = array(
			    'title' => $icon['title'],
			    'icon' => $icon['file'],
			    'link' => $skin->link( RecentChange::newFromId( $item['rcid'] )->getTitle(), $text ),
			    'timestamp' => wfTimestamp( TS_DB, $item['timestamp'] ),
			    'user' => $skin->userLink( User::newFromName( $item['user'] )->getId(), $item['user'] )
			);
	    }
	}
	
	$template = new RecentChangesDashboardTemplate();
	$template->set( 'items', $items );
	
	return array( $template->fetch(), 'isHTML' => true );
    }
 
class RecentChangesBox {
	public function __construct() { }
	
	public static function getData() {
		$params = new FauxRequest( array(
	        'action' => 'query',
	        'list' => 'recentchanges',
			'show' => '!minor|!bot',
			'rcprop' => 'title|timestamp|user|ids|loginfo|comment',
			'rclimit' => 5
		) );
		
		$api = new ApiMain( $params );
		$api->execute();
		
		$data = $api->getResultData();
		
		return $data['query']['recentchanges'];
	}
	
	public static function getChangeIcon( $ns, $type, $action, $comment ) {
		switch ( $ns ) {
			case NS_MAIN:
				$iconObj = 'page'; break;
			case NS_USER:
				$iconObj = 'user'; break;
			case NS_IMAGE:
				$iconObj = 'file'; break;
			case NS_CATEGORY:
				$iconObj = 'folder'; break;
		}
		if ( empty( $iconObj ) ) {
			$iconObj = 'page';
		}
		switch ( $type ) {
			case 'new':
				$iconAction = 'create'; break;
			case 'edit':
				$iconAction = 'edit'; break;
			case 'move':
				$iconAction = 'move'; break;
			case 'log':
				$iconAction = $action; break;
		}
		
		if ( $comment == 'New comment' ) {
			list( $iconObj, $iconAction ) = array( 'comment', 'create' );
		}
		
		return array(
			'file' => "rc_{$iconObj}_{$iconAction}_16_white.png",
			'title' => ucfirst( $iconObj ) . ' ' . ucfirst( $iconAction )
		);
	}
}
Return current item: BusinessWiki