From ea5f40552eab2de95cad7e54940d22e3e4d0b6da Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 1 May 2006 15:54:20 +0000 Subject: [PATCH] * Updated initStats maintenance script * Remove recountImages since it's now redundant --- RELEASE-NOTES | 2 +- maintenance/initStats.php | 65 ++++++++++++++++++++++++----------- maintenance/recountImages.php | 27 --------------- 3 files changed, 45 insertions(+), 49 deletions(-) delete mode 100644 maintenance/recountImages.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index dd1ab18844..b4ba65af2c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -178,7 +178,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN formatted according to the current user's settings * (bug 218) Redirects do not support named anchors * (bug 5780) Thousands and decimal separators for Norwegian -* Maintenance script to recount images and update the site statistics +* Updated initStats maintenance script == Compatibility == diff --git a/maintenance/initStats.php b/maintenance/initStats.php index 9c1e1fa479..0fd881f175 100644 --- a/maintenance/initStats.php +++ b/maintenance/initStats.php @@ -1,34 +1,57 @@ + * @licence GNU General Public Licence 2.0 or later + */ + +$options = array( 'help', 'update' ); require_once( 'commandLine.inc' ); - +echo( "Refresh Site Statistics\n\n" ); $dbr =& wfGetDB( DB_SLAVE ); +$fname = 'initStats'; + +echo( "Counting total edits..." ); +$edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname ); +echo( "{$edits}\nCounting number of articles..." ); + +$good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname ); +echo( "{$good}\nCounting total pages..." ); -$edits = $dbr->selectField( 'revision', 'COUNT(rev_id)', '' ); -$pages = $dbr->selectField( 'page', 'COUNT(page_id)', - array( - 'page_namespace' => 0, - 'page_is_redirect' => 0, - 'page_len > 0', - ) -); // HACK APPROXIMATION +$pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname ); +echo( "{$pages}\nCounting number of users..." ); -echo "$wgDBname: setting edits $edits, pages $pages\n"; +$users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname ); +echo( "{$users}\nCounting number of admins..." ); + +$admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname ); +echo( "{$admin}\nCounting number of images..." ); + +$image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname ); +echo( "{$image}\n\nUpdating site statistics..." ); $dbw =& wfGetDB( DB_MASTER ); +$values = array( 'ss_total_edits' => $edits, + 'ss_good_articles' => $good, + 'ss_total_pages' => $pages, + 'ss_users' => $users, + 'ss_admins' => $admin, + 'ss_images' => $image ); +$conds = array( 'ss_row_id' => 1 ); +$views = array( 'ss_total_views' => 0 ); + if( isset( $options['update'] ) ) { - echo "(updating...)\n"; - $dbw->update( 'site_stats', - array( 'ss_total_edits' => $edits, - 'ss_good_articles' => $pages ), - array( 'ss_row_id' => 1 ) ); + $dbw->update( 'site_stats', $values, $conds, $fname ); } else { - $dbw->delete( 'site_stats', array( 'ss_row_id' => 1 ) ); - $dbw->insert( 'site_stats', - array( 'ss_row_id'=> 1, - 'ss_total_views' => 0, - 'ss_total_edits' => $edits, - 'ss_good_articles' => $pages ) ); + $dbw->delete( 'site_stats', $conds, $fname ); + $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname ); } +echo( "done.\n\n" ); + ?> \ No newline at end of file diff --git a/maintenance/recountImages.php b/maintenance/recountImages.php deleted file mode 100644 index 613082feb9..0000000000 --- a/maintenance/recountImages.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @licence GNU General Public Licence 2.0 or later - */ - -require_once( 'commandLine.inc' ); - -function recountImages() { - $dbw =& wfGetDB( DB_MASTER ); - $count = $dbw->selectField( 'images', 'COUNT(*)', '', 'recountImages' ); - # Replication safe update; set to NULL first to force the change to slaves - $dbw->update( 'site_stats', array( 'ss_images' => NULL ), array( 'ss_row_id' => 1 ), 'recountImages' ); - $dbw->update( 'site_stats', array( 'ss_images' => $count ), array( 'ss_row_id' => 1 ), 'recountImages' ); - return $count; -} - -echo( "Updating image count in site statistics..." ); -recountImages(); -echo( "set to {$count}.\n\n" ); - -?> \ No newline at end of file -- 2.20.1