- /**
- * @param bool $fix
- * @todo DON'T USE THIS YET! It will remove entries which have children,
- * but which aren't properly attached (eg if page_latest is bogus
- * but valid revisions do exist)
- */
- private function checkWidows( $fix ) {
- $dbw = $this->getDB( DB_MASTER );
- $page = $dbw->tableName( 'page' );
- $revision = $dbw->tableName( 'revision' );
-
- if ( $fix ) {
- $this->lockTables( $dbw );
- }
-
- $this->output( "\nChecking for childless page table entries... "
- . "(this may take a while on a large wiki)\n" );
- $result = $dbw->query( "
- SELECT *
- FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id
- WHERE rev_id IS NULL
- " );
- $widows = $result->numRows();
- if ( $widows > 0 ) {
- $this->output( "$widows childless pages...\n" );
- $this->output( sprintf( "%10s %11s %2s %s\n", 'page_id', 'page_latest', 'ns', 'page_title' ) );
- foreach ( $result as $row ) {
- printf( "%10d %11d %2d %s\n",
- $row->page_id,
- $row->page_latest,
- $row->page_namespace,
- $row->page_title );
- if ( $fix ) {
- $dbw->delete( 'page', [ 'page_id' => $row->page_id ] );
- }
- }
- if ( !$fix ) {
- $this->output( "Run again with --fix to remove these entries automatically.\n" );
- }
- } else {
- $this->output( "No childless pages! Yay!\n" );
- }
-
- if ( $fix ) {
- $dbw->unlockTables( __METHOD__ );
- }
- }
-