Tweak to r47279 -- include final newline to keep the terminal clean :)
[mediawiki.git] / maintenance / updateArticleCount.inc.php
bloba847a2edb1e75cfb5afcc9cd8769736fc503a14c
1 <?php
2 /**
3 * Support class for the updateArticleCount.php maintenance script
5 * @file
6 * @ingroup Maintenance
7 * @author Rob Church <robchur@gmail.com>
8 */
10 class ArticleCounter {
12 var $dbr;
13 var $namespaces;
15 function ArticleCounter() {
16 global $wgContentNamespaces;
17 $this->namespaces = $wgContentNamespaces;
18 $this->dbr = wfGetDB( DB_SLAVE );
21 /**
22 * Produce a comma-delimited set of namespaces
23 * Includes paranoia
25 * @return string
27 function makeNsSet() {
28 foreach( $this->namespaces as $namespace )
29 $namespaces[] = intval( $namespace );
30 return implode( ', ', $namespaces );
33 /**
34 * Produce SQL for the query
36 * @return string
38 function makeSql() {
39 list( $page, $pagelinks ) = $this->dbr->tableNamesN( 'page', 'pagelinks' );
40 $nsset = $this->makeNsSet();
41 return "SELECT COUNT(DISTINCT page_namespace, page_title) AS pagecount " .
42 "FROM $page, $pagelinks " .
43 "WHERE pl_from=page_id and page_namespace IN ( $nsset ) " .
44 "AND page_is_redirect = 0 AND page_len > 0";
47 /**
48 * Count the number of valid content pages in the wiki
50 * @return mixed Integer, or false if there's a problem
52 function count() {
53 $res = $this->dbr->query( $this->makeSql(), __METHOD__ );
54 $row = $this->dbr->fetchObject( $res );
55 $this->dbr->freeResult( $res );
56 return $row->pagecount;