This paper reviews the present understanding of the origin of ferromagnetic response that has been detected in a number of diluted magnetic semiconductors (DMS) and diluted magnetic oxides (DMO) as well as in some nominally magnetically undoped materials. It is argued that these systems can be grouped into four classes. To the first belong composite materials in which precipitations of a known ferromagnetic, ferrimagnetic or antiferromagnetic compound account for magnetic characteristics at high temperatures. The second class forms alloys showing chemical nano-scale phase separation into the regions with small and large concentrations of the magnetic constituent. Here, high-temperature magnetic properties are determined by the regions with high magnetic ion concentrations, whose crystal structure is imposed by the host. Novel methods enabling a control of this spinodal decomposition and possible functionalities of these systems are described. To the third class belong (Ga,Mn)As, heavily doped p-(Zn,Mn)Te, and related semiconductors. In these solid solutions the theory built on p-d Zener's model of hole-mediated ferromagnetism and on either the Kohn-Luttinger kp theory or the multi-orbital tight-binding approach describes qualitatively, and often quantitatively, thermodynamic, micromagnetic, optical, and transport properties. Moreover, the understanding of these materials has provided a basis for the development of novel methods enabling magnetisation manipulation and switching. Finally, in a number of carrier-doped DMS and DMO a competition between long-range ferromagnetic and short-range antiferromagnetic interactions and/or the proximity of the localisation boundary lead to an electronic nano-scale phase separation. These materials exhibit characteristics similar to colossal magnetoresistance oxides.