Difference between revisions of "Extension:ImageHistoryClear"
From Organic Design wiki
m |
|||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | <source lang="php"> | ||
<?php | <?php | ||
/** | /** | ||
− | * ImageHistoryClear extension - | + | * ImageHistoryClear extension - An extension to strip TOC, history and links information from image page views by anonymous users. Made with [http://www.organicdesign.co.nz/Template:Extension Template:Extension]. |
− | * | + | * |
* See http://www.mediawiki.org/wiki/Extension:ImageHistoryClear for installation and usage details | * See http://www.mediawiki.org/wiki/Extension:ImageHistoryClear for installation and usage details | ||
* | * | ||
Line 11: | Line 12: | ||
* @licence GNU General Public Licence 2.0 or later | * @licence GNU General Public Licence 2.0 or later | ||
*/ | */ | ||
+ | |||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
define('IMAGEHISTORYCLEAR_VERSION', '1.0.0, 2008-10-21'); | define('IMAGEHISTORYCLEAR_VERSION', '1.0.0, 2008-10-21'); | ||
− | + | $wgExtensionFunctions[] = 'efSetupImageHistoryClear'; | |
− | |||
− | $wgExtensionFunctions[] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
'name' => 'ImageHistoryClear', | 'name' => 'ImageHistoryClear', | ||
'author' => '[http://www.organicdesign.co.nz/wiki/User:Jack User:Jack]', | 'author' => '[http://www.organicdesign.co.nz/wiki/User:Jack User:Jack]', | ||
− | 'description' => ' | + | 'description' => 'An extension to strip TOC, history and links information from image page views by anonymous users. Made with [http://www.organicdesign.co.nz/Template:Extension Template:Extension].', |
'url' => 'http://www.organicdesign.co.nz/Extension:ImageHistoryClear', | 'url' => 'http://www.organicdesign.co.nz/Extension:ImageHistoryClear', | ||
'version' => IMAGEHISTORYCLEAR_VERSION | 'version' => IMAGEHISTORYCLEAR_VERSION | ||
); | ); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
/** | /** | ||
− | * | + | * Function called from the hook BeforePageDisplay, with a regular expression to replace TOC, history and image information. |
*/ | */ | ||
− | function | + | function efImageHistoryClear(&$out) { |
− | + | $out->mBodytext = preg_replace('%(<ul id="filetoc">.+?</ul>)(.*)(<h2 id="filehistory".+$)%s', '\2', $out->mBodytext); | |
− | + | return true; | |
+ | |||
} | } | ||
/** | /** | ||
− | * | + | * Setup function specifies a condition for the user being anonymous and the page being an image page |
*/ | */ | ||
− | function | + | function efSetupImageHistoryClear() { |
− | global $ | + | global $wgHooks, $wgUser, $wgRequest; |
− | $ | + | $title = Title::newFromText($wgRequest->getText('title')); |
− | + | if (is_object($title) && $title->getNamespace() == NS_IMAGE && $wgUser->isAnon()) | |
+ | $wgHooks['BeforePageDisplay'][] = 'efImageHistoryClear'; | ||
} | } | ||
+ | </source> | ||
+ | [[Category:Legacy Extensions]] |
Latest revision as of 16:40, 20 April 2018
<?php
/**
* ImageHistoryClear extension - An extension to strip TOC, history and links information from image page views by anonymous users. Made with [http://www.organicdesign.co.nz/Template:Extension Template:Extension].
*
* See http://www.mediawiki.org/wiki/Extension:ImageHistoryClear for installation and usage details
*
* @package MediaWiki
* @subpackage Extensions
* @author [http://www.organicdesign.co.nz/wiki/User:Jack User:Jack]
* @copyright © 2008 [http://www.organicdesign.co.nz/wiki/User:Jack 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' => '[http://www.organicdesign.co.nz/wiki/User:Jack User:Jack]',
'description' => 'An extension to strip TOC, history and links information from image page views by anonymous users. Made with [http://www.organicdesign.co.nz/Template:Extension 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('%(<ul id="filetoc">.+?</ul>)(.*)(<h2 id="filehistory".+$)%s', '\2', $out->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';
}