If you look to the entry for the Noggenfogger Elixir's spell (http://www.wowhead.com/?spell=16589) you will see that it has the effect Dummy. If you look through SpellEffects.cpp, you will eventually come across void Spell::EffectDummy(uint32 i) scroll through this, and you will find this code:
case 16589: // Noggenfogger Elixir
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
return;
uint32 spell_id = 0;
switch(urand(1, 3))
{
case 1: spell_id = 16595; break;
case 2: spell_id = 16593; break;
default:spell_id = 16591; break;
}
m_caster->CastSpell(m_caster, spell_id, true, NULL);
return;
}
As you can see, it randomly selects one of the effects spells for the Noggenfogger Elixir and applies it to the player. This is basically how it's done: spells that need server-side scripting are scattered about in the spell files of the server. You can usually find them by looking up their effects.
There are a few exceptions, however. Spells with the effect Script are done in the database. Dummy spells can be scripted with an external scripting module (only master branch, not mangos-0.12)