]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/updateArticleCount.inc.php
MediaWiki 1.11.0-scripts
[autoinstallsdev/mediawiki.git] / maintenance / updateArticleCount.inc.php
1 <?php
2
3 /**
4  * Support class for the updateArticleCount.php maintenance script
5  *
6  * @addtogroup 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 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";
44         }
45         
46         /**
47          * Count the number of valid content pages in the wiki
48          *
49          * @return mixed Integer, or false if there's a problem
50          */
51         function count() {
52                 $res = $this->dbr->query( $this->makeSql(), __METHOD__ );
53                 if( $res ) {
54                         $count = $this->dbr->numRows( $res );
55                         $this->dbr->freeResult( $res );
56                         return $count;
57                 } else {
58                         # Look out for this when handling the result
59                         #    - Actually it's unreachable, !$res throws an exception -- TS
60                         return false; 
61                 }
62         }
63
64 }
65
66