3 * Support class for the updateArticleCount.php maintenance script
7 * @author Rob Church <robchur@gmail.com>
10 class ArticleCounter
{
15 function ArticleCounter() {
16 global $wgContentNamespaces;
17 $this->namespaces
= $wgContentNamespaces;
18 $this->dbr
= wfGetDB( DB_SLAVE
);
22 * Produce a comma-delimited set of namespaces
27 function makeNsSet() {
28 foreach( $this->namespaces
as $namespace )
29 $namespaces[] = intval( $namespace );
30 return implode( ', ', $namespaces );
34 * Produce SQL for the query
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";
48 * Count the number of valid content pages in the wiki
50 * @return mixed Integer, or false if there's a problem
53 $res = $this->dbr
->query( $this->makeSql(), __METHOD__
);
54 $row = $this->dbr
->fetchObject( $res );
55 $this->dbr
->freeResult( $res );
56 return $row->pagecount
;