Difference between revisions of "Extension:ImageHistoryClear"

From Organic Design wiki
(condition)
(no need for nested if's)
Line 16: Line 16:
 
define('IMAGEHISTORYCLEAR_VERSION', '1.0.0, 2008-10-21');
 
define('IMAGEHISTORYCLEAR_VERSION', '1.0.0, 2008-10-21');
 
   
 
   
$wgExtensionFunctions[]       = 'efSetupImageHistoryClear';
+
$wgExtensionFunctions[] = 'efSetupImageHistoryClear';
  
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 39: Line 39:
 
  * Setup function specifies a condition for the user being anonymous and the page being an image page
 
  * Setup function specifies a condition for the user being anonymous and the page being an image page
 
  */
 
  */
 
 
function efSetupImageHistoryClear() {
 
function efSetupImageHistoryClear() {
global $wgHooks,$wgUser,$wgRequest;
+
global $wgHooks, $wgUser, $wgRequest;
 
$title = Title::newFromText($wgRequest->getText('title'));
 
$title = Title::newFromText($wgRequest->getText('title'));
if (is_object ($title)) {
+
if (is_object($title) && $title->getNamespace() == NS_IMAGE && $wgUser->isAnon())  
if($title->getNamespace()==NS_IMAGE && $wgUser->isAnon())  
 
 
$wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear';
 
$wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear';
}
 
 
}
 
}

Revision as of 20:18, 13 November 2008

<?php /**

* ImageHistoryClear extension - An extension to strip TOC, history and links information from image page views by anonymous users. Made with Template:Extension.
*Template:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.
* See http://www.mediawiki.org/wiki/Extension:ImageHistoryClear for installation and usage details
*
* @package MediaWiki
* @subpackage Extensions
* @author User:Jack
* @copyright © 2008 User:Jack
* @licence GNU General Public Licence 2.0 or later
*/

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('IMAGEHISTORYCLEAR_VERSION', '1.0.0, 2008-10-21');

$wgExtensionFunctions[] = 'efSetupImageHistoryClear';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'ImageHistoryClear', 'author' => 'User:Jack', 'description' => 'An extension to strip TOC, history and links information from image page views by anonymous users. Made with Template:Extension.', 'url' => 'http://www.organicdesign.co.nz/Extension:ImageHistoryClear', 'version' => IMAGEHISTORYCLEAR_VERSION );

/**

* Function called from the hook BeforePageDisplay, with a regular expression to replace TOC, history and image information.
*/

function efImageHistoryClear (&$out) {

$out->mBodytext = preg_replace ('%(

    .+?

)(.*)(

mBodytext);

return true;

}

/**

* Setup function specifies a condition for the user being anonymous and the page being an image page
*/

function efSetupImageHistoryClear() { global $wgHooks, $wgUser, $wgRequest; $title = Title::newFromText($wgRequest->getText('title')); if (is_object($title) && $title->getNamespace() == NS_IMAGE && $wgUser->isAnon()) $wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear'; }