Migrate main page to new data scheme

 * Refactor grid view computation:
   - Operate on copies instead of references and return the result,
     because copies are usually faster in PHP and make for a better
	 API.
   - Preserve original thumbnail list instead of sorting it back to
     that state.

 * MariaDB creates temporary tables and is slow when joining views.
   It is signifantly faster to incorporate the query of the view into
   the main query.
Introduce checks to prevent runtime warning
CSS: Fixed grid size for missing thumbnails
Remove some white space on line endings