Difference between revisions of "Extension:RecentActivity"

From Organic Design wiki
(Created page with '<?php /** * RecentActivity extension - Adds parser functions for listing recently created and edited articles *{{Category:Extensions|RecentActivity}}{{php}}{{Category:Extension...')
 
(moved to svn)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<?php
+
{{svn|extensions|RecentActivity/RecentActivity.php}}
/**
 
* RecentActivity extension - Adds parser functions for listing recently created and edited articles
 
*{{Category:Extensions|RecentActivity}}{{php}}{{Category:Extensions created with Template:Extension}}
 
* See http://www.mediawiki.org/wiki/Extension:RecentActivity for installation and usage details
 
*
 
* @package MediaWiki
 
* @subpackage Extensions
 
* @author [http://www.mediawiki.org/wiki/User:Nad User:Nad]
 
* @copyright © 2007 [http://www.mediawiki.org/wiki/User:Nad User:Nad]
 
* @licence GNU General Public Licence 2.0 or later
 
*/
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
 
define('RECENTACTIVITY_VERSION', '0.0.0, 2009-03-13');
 
 
$egRecentActivityMagic        = "RecentActivity";
 
$wgExtensionFunctions[]        = 'efSetupRecentActivity';
 
$wgHooks['LanguageGetMagic'][] = 'efRecentActivityLanguageGetMagic';
 
 
$wgExtensionCredits['parserhook'][] = array(
 
'name'        => 'RecentActivity',
 
'author'      => '[http://www.mediawiki.org/wiki/User:Nad User:Nad]',
 
'description' => 'Adds parser functions for listing recently created and edited articles',
 
'url'        => 'http://www.mediawiki.org/wiki/Extension:RecentActivity',
 
'version'    => RECENTACTIVITY_VERSION
 
);
 
 
class RecentActivity {
 
 
 
function __construct() {
 
global $wgParser, $egRecentActivityMagic;
 
$wgParser->setFunctionHook($egRecentActivityMagic, array($this, 'expandMagic'), SFH_NO_HASH);
 
}
 
 
 
function expandMagic(&$parser) {
 
 
 
# Populate $argv with both named and numeric parameters
 
$argv = array();
 
foreach (func_get_args() as $arg) if (!is_object($arg)) {
 
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg;
 
}
 
$type  = isset($argv['type'])  ? strtolower($argv['type']) : '';
 
$user  = isset($argv['user'])  ? $argv['user']  : false;
 
$count  = isset($argv['count'])  ? $argv['count']  : 5;
 
$format = isset($argv['format']) ? $argv['format'] : '*';
 
 
 
# Build the list
 
$items = array();
 
switch ($type) {
 
 
 
case 'edits':
 
$dbr  = wfGetDB( DB_SLAVE );
 
$tbl  = $dbr->tableName( 'revision' );
 
$user = $user ? $dbr->addQuotes( $user ) : '';
 
#select rev_page,max(rev_id) as maxid from revision group by rev_page order by maxid desc limit 5;
 
$res  = $dbr->select(
 
$tbl,
 
'distinct rev_page',
 
$user,
 
__METHOD__,
 
array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => $count )
 
);
 
while ( $row = $dbr->fetchRow( $res ) ) {
 
$page = Title::newFromId($row['rev_page'])->getPrefixedText();
 
$items[] = $format."[[$page]]";
 
}
 
break;
 
 
 
case 'new':
 
break;
 
 
 
default: $items[] = 'Bad activity type specified!';
 
}
 
 
 
return join("\n", $items);
 
}
 
}
 
 
 
/**
 
* Called from $wgExtensionFunctions array when initialising extensions
 
*/
 
function efSetupRecentActivity() {
 
global $egRecentActivity;
 
$egRecentActivity = new RecentActivity();
 
}
 
 
 
/**
 
* Register magic words
 
*/
 
function efRecentActivityLanguageGetMagic(&$magicWords, $langCode = 0) {
 
global $egRecentActivityMagic;
 
$magicWords[$egRecentActivityMagic]  = array($langCode, $egRecentActivityMagic);
 
return true;
 
}
 

Latest revision as of 19:01, 25 May 2012

Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.