Manual talk:Hooks

This page and it's sub-pages were originally created from information contained at MediaWiki Hooks and their Parameters. --HappyDog 23:48, 17 January 2006 (UTC)

It has subsequently used information from hooks.txt (part of the docs bundled with MediaWiki, and previously called hooks.doc).

Correct up to 1.6.3
I have done a thorough search through all versions of MediaWiki from v1.4.0 (where hooks were first introduced) up to 1.6.3 and included all hooks that I found (there were many that had so far been missed) and updated the version numbers for existing hooks, most of which were wrong.

There is still a lot to do here, in particular:
 * I have no idea what a lot of the new hooks are for, or what arguments they take, as they are not documented anywhere. This information needs filling in, and (where necessary) new sub-pages created.
 * I have made some guesses about the function of some of the hooks when placing them in the top table. Feel free to rearrange these.  We may also want to split up some of the larger groups.
 * The version numbers on the sub-pages need updating to reflect the correct version numbers on this page. DONE --HappyDog 15:43, 15 April 2006 (UTC)

These lists are now fully complete up to MediaWiki 1.6.3 and all listed version numbers are now correct. Note that unreleased/beta/development versions of the software have been ignored - the version numbers here reflect when the hook was introduced into the public stable version of the software.

--HappyDog 05:42, 15 April 2006 (UTC)


 * I ran "grep -R wfRunHooks *" on the source for 1.6.7 and then manually crossed off everything already referenced in the text of this page, and I saw no new ones. I assume this is complete. I did not see any wfRunHooks calls that passed a non-constant event (i.e., dynamically called). Is this sufficient to call it good for 1.6.7? - Grubber 02:40, 6 December 2006 (UTC)


 * I've done the same process for 1.6.8, 1.7.0, 1.7.1, 1.8.0, 1.8.1, and 1.8.2. I have inserted the roughly 5 missing ones and marked the text complete up to 1.8.2. - Grubber 03:54, 6 December 2006 (UTC)


 * Thank you! --HappyDog 13:19, 6 December 2006 (UTC)

Writing an event handler
If you want the object to be passed by reference, preceed it with a "&". Otherwise, the event handler will work with a copy of your object.

More Robust ldapLogin Function
mailto:jon@myrealmail.net

This function is a bit more robust that the example given in the main document.

Simply set some LDAP server variables like this:

$ldap['server'] ="ldaps://myldap.company.com:636"; $ldap['base']   = "o=company"; $ldap['admindn'] = "cn=read,o=company"; $ldap['adminpw'] = "readPassword";

Then call ldapLogin:

$loginOK = ldapLogin ($ldap['server'], $ldap['base'], $username, $password, $ldap['admindn'], $ldap['adminpw']);

 function ldapLogin ( $server, $base, $username, $password, $admindn="", $adminpw="" ) {       # Create a filter that will find objects in most LDAP servers and AD        $filter = "(|(uid=". $username. ")(cn=". $username. ")(samAcountname=". $username. "))";

# Connect to the LDAP server $ds=ldap_connect($server); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); # Force Version 3 Protocol

if (! $ds) {               print ("Unable to connect to LDAP server $server"); return (FALSE); }

# If we can't bind as anonymous to search LDAP, us the $admindn/$adminpw credentials if ( $admindn != "" ) {               $bind=ldap_bind($ds, $admindn, $adminpw); if ( ! $bind ) {                       print ("Unable to bind as admin user $admindn to search"); ldap_close ($ds); return (FALSE); }       }        else # Bind anonymously {               $bind=ldap_bind($ds); if ( ! $bind ) {                       print ("Unable to bind as anonymous user to search $server"); ldap_close ($ds); return (FALSE); }       }

# Search for the $userid using the filter and the search base $sr=ldap_search($ds, $base, $filter); if ( ! $sr ) {               print ("Unable to perform search: $server, base=$base, filter=$filter"); ldap_close ($ds); return (FALSE); }

# Return the entries we found $info = ldap_get_entries($ds, $sr);

# If we get 0 entries, no userid match if ( $info["count"] == 0 ) {               print ("Can't find object $username!"); ldap_close ($ds); return (FALSE); }

# If we get more than one entry, our search is too loose? if ( $info["count"] > 1 ) {               print ("Found more than one $username, set the search base differently?"); ldap_close ($ds); return (FALSE); }

# We have one entry, get the DN       $dn = $info[0][dn];

# Close this connection ldap_close ($ds);

# Open a new connection $ds=ldap_connect($server); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); # Force Version 3 Protocol if (! $ds) {               print ("Unable to connect to LDAP server $server"); return (FALSE); }

# Bind as the user's DN with password $bind=ldap_bind($ds, $dn, $password); if ( $bind ) {               ldap_close ($ds); return (TRUE); }

ldap_close ($ds); return (FALSE); } 

ArticleFromTitle hook
Does anyone know from which file this hook is called? Nazly.elshazly 14:25, 29 January 2007 (UTC)

A grep shows it in Wiki.php (in 1.8.2) --Eric Myers 15:30, 3 March 2007 (UTC)

static function calls?
Are static calls like myclass::myfunction possible?