Difference between revisions of "Extension:ImageHistoryClear"

From Organic Design wiki
m
(Condition works, extension done)
Line 26: Line 26:
 
);
 
);
 
   
 
   
 +
/**
 +
* Regular expression to replace TOC, history and image information.
 +
*/
 +
 
function efImageHistoryClear (&$out) {
 
function efImageHistoryClear (&$out) {
  
 
$out->mBodytext = preg_replace ('%<ul id="filetoc">.+?</ul>%s','',$out->mBodytext);
 
$out->mBodytext = preg_replace ('%<ul id="filetoc">.+?</ul>%s','',$out->mBodytext);
$out->mBodytext = preg_replace ('%<h2 id="filehistory">.+?</ul>%s','',$out->mBodytext);
+
$out->mBodytext = preg_replace ('%<h2 id="filehistory".+$%s','',$out->mBodytext);
$out->mBodytext = preg_replace ('%<h2 id="filelinks">Links</h2>.+?</div>%s','',$out->mBodytext);
+
 
 
return true;
 
return true;
 
}
 
}
 
 
   
 
   
 
/**
 
/**
  * Called from $wgExtensionFunctions array when initialising extensions
+
  * Setup function specifies a condition for the user being anonymous and the page being an image page
 
  */
 
  */
 
function efSetupImageHistoryClear() {
 
function efSetupImageHistoryClear() {
global $wgHooks;
+
global $wgHooks,$wgUser;
$wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear';
+
$title = Title::newFromText($_REQUEST['title']);
+
#print_r($title);
 
+
if($title->getNamespace()==6 && $wgUser->isAnon())
 +
$wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear';
 
}
 
}

Revision as of 20:21, 29 October 2008

<?php /**

* ImageHistoryClear extension - A extension made with Template:Extension to strip the image history and links from image pages.
*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' => 'A extension made with Template:Extension to strip the image history and links from image pages.', 'url' => 'http://www.organicdesign.co.nz/Extension:ImageHistoryClear', 'version' => IMAGEHISTORYCLEAR_VERSION );

/**

* Regular expression to replace TOC, history and image information.
*/

function efImageHistoryClear (&$out) {

$out->mBodytext = preg_replace ('%

    .+?

%s',,$out->mBodytext); $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; $title = Title::newFromText($_REQUEST['title']); #print_r($title); if($title->getNamespace()==6 && $wgUser->isAnon()) $wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear'; }