I guess it should look something like this, is what Brion's saying?
1) Database abstraction layer. Contains low-level methods like "select" and "replace". Basically our current Database class and descendants. 2) Database access layer. No calls to database abstraction layer should ever be made outside of here (maybe enforced eventually by inheritance and protected methods, or something, since PHP doesn't have friends). Classes in this layer might include Article, Title, User, and others closely tied to the database. Special pages and complicated API requests would involve new functions added to these, I guess, like fetchArticleIds(matching criteria) or whatever. 3) Display layer. Translates user request (through API, WebDAV, human web interface, ...) into series of calls to database access layer. Would include classes like the current API, Linker and descendants, web request initialization stuff, and special pages (but much special page logic would be moved to things like Article). These would of course be grouped according to various access methods, which would be independent of each other. i) General library functions that don't involve the database. Includes parser, utility functions for XML/strings/..., etc. Some might be called by any layer, conceivably (like string or IP address functions), others would probably only be called by the display layer (parser classes). Includes classes like Parser and friends, Xml, StringFunctions, IP, etc.
Is that sort of what you're thinking, Brion? It would require the database access layer to be *very* general, so general that it's not easy to see how it would be less complicated than just dropping it and writing the SQL queries manually as we do now, other than that it makes schema changes easier (which is nice, but if we wanted to do that it would probably be no harder to rewrite queries referring to obsolete tables or columns on the level of Database::select and whatnot). I also can't see how extensions would fit into this, in that they may well have to run literal SQL queries that we didn't anticipate.