]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/updateArticleCount.inc.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / maintenance / updateArticleCount.inc.php
1 <?php
2 /**
3  * Support class for the updateArticleCount.php maintenance script
4  *
5  * @file
6  * @ingroup Maintenance
7  * @author Rob Church <robchur@gmail.com>
8  */
9
10 class ArticleCounter {
11
12         var $dbr;
13         var $namespaces;
14         
15         function ArticleCounter() {
16                 global $wgContentNamespaces;
17                 $this->namespaces = $wgContentNamespaces;
18                 $this->dbr = wfGetDB( DB_SLAVE );
19         }
20         
21         /**
22          * Produce a comma-delimited set of namespaces
23          * Includes paranoia
24          *
25          * @return string
26          */
27         function makeNsSet() {
28                 foreach( $this->namespaces as $namespace )
29                         $namespaces[] = intval( $namespace );
30                 return implode( ', ', $namespaces );
31         }
32         
33         /**
34          * Produce SQL for the query
35          *
36          * @return string
37          */
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";
45         }
46         
47         /**
48          * Count the number of valid content pages in the wiki
49          *
50          * @return mixed Integer, or false if there's a problem
51          */
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;
57         }
58
59 }
60
61