Extension:InvadePrivacy

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
InvadePrivacy
Release status: beta
Implementation Special page
Description Lets you displays users' email addresses and/or real names via special pages
Author(s) Nathan Larson (Leucostictetalk)
Latest version 1.0.0 (2014-02-07)
MediaWiki 1.22+
PHP 5.3+
Database changes No
License GNU General Public License 3.0 or later
Download See the code section
Added rights
  • invadeprivacy
Translate the InvadePrivacy extension if it is available at translatewiki.net
Check usage and version matrix.

The InvadePrivacy extension lets you displays users' email addresses and/or real names via "Special:InvadePrivacy" and "Special:InvadePrivacy/user_real_name". By default, only bureaucrats have access to it.

Installation[edit]

  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/InvadePrivacy/InvadePrivacy.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit]

InvadePrivacy.php
<?php
/**
 * InvadePrivacy MediaWiki extension.
 *
 * Written by Leucosticte
 * https://www.mediawiki.org/wiki/User:Leucosticte
 *
 * 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 3 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.
 *
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @ingroup Extensions
 */

if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
        die( 1 );
}

$wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'InvadePrivacy',
        'author' => 'Nathan Larson',
        'url' => 'https://mediawiki.org/wiki/Extension:InvadePrivacy',
        'descriptionmsg' => 'invadeprivacy-desc',
        'version' => '1.0.0'
);

$wgExtensionMessagesFiles['InvadePrivacy'] = __DIR__ . '/InvadePrivacy.i18n.php';
$wgAutoloadClasses['SpecialInvadePrivacy'] = __DIR__ . '/SpecialInvadePrivacy.php';
$wgSpecialPages['InvadePrivacy'] = 'SpecialInvadePrivacy';
$wgGroupPermissions['bureaucrat']['invadeprivacy'] = true;
SpecialInvadePrivacy.php
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
   die( 'This file is a MediaWiki extension. It is not a valid entry point' );
}

class SpecialInvadePrivacy extends SpecialPage {
   function __construct( ) {
      parent::__construct( 'InvadePrivacy' );
   }

   public function userCanExecute( User $user ) {
      return true;
   }

   function execute( $par ) {
      $this->setHeaders();
      $viewOutput = $this->getOutput();
      $user = $this->getUser();
      if ( !$user->isAllowed( 'invadeprivacy' ) ) {
         throw new PermissionsError( null, array( array(
            'invadeprivacy-notallowed' ) ) );
      }
      $options = array( 'user_real_name' );
      if ( !in_array( $par, $options ) ) {
         $par = 'user_email';
      }
      $dbr = wfGetDB( DB_SLAVE );
      $res = $dbr->select( 'user', array ( 'user_name', $par ) );
      $resEmail = array();
      foreach ( $res as $row ) {
         if ( $par == 'user_email' ) {
            $resEmail[$row->user_email][] = $row->user_name;
         } else {
            $resEmail[$row->user_real_name][] = $row->user_name;
         }

      }
      ksort( $resEmail );
      $output = "{|class=\"wikitable\"\n|-\n!$par\n!User\n|-\n";
      foreach ( $resEmail as $key => $value ) {
         $count = count( $value );
         $output .= "|rowspan = \"$count\" | $key\n";
         foreach ( $value as $valueValue ) {
            $output .= "|$valueValue\n|-\n";
         }
      }
      $output .= "|}\n";
      $viewOutput->addWikiText( $output );
      return $output;
   }

   protected function getGroupName() {
      return 'other';
   }
}
InvadePrivacy.i18n.php
<?php
/**
 * Internationalization file for the InvadePrivacy extension.
 *
 * @since 1.0.0
 *
 * @file
 *
 * @licence GNU GPL
 * @author Nathan Larson (Leucosticte)
 */

$messages = array();

/** English
 * @author Nathan Larson (Leucosticte)
 */
$messages['en'] = array(
    'invadeprivacy' => 'Invade privacy',
    'invadeprivacy-desc' => "Implements [[Special:InvadePrivacy|a special page]] that displays a list of users' real names and/or email addresses",
    'invadeprivacy-notallowed' => 'Your account does not have permission to invade privacy.',
);