Imaam as Saa’di (may Allah have mercy on him) said:
The one entering the mosque should proceed with his right foot, and then says: ‘Bismillaahi Allaahumma Salli-Wa-Sallim Alaa Muhammad; Allaahumma Ighfir-lee Dzo-noo-bee, Waf-tah-lee abwaaba rahmatika'(Reported by Muslim, No:713)
Then he should pre-occupy himself with Prayer, Remembrance of Allaah, Recitation of the Qur’aan and Knowledge. He either teaches or learns, or listens. He gives advice to those in the mosque and directs them to that which contains good. And he does not pre-occupy himself with other than that, being engrossed in the affairs of the dunyaah, for the Mosques have not been built, except for seeking nearness to Allaah, whilst the other places are for exploring and pre-occupation with the (affairs) of the Dunyaah.
Source: Noorul Basaa-ir Wal Albaab of Imaam as-Saa’di, Page: 72