Tend your garden and fix your windows
I recently heard the expression "tending your garden" applied to software. Most importantly, taking care of the weeds before they take over. It's such a great analogy. We've all had to deal with poor codebases. Or we started with a great codebase and just made one quick change that we promised ourselves we'd totally comment, refactor and fully test later. And then that just never happens because another quick change comes along for something that's super-ASAP (and what isn't?). So before we realize it, the weeds are taking over.
Another analogy that I think applies to web applications is the broken window theory and it's sort of related to the weeds and the garden. That one quick change we didn't comment and refactor is one broken window. Another developer comes along and figures that nobody cares or takes pride in this project, so he just writes some crappy code to get done whatever he needs to get done. Before you know it, the neighborhood goes to shit. It takes a lot of discipline and motivation to tend your garden in a bad neighborhood. Because really, nobody else seems to care and the hooligans may be back any second and trample your tomatoes.
The morale? Rip out weeds and fix windows from the get-go. If you can't, at least look at your contribution as an oasis in an otherwise neglected garden. Maybe other developers will take it as an inspiration.