summaryrefslogtreecommitdiff
path: root/maintenance/updateArticleCount.inc.php
blob: 7eaea74912625cfae963a6d0540cbaae0a326e85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

/**
 * Support class for the updateArticleCount.php maintenance script
 *
 * @package MediaWiki
 * @subpackage Maintenance
 * @author Rob Church <robchur@gmail.com>
 */

class ArticleCounter {

	var $dbr;
	var $namespaces;
	
	function ArticleCounter() {
		global $wgContentNamespaces;
		$this->namespaces = $wgContentNamespaces;
		$this->dbr =& wfGetDB( DB_SLAVE );
	}
	
	/**
	 * Produce a comma-delimited set of namespaces
	 * Includes paranoia
	 *
	 * @return string
	 */
	function makeNsSet() {
		foreach( $this->namespaces as $namespace )
			$namespaces[] = intval( $namespace );
		return implode( ', ', $namespaces );
	}
	
	/**
	 * Produce SQL for the query
	 *
	 * @return string
	 */
	function makeSql() {
		extract( $this->dbr->tableNames( 'page', 'pagelinks' ) );
		$nsset = $this->makeNsSet();
		return "SELECT DISTINCT page_namespace,page_title FROM $page,$pagelinks " .
			"WHERE pl_from=page_id and page_namespace IN ( $nsset ) " .
			"AND page_is_redirect = 0 AND page_len > 0";
	}
	
	/**
	 * Count the number of valid content pages in the wiki
	 *
	 * @return mixed Integer, or false if there's a problem
	 */
	function count() {
		$res = $this->dbr->query( $this->makeSql(), __METHOD__ );
		if( $res ) {
			$count = $this->dbr->numRows( $res );
			$this->dbr->freeResult( $res );
			return $count;
		} else {
			# Look out for this when handling the result
			#    - Actually it's unreachable, !$res throws an exception -- TS
			return false; 
		}
	}

}

?>