Index: Article.php =================================================================== --- Article.php (revision 47087) +++ Article.php (working copy) @@ -2520,6 +2521,15 @@ # Delete restrictions for it $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ ); + # Fix category table counts + # Do this *before* deleting the page entry, in case we have cascading deletes + $cats = array(); + $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ ); + foreach( $res as $row ) { + $cats []= $row->cl_to; + } + $this->updateCategoryCounts( array(), $cats ); + # Now that it's safely backed up, delete it $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__); $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy @@ -2561,14 +2571,6 @@ # Clear caches Article::onArticleDelete( $this->mTitle ); - # Fix category table counts - $cats = array(); - $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ ); - foreach( $res as $row ) { - $cats []= $row->cl_to; - } - $this->updateCategoryCounts( array(), $cats ); - # Clear the cached article id so the interface doesn't act like we exist $this->mTitle->resetArticleID( 0 ); $this->mTitle->mArticleID = 0;