Extension:Notified User

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Notified User

Release status: beta

Implementation Notify
Description Gives the possibility to see the users notified to an article
Author(s) Christian Klugesherz
Last version Source attached to article (2008-08-05)
MediaWiki 1.0
License No license specified
Download No link
Parameters

lang="English",...

Check usage (experimental)

Extension:Notified User allows all users to have a list of the users who are notified to an article.

On each article you will find a tag "notified users" which gives the users list which are notified to this article

Contents

[edit] Installation

Copy the php source below to your extensions directory. Then include it in your LocalSettings.php file as in the following example.

include ("$IP/extensions/NotifiedUser/NotifiedUser.php");
$wgNotifiedUserActionLink = 'Notified Users';

[edit] Example

[edit] Tag

NotifiedUser00.jpg


[edit] Result

NotifiedUser01.jpg

[edit] Source code

<?php
# Extension:NotifiedUser
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: Christian Klugesherz
# - See http://www.mediawiki.org/wiki/Extension:NotifiedUser for installation and usage details
# - Started: 2008-07-23 
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
define('NotifiedUser_VERSION','1.0.0, 2008-07-23');
 
//-----------------------------------------------------------------
// Variables
//-----------------------------------------------------------------
 
// Link Title
$wgNotifiedUserActionLink = 'Notified Users'; 
 
// For Debug: log on if set to true
$wgNotifiedUserDebug = false;       
$wgNotifiedUserDebugFile = "c:\debug.txt";
 
// Mediawiki variables
$wgExtensionFunctions[] = 'wfSetupNotifiedUser';
 
$wgExtensionCredits['specialpage'][] = array(
        'name'        => 'Special:NotifiedUser',
        'author'      => 'Christian Klugesherz',
        'description' => 'Display the Notified Users for a specific Article',
        'url'         => 'http://www.mediawiki.org/wiki/Extension:NotifiedUser',
        'version'     => NotifiedUser_VERSION
        );
 
//-----------------------------------------------------------------
// action links
//-----------------------------------------------------------------
 
$wgHooks['SkinTemplateTabs'][] = 'wfNotifiedUserActionLink';
function wfNotifiedUserActionLink(&$skin,&$actions) 
{
        global $wgNotifiedUserActionLink,$wgTitle;
        if (is_object($wgTitle)) 
        {
                $url = Title::makeTitle(NS_SPECIAL,'NotifiedUser')->getLocalURL('nu_title='.$wgTitle->getPrefixedText());
                $actions['NotifiedUser'] = array('text' => $wgNotifiedUserActionLink, 'class' => false, 'href' => $url);
        }
        return true;
}
 
//=======================================================================================
// handles the debug output to a debug file
//=======================================================================================
function debug_nu($input)
{
        global $wgNotifiedUserDebug;
        global $wgNotifiedUserDebugFile;
        if ($wgNotifiedUserDebug)
        {
                $f = fopen($wgNotifiedUserDebugFile, "a+");
                fputs($f, $input."\r\n");
                fclose($f);
        }
} 
 
//=======================================================================================
# Define a new class based on the SpecialPage class
//=======================================================================================
require_once("$IP/includes/SpecialPage.php");
class SpecialNotifiedUser extends SpecialPage 
{
        //-----------------------------------------------------------------
        # Constructor
 //-----------------------------------------------------------------
        function SpecialNotifiedUser() 
        {
                SpecialPage::SpecialPage('NotifiedUser','');
        }
 
        //-----------------------------------------------------------------
        # Override SpecialPage::execute($param = '')
 //-----------------------------------------------------------------
        function execute($param) 
        {
                global $wgOut;
                $param = str_replace('_',' ',$param);
                $this->setHeaders();
 
                # Get info from request or set to defaults
         $this->title = isset($_REQUEST['nu_title']) ? $_REQUEST['nu_title'] : $param;
 
                # Bail if no article title to send has been specified
         if ($this->title) 
                {
                        $wgOut->addWikiText(wfMsg('nu_heading',$this->title));
                }
                else 
                {
                        return $wgOut->addWikiText(wfMsg('nu_noarticle'));
                }
 
                # Render form
         $special = Title::makeTitle(NS_SPECIAL,'NotifiedUser');
 
                $wgOut->addHTML('<fieldset><legend>'.wfMsg('nu_founduserlist').'</legend>');
 
                # Collect information
         // Les Tables Wiki sont : http://www.mediawiki.org/wiki/Category:MediaWiki_database_tables
                // http://www.mediawiki.org/wiki/Manual:Database_access
                // Liste Name space:
                // http://meta.wikimedia.org/wiki/Help:Namespace#Namespace_uses
                // La requête à faire est
                //  Trouver les users notifié sur une article (Il peuvent apparaitre plusieurs fois)
                //  Exemple
                //  SELECT wl_user FROM `watchlist` WHERE wl_title= 'SIP'
                //  Le nom de l'utilisateur est:
                //  SELECT user_name FROM `user` WHERE user_id = "1"
 
                $db  = & wfGetDB(DB_SLAVE);
                $wl  = $db->tableName('watchlist');
 
                // Remove: ':' example user:Christian Klugesherz
                if (strripos($this->title, ":") === false)
                {
                        $wl_title = str_replace(' ','_',$this->title);
                }
                else
                {
                        $wl_title = str_replace(' ','_',$this->title);
                        $wl_title = substr(strrchr($wl_title, ":"), 1);
                }
 
                $wl_query = "SELECT wl_user FROM $wl WHERE wl_title= '$wl_title'";
                debug_nu($wl."Query=".$wl_query);
                $result = $db->query($wl_query);
 
                $u  = $db->tableName('user');
 
                $onshot = "-100";
                while ( $row = $db->fetchRow( $result ) ) 
                {
                        debug_nu("   ".$wl."wl_user =".$row[0]);
 
                        if ($onshot != $row[0])
                        {
                                $onshot = $row[0];
                                $u_query = "SELECT user_name FROM $u WHERE user_id= '$row[0]'";
                                debug_nu("          ".$u."Query=".$u_query);
                                $u_result = $db->query($u_query);
                                $urow = $db->fetchRow( $u_result );
                                $wgOut->addWikiText($urow[0]) ;
                                debug_nu("          ".$u."user =".$urow[0]);
                        }
                }
                debug_nu(" ");
 
                $db->freeResult( $result);
                if ($row) 
                {
                        $db->freeResult( $u_result);
                }
 
                # ------ End Collect 
         
                $wgOut->addHTML('</fieldset>');
 
                $wgOut->addWikiText(wfMsg('nu_back',$this->title));
 
        }
}
 
//=======================================================================================
# Called from $wgExtensionFunctions array when initialising extensions
//=======================================================================================
function wfSetupNotifiedUser() 
{
        global $wgLanguageCode,$wgMessageCache;
 
        //debug_nu($wgLanguageCode);          
 
        # Add the messages used by the specialpage
 if ($wgLanguageCode == 'en') 
        {
                $wgMessageCache->addMessages(array(
                        'notifieduser'        => "Notified Users",
                        'nu_heading'          => "====Notified Users for article: [[$1]]====",
                        'nu_noarticle'        => "Please specify an article, for example [[Special:NotifiedUser/Main Page]].",
                        'nu_back'             => "Back to Article '''[[$1]]'''",
                        'nu_founduserlist'    => "List",
                ));
        }
 
        # Add the specialpage to the environment
 SpecialPage::addPage(new SpecialNotifiedUser());
 
}
 
//=======================================================================================
//=======================================================================================
//=======================================================================================
 
?>

[edit] Improvements

  • For the list of user, I get and hold the first wl_user in the wathchlist database that I found. Another solution (and better solution) could be to get the namespace of the article, and to make in wathchlist database a mysql query with article name and namespace: ==> Only one result

Any help to find the namespace would be appreciated

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox