electrical wiring concern
This answer is for North America, with U. S. wiring colors.

Do not attempt this unless you are confident you can learn the path and purpose of every wire. You should use both a continuity tester and a voltage detector, such as a small light bulb, that draws some actual power from the circuit under test. 

You are looking at a ceiling junction box with three cables, each with a ground (bare, green, or green/yellow), white, and black wire. Most likely BUT TEST TO MAKE SURE one cable is the power source, one goes to the switch, and one continues on to deliver to another junction box. 

You need to figure out which cable is which. 



First -- with the power on, carefully test each black &amp; white pair for the presence of line voltage. One of these pairs will light your lamp; the other two will not. If you get any other result, stop and call an electrician. Remember which pair has power. Turn off the circuit breaker again. 

Next -- use your continuity tester to find which cable goes to the switch. You don't need to disconnect the switch for this, but it's easier if you turn it off. 

The remaining cable continues to the next junction box and provides power to another part of your house. You should have noticed by now that some of your outlets and lights stopped working when you ripped these wires apart. If you do not see this condition, stop and call an electrician. Use your continuity checker to prove that this cable is connected to the dead outlets and lights. 

When you are very confident that you know what loads are powered by this cable, connect it to the power cable, white to white and black to black, and flip on the circuit breaker. Check that the dead outlets and lights are now working. If you get any other result, stop and call an electrician. 

Turn off the circuit breaker.

Now connect all the grounds together. I like to include a connection to the junction box, if it is metal. 

Connect the white wire from the switch to the black wire from the fixture. Mark both ends of this white wire with colored paint or tape. 

Connect all the remaining white wires together. 

Connect all the remaining black wires together. 

You should end up wired like this: