For MediaWiki (recent comments | status changes | tags | authors | states | release notes)
Index: trunk/phase3/includes/CategoryPage.php =================================================================== --- trunk/phase3/includes/CategoryPage.php (revision 44918) +++ trunk/phase3/includes/CategoryPage.php (revision 44919) @@ -36,6 +36,19 @@ $this->closeShowCategory(); } } + + /** + * Don't return a 404 for categories in use. + */ + function hasViewableContent() { + if( parent::hasViewableContent() ) { + return true; + } else { + $cat = Category::newFromTitle( $this->mTitle ); + return $cat->getId() != 0; + } + + } function openShowCategory() { # For overloading Index: trunk/phase3/includes/Article.php =================================================================== --- trunk/phase3/includes/Article.php (revision 44918) +++ trunk/phase3/includes/Article.php (revision 44919) @@ -508,6 +508,18 @@ public function exists() { return $this->getId() > 0; } + + /** + * Check if this page is something we're going to be showing + * some sort of sensible content for. If we return false, page + * views (plain action=view) will return an HTTP 404 response, + * so spiders and robots can know they're following a bad link. + * + * @return bool + */ + public function hasViewableContent() { + return $this->exists() || $this->mTitle->isAlwaysKnown(); + } /** * @return int The view count for the page @@ -714,6 +726,7 @@ $rdfrom = $wgRequest->getVal( 'rdfrom' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); $purge = $wgRequest->getVal( 'action' ) == 'purge'; + $return404 = false; $wgOut->setArticleFlag( true ); @@ -813,12 +826,22 @@ $text = wfMsg( 'noarticletext' ); } } + # Non-existent pages if( $this->getID() === 0 ) { $wgOut->setRobotPolicy( 'noindex,nofollow' ); $text = "<div class='noarticletext'>\n$text\n</div>"; + if( !$this->hasViewableContent() ) { + // If there's no backing content, send a 404 Not Found + // for better machine handling of broken links. + $return404 = true; + } } + if( $return404 ) { + $wgRequest->response()->header( "HTTP/1.x 404 Not Found" ); + } + # Another whitelist check in case oldid is altering the title if( !$this->mTitle->userCanRead() ) { $wgOut->loginToUse(); Index: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES (revision 44918) +++ trunk/phase3/RELEASE-NOTES (revision 44919) @@ -241,8 +241,9 @@ * (bug 16760) Add CSS-class to action links of Special:Log * (bug 505) Time zones can now be specified by location in user preferences, avoiding the need to manually update for DST. Patch by Brad Jorsch. +* (bug 2585) HTTP 404 return code is now given for a page view if the page + does not exist, allowing spiders and link checkers to detect broken links. - === Bug fixes in 1.14 === * (bug 14907) DatabasePostgres::fieldType now defined.