How to Reset your MediaWiki Admin Password

So for some strange reason, it just took me a good 20minutes to find an article on Google to tell me how to reset the Mediawiki admin password (because yes .. I forgot it). Some articles mentioned using phpMyAdmin to edit the users table directly, however the password is stored in a TinyBLOB format – so I had no clue.

Luckily I finally found a way to reset the Admin password!

You’ll need shell/SSH access for this procedure to work.

1) Login to your media wiki installation
2) Then type the following;

cd maintenance
php changePassword.php --user=Admin --password=tada321$

This will change the “Admin” user’s password to “tada321$” ! I then highly suggest you login to MediaWiki and change the password to something more secure/familiar :D

How to Bootstrap PHP Code

So what the heck is this Bootstrap PHP thing anyway?

Bootstrap means to load a small program that eventually calls the desired program into the computer, similar to an operating system being called by a BIOS program. The word bootstrap also has different meaning in different fields like science, medical, etc.

With regards to computer technology, “bootstrap PHP code” means creating a bootstrapper that handles all the dynamic requests coming to a server and apply the true MVC (Model View Component) framework so that in future you can change the functionality for each unique component or application without changing the entire code or application.

Below you will find some steps to get the process started;

1. Go to the home directory of your website and create a “Website_Src” folder and put all your application files inside it.

2. Inside the “Website_Src” directory, create an index.php file and add the following code to it.

class index
	public function _construct()

	public function index($args)
		echo 'This is default index page visible to every request that can’t be routed';

3. Now, create a second file and name it “welcome.php” & add the following lines of code to it.

class welcome
	public function _construct()
	public function index($args)
		// redirecting it to test function()

	public function test($args)
		if (isset($args[0] )) echo $args[0];
		if (isset($args[1] )) echo ' '.$args[1];

4. Now, create a “.htaccess” file (if you don’t already have one) and add the following code to it. This will allow only specific characters in URI.

Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_/ ] )$ index.php?route=$1 [L,QSA]

5. Finally, paste the following code into you “index.php” file present in the “public_html” directory and test your bootstrap php code by clicking on your website link say:

// This bootstrap php code will work only with php5 with no template engine.
// Stops from reporting any error

// This is the folder where all your application files are present.
define('CLASSDIR', ' Website_Src ');

// Absolute path to the source files, just one level behind public folder
define('BASEDIR', @realpath( dirname (__FILE__).'/../'.CLASSDIR).'/' );
// Automatic loading of classes by using a function so that you can get rid of all include() calls.

function _autoload($class)
	$file = BASEDIR.$class.'.php';
	if (!file_exists ($file) )
		echo 'Requested module ''.$class.'' is missing. Execution stopped.';

// breaking requesting URI to parts & retrieving the specific arguments, methods & class
$route = '';
$class = '';
$method = '';
$args = null;
$cmd_path = BASEDIR;
$fullpath = '';
$file = '';

if (empty($_GET['route']) ) $route = 'index'; else $route = $_GET['route'];
$route = trim($route, '/\');
$parts = explode('/', $route);

foreach($parts as $part)
	$part = str_replace('-', '_', $part);
	$fullpath .= $cmd_path.$part;

	if (is_dir($fullpath))
		$cmd_path .= $part.'/';

	if (is_file($fullpath.'.php') )
		$class = $part;

if (empty($class) ) $class = 'index';
	$action = array_shift($parts);
	$action = str_replace('-', '_', $action);

if (empty($action) ) $action = 'index';
	$file = $cmd_path.$class.'.php';
	$args = $parts;

// now that we have the parts , let's run a few more test and then execute the function in the class file
if (is_readable($file) == false)
	echo 'Requested module ''.$class.'' is missing. Execution stopped.';

// load the requested file
$class = new $class();

if (is_callable(array($class, $action) ) == false )
	// function not found in controller , set it as index and send it to args
	array_unshift($args, $action);
	$action = 'index';

// Run Action


Adsense inline your WordPress Blog posts

I stumbled upon this very handy guide on how to insert an adsense ad unit after the first post on your wordpress blog.

To do this you will need to be able to edit the template files, specifically the “index.php” file.
The guide uses a simple PHP if statement to count the number of posts and insert the adsense code after the first post (or second or third etc).

Open up the template file index.php in your favourite text editor and add this to the top.

In the index file there is a “while” loop that grabs all the needed wordpress posts.
It starts with this

and ends with

Just before this “endwhile” statement, we need to add some code.

And your done!

Read more about tips on adding Adsense to your blog.

PHP Dynamic Checkboxes

I noticed the lack of tutorials or articles when using checkboxes in a dynamic form, so I thought I’d post some code I used recently to manage deleting rows. The thing most people forget isthat the checkbox field name has to have a [] on the end as this tells PHP to use an array and not a normal variable to hold the information.

if ($_REQUEST["btnDelete"])
	foreach ($_REQUEST["chkDelete"] as $value) {
	     echo $value;


d> "; echo " "; echo " "; echo ""; } ?>

Form Validation – HTML Tag stripping

This short article will talk about protecting your web forms from users who may try to exploit your website by entering in HTML into a text box.

Validation is something all web coders should think about as it protects the end user from making mistakes and protects your website from malicious attacks.

The following code uses the “htmlspecialchars” PHP function to strip all HTML tags from the entered data and then puts back what is allowed according to what YOU set.

!i', create_function('$matches','return str_replace(array(">", "<", """, "&"), array(">", "<", "\"", "&"), $matches[0]);'), $content);

Squirrelmail error You must be logged in to access this page

I came across a problem where squirrelmail kept reporting to me You must be logged in to access this page. I thought it was a cookie problem so I spent ages trying to debug PHP and apache.

The problem was that the server didnt have IMAP installed. Squirrelmail is an IMAP client only.

On debian do the following and you should be right!

apt-get install uw-imapd