Extension:RecentActivity

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear app error.png
RecentActivity

Release status: unstable

Implementation Parser function
Description Adds parser functions for listing recently created and edited articles.
Author(s) User:Nad
Last version 1.0.2 (2009-03-16)
MediaWiki all versions
License GPL
Download OrganicDesign

Check usage (experimental)

The RecentActivity extension allows the generation of lists of recently created articles or recent edits either by anyone, or by a specific user. By default it will give five results ordered by most recent first in a bullet list format. Here's some example usage:

[edit] Installation

  1. Grab the piece of code shown below and save it in a text editor as RecentActivity.php
  2. Upload the RecentActivity.php file in your extensions directory using your ftp client.
  3. Place the following text in your LocalSettings.php file: require_once("extensions/RecentActivity.php");
    (Make sure there's a semicolon (;) at the end of that line)

[edit] Usage

Show the last five articles that have been edited
{{RecentActivity:type=edits}}
Show the last five articles that have been created
{{RecentActivity:type=new}}
Show the last five articles that have been created by user Foo
{{RecentActivity:type=new|user=Foo}}
Show the last ten articles that have been edited
{{RecentActivity:type=edits|count=10}}
Show the last five articles that have been edited, each preceded by two asterisks (useful for putting in treeviews)
{{RecentActivity:type=edits|format=**}}


[edit] Source

<?php
/**
 * RecentActivity extension - Adds parser functions for listing recently created and edited articles
 *
 * 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', '1.0.4, 2009-03-29');
 
$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 ? 'rev_user_text = '.$dbr->addQuotes( $user ) : '';
                                $res  = $dbr->select(
                                        $tbl,
                                        'distinct rev_page',
                                        $user,
                                        __METHOD__,
                                        array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => $count )
                                );
                                while ( $row = $dbr->fetchRow( $res ) ) {
                                        $title = Title::newFromId( $row['rev_page'] );
                                        if ( is_object( $title ) ) {
                                                $page = utf8_decode( $title->getPrefixedText() );
                                                $items[] = $format."[[:$page|$page]]";
                                        }
                                }
                                $dbr->freeResult( $res );
                        break;
 
                        case 'new':
                                $dbr  = wfGetDB( DB_SLAVE );
                                $tbl  = $dbr->tableName( 'revision' );
                                $user = $user ? 'rev_user_text = '.$dbr->addQuotes( $user ) : '';
                                $res  = $dbr->select(
                                        $tbl,
                                        'rev_page, MIN(rev_id) as minid',
                                        $user,
                                        __METHOD__,
                                        array( 'GROUP BY' => 'rev_page', 'ORDER BY' => 'minid DESC', 'LIMIT' => $count )
                                );
                                while ( $row = $dbr->fetchRow( $res ) ) {
                                        $title = Title::newFromId( $row['rev_page'] );
                                        if ( is_object( $title ) ) {
                                                $page = utf8_decode( $title->getPrefixedText() );
                                                $items[] = $format."[[:$page|$page]]";
                                        }
                                }
                                $dbr->freeResult( $res );
                        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;
}
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox