Extension:DatabaseFetchHook.php
<?php
- Extension:DatabaseFetchHookTemplate:Php
- - See http://www.mediawiki.org/wiki/Extension:DatabaseFetchHook for installation and usage details
- - Started: 2007-03-05
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('DFH_VERSION','2.0.0, 2007-10-11');
$wgExtensionCredits['parserhook'][] = array( 'name' => "DatabaseFetchHook", 'author' => 'User:Nad', 'description' => 'Dynamically adds a new hook to intercept the database fetchObject and fetchRow methods', 'url' => 'http://www.mediawiki.org/wiki/Extension:DatabaseFetchHook', 'version' => DFH_VERSION );
- Create a LoadBalancer2 class by extending the existing LoadBalancer
$LoadBalancer = get_class($wgLoadBalancer); $LoadBalancer2 = $LoadBalancer.'2'; eval("class $eLoadBalancer2 extends $LoadBalancer".' {
# Override the getConnection method to return a secureDatabase connection function &getConnection($i, $fail = true, $groups = array()) { $db =& parent::getConnection($i,$fail,$groups);
# Create a secure subclass of the database class with extended fetchObject method $Database = get_class($db); $Database2 = $Database.'2'; if (!class_exists($Database2)) { eval("class $Database2 extends $Database ".\'{ function fetchObject($res) { $row = parent::fetchObject($res); wfRunHooks("DatabaseFetchHook", array(&$this,&$row)); return $row; } }\'); }
# Replace the DatabaseXXX connection with an identical secureDatabaseXXX connection $db2 = new $Database2; foreach(array_keys(get_class_vars($Database)) as $k) $db2->$k = $db->$k; unset($db);
return $db2; }
}');
- Replace the global LoadBalancer object with an identical instance of the new LoadBalancer2 class
$oldLoadBalancer = $wgLoadBalancer; $wgLoadBalancer = new $LoadBalancer2($oldLoadBalancer->mServers); foreach(array_keys(get_class_vars($LoadBalancer)) as $k) $wgLoadBalancer->$k = $oldLoadBalancer->$k; ?>