00001 <?php
00010 class ArticleCounter {
00011
00012 var $dbr;
00013 var $namespaces;
00014
00015 function ArticleCounter() {
00016 global $wgContentNamespaces;
00017 $this->namespaces = $wgContentNamespaces;
00018 $this->dbr = wfGetDB( DB_SLAVE );
00019 }
00020
00027 function makeNsSet() {
00028 foreach( $this->namespaces as $namespace )
00029 $namespaces[] = intval( $namespace );
00030 return implode( ', ', $namespaces );
00031 }
00032
00038 function makeSql() {
00039 list( $page, $pagelinks ) = $this->dbr->tableNamesN( 'page', 'pagelinks' );
00040 $nsset = $this->makeNsSet();
00041 return "SELECT COUNT(DISTINCT page_namespace, page_title) AS pagecount " .
00042 "FROM $page, $pagelinks " .
00043 "WHERE pl_from=page_id and page_namespace IN ( $nsset ) " .
00044 "AND page_is_redirect = 0 AND page_len > 0";
00045 }
00046
00052 function count() {
00053 $res = $this->dbr->query( $this->makeSql(), __METHOD__ );
00054 $row = $this->dbr->fetchObject( $res );
00055 $this->dbr->freeResult( $res );
00056 return $row->pagecount;
00057 }
00058
00059 }
00060
00061