We show that first-principles electronic structure calculations of silicon wires with diameters up to \ensuremath{\sim}1.5 nm support the idea that quantum confinement and surface effects are responsible for the luminescence in porous silicon. Instead of the indirect gap of crystalline bulk silicon, the band structure of these wires exhibits a direct gap at k=0. The imaginary part of the dielectric function, polarized in the direction of the wire, shows a peak in the visible range. The dependence of this feature on wire size is analyzed and correlated to experimental luminescence spectra.