Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Majr25 committed Jul 2, 2012
1 parent 9ae1ef8 commit ebced2a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ExcludeRandom.i18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$messages = array();
$messages['en'] = array(
'excluderandom-desc' => 'Allows pages to be excluded from [[mw:Help:Random page|Special:Random]]',
);
50 changes: 50 additions & 0 deletions ExcludeRandom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* ExcludeRandom - this extension allows pages to be excluded from Special:Random
*
* To activate this extension, add the following into your LocalSettings.php file:
* require_once( '$IP/extensions/ExcludeRandom/ExcludeRandom.php' );
*
* @ingroup Extensions
* @author Matt Russell
* @version 0.1
* @link https://www.mediawiki.org/wiki/Extension:ExcludeRandom Documentation
* @license CopyLeft
*/

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

$wgExcludeRandomPages = null;

$wgHooks['SpecialRandomGetRandomTitle'][] = 'wfExcludeRandomInit';

/* Define extensions info */
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'ExcludeRandom',
'author' =>'[http://matt-russell.com Matt Russell]',
'url' => 'https://www.mediawiki.org/wiki/Extension:ExcludeRandom',
'descriptionmsg' => 'excluderandom-desc',
'version' => 0.1,
);

/* Define internationalisation file */
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['ExcludeRandom'] = $dir . 'ExcludeRandom.i18n.php';

function wfExcludeRandomInit( &$rand, &$isRedir, &$namespaces, &$extra, &$title ) {
GLOBAL $wgExcludeRandomPages, $dbr;
if ( !$wgExcludeRandomPages ) {
return true;
}

foreach ( $wgExcludeRandomPages AS $cond ) {
$escape = str_replace( array( ' ', '\\', '%', '_', '*', '\'' ), array( '_', '\\\\', '\%', '\_', '%', '\\\'' ), $cond );
$extra[] = "`page_title` NOT LIKE '$escape'";
}

return true;
}

0 comments on commit ebced2a

Please sign in to comment.