84fdfddb94263f771dce3b17f6f12af892e90354
4 * Support class for the updateArticleCount.php maintenance script
6 * @addtogroup Maintenance
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 DISTINCT page_namespace,page_title FROM $page,$pagelinks " .
42 "WHERE pl_from=page_id and page_namespace IN ( $nsset ) " .
43 "AND page_is_redirect = 0 AND page_len > 0";
47 * Count the number of valid content pages in the wiki
49 * @return mixed Integer, or false if there's a problem
52 $res = $this->dbr
->query( $this->makeSql(), __METHOD__
);
54 $count = $this->dbr
->numRows( $res );
55 $this->dbr
->freeResult( $res );
58 # Look out for this when handling the result
59 # - Actually it's unreachable, !$res throws an exception -- TS