Improving query.
Minor - format code.
Minor - Format code , fixing PHP warnings.
Minor - format code.
Minor - cleaning code.
Don't show links if the category was deleted see BT#9046