Probably war weariness is completely defined by the following modifiers:
BASE_WAR_WEARINESS_MULTIPLIER (value 5, can be found in GlobalDefines.xml)
FORCED_WAR_WAR_WEARINESS_MODIFIER (value -50, can be found in GlobalDefines.xml)
MULTIPLAYER_WAR_WEARINESS_MODIFIER (value -50, can be found in GlobalDefines.xml)
WW_UNIT_KILLED_ATTACKING (value 3), WW_KILLED_UNIT_DEFENDING (value 1), WW_UNIT_KILLED_DEFENDING (value 2), WW_KILLED_UNIT_ATTACKING (value 2), WW_UNIT_CAPTURED (value 2), WW_CAPTURED_UNIT (value 1), WW_CAPTURED_CITY (value 6), WW_HIT_BY_NUKE (value 3), WW_ATTACKED_WITH_NUKE (value 12), WW_DECAY_RATE (value -1), WW_DECAY_PEACE_PERCENT (value 99), all found in GlobalDefines.xml
iAIWarWearinessPercent (value differs with difficulty level from 100 to 20 when difficulty level increases from settler to deity, can be found in CIV4HandicapIndo.xml)
iWarWearinessModifier (value differs with planet size from 50 to -50 when planet size increases)
I'll make a guess at what the formula for war weariness will look like. Note that this is a guess and not based on any research.
First calculate the sum of all causes for war weariness and call this variable WWpoints
Add 1 for each unit that you kill while attacking, add 2 for each unit that you kill while defending, add 3 for each unit that you lose while attacking, add 2 for each unit that you lose while defending, add 1 for each unit that you capture, add 2 for each unit that is captured from you, add 6 for each city from you that is captured (it could be that you also add 6 for every city that you capture, but I don't think so), add 3 for each nuke that hits you, add 12 for each nuke is used against you (whether it hits or not), subtract 1.
The basic idea for a formula: 100 points of war weariness causes 5 % of the population of a city to become unhappy. This is modified for the map size, the AI modifier, the fact if you declared war or got declared war on and if it is a multiplayer game or a single player game.
The variable AIWW is defined as (iAIWarWearinessPercent/100) if you're calculating the war weariness for the AI (a number between 0.2 and 1) and is defined as 1 if you're calculating the war weariness for a human player.
The variable WWsize is defined as (100+iWarWearinessModifier)/100. It is a number between 0.5 and 1.5.
The variable Multi is defined as 0.5 if you're playing a multiplayer game and 1 if you're playing a single player game.
The variable Forced is 0.5 if you were declared war on and 1 if you declared war yourself.
My guess for the formula (where a part of the formula between [ ] means rounding down):
New turns WW points = [ (Old turns WW points + [ [ [ [WWpoints * Forced] * WWsize] * Multi] * AIWW]) * 99/100]
War weariness in any city = [(WW Points /100) * 5/100 * City Size]
Note that there are some buildings and civics which decrease war weariness in a city by a certain percentage. But I guess that those effects are rather well known and don't require any further research.
Ok, this is my rather detailed guess.
And I really wouldn't be surprised if it was wrong.
I think that the part about war weariness points and the part that war weariness in a city is linked to the size of the city is correct.
Is someone willing to do some tests to find the real formula (instead of my wild guess)? A good test would be: how many AI units do you need to kill while attacking to get 1 unhappy citizen in a city of size 20. This would be done on a huge size world because I expect a nice world size modifier there.