For the maintenance/ directory files:
[lhc/web/wiklou.git] / maintenance / updateArticleCount.inc.php
1 <?php
2
3 /**
4 * Support class for the updateArticleCount.php maintenance script
5 *
6 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 class ArticleCounter {
12
13 var $dbr;
14 var $namespaces;
15
16 function ArticleCounter() {
17 global $wgContentNamespaces;
18 $this->namespaces = $wgContentNamespaces;
19 $this->dbr =& wfGetDB( DB_SLAVE );
20 }
21
22 /**
23 * Produce a comma-delimited set of namespaces
24 * Includes paranoia
25 *
26 * @return string
27 */
28 function makeNsSet() {
29 foreach( $this->namespaces as $namespace )
30 $namespaces[] = intval( $namespace );
31 return implode( ', ', $namespaces );
32 }
33
34 /**
35 * Produce SQL for the query
36 *
37 * @return string
38 */
39 function makeSql() {
40 list( $page, $pagelinks ) = $this->dbr->tableNamesN( 'page', 'pagelinks' );
41 $nsset = $this->makeNsSet();
42 return "SELECT DISTINCT page_namespace,page_title 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 if( $res ) {
55 $count = $this->dbr->numRows( $res );
56 $this->dbr->freeResult( $res );
57 return $count;
58 } else {
59 # Look out for this when handling the result
60 # - Actually it's unreachable, !$res throws an exception -- TS
61 return false;
62 }
63 }
64
65 }
66
67 ?>