Most kidney stones are made of calcium oxalate and these are the ones I had. So I'll be focusing on preventing this type of kidney stones. Here's what I've found out.

Increase fluid intake - water and lemonade

The most fundamental nutrition change one can make is to drink more water. I've seen anywhere from 1.5 to 3 liters a day being recommended. The rule of thumb is to keep increasing water intake until one's urine is clear. If one can't do that with 3 liters a day, something must be wrong.

Another good liquid to ingest is lemon juice or lemonade (lemon juice plus water). The reason is that citric acid reacts with calcium and can dissolve stones that are forming in the kidneys. It's unclear whether it can reduce big stones or simply prevent smaller ones. And the amount of citric acid needed for this hasn't been established, so drinking lemon juice is beneficial, but should not be exaggerated.

Liquids to avoid (or reduce) are: black tea, colas, grapefruit juice and cranberry juice due to high oxalate contents (see below).

Maintain or increase calcium

Increasing natural calcium intake might be beneficial to stone formers, says current research. Even though calcium is a major part of the calcium oxalate stone, the stone is only formed with the calcium that is not expelled by the intestinal tract. That is, if not enough calcium is eaten with oxalate, the oxalate will bind with calcium in the kidneys instead of binding earlier in the intestines.

That means that when eating a salad (typically rich in oxalate), add some cheese or yogurt to it.

It's not clear that calcium supplementation is necessary. Some studies suggest it might be beneficial. If chosen to do so, don't do it at bedtime and prefer to take it with a meal during day time, according to this research, if taking calcium carbonate. The best form of calcium supplements for stone formers is probably calcium citrate due to its link with citric acid. It can be taken at any time.

Reduce sodium

Sodium competes with calcium for reabsorption in the kidneys and hence sodium and calcium contents in urine tend to increase and decrease together. Hence, a reduced sodium intake can prevent calcium from being expelled and hence reduce stone formation. This finding is supported by early research as well as more recent studies.

Control oxalate intake, meat

Oxalate is present in a lot of vegetables and nuts. A rigorous control of oxalate is difficult and possibly unnecessary as it would eliminate a lot of healthy foods. So, controlling the ingestion of foods deemed very rich in oxalate is important. Various lists abound online. The common items are spinach, rhubarb, nuts and some berries.

Avoiding meat can be helpful too since meat digestion produces uric acid, which lowers urine ph, which in turn is associated with higher risk of stone formation (see below).

Control urine ph

A goal for kidney stone formers should be to keep their urine ph neutral (close to 7). Mainly because that's what a neutral ph is and that's the level the kidneys are trying keep the blood at. If the blood is too acidic, the urine will be acidic. If it's too alkaline, the urine will be alkaline. To keep the kidneys from stressing too much, strive for a balanced diet that can keep the urine close to neutral (ph 7).

Foods that lower the ph (make it more acidic): meat products, cranberry juice.

Foods that raise the ph (make it more alkaline): citrus fruits and juices, vegetables, and dairy products. (source)

High protein intake (often associated with low-carbohydrate diets, such as Atkins) can lower the ph in urine and thus increase propensity of forming stones.

Potassium citrate is a type of salt that can raise urine ph and therefore might be beneficial against kidney stones. Research so far has only been conducted in children, with good results (extra citation). For supplementation, observe the RDA of 2g per day. The highest supplement amount allowed by the FDA is 100 mg though, which may not be enough for serious cases.

Testing the ph of urine is simple, safe and cheap. One can buy test strips and track urine ph over time, noting how changes in diet affect overall urine ph.

Further reading

Nephrolithiasis: Treatment, causes, and prevention

Kidney stones in adults

Strategies for preventing calcium oxalate stones

Dietary Supplement Fact Sheet: Calcium