From 183851b06bd6c52f3cae5375f433da720d410447 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 11 Oct 2006 18:12:39 +0000 Subject: MediaWiki 1.7.1 wiederhergestellt --- maintenance/updateArticleCount.inc.php | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 maintenance/updateArticleCount.inc.php (limited to 'maintenance/updateArticleCount.inc.php') diff --git a/maintenance/updateArticleCount.inc.php b/maintenance/updateArticleCount.inc.php new file mode 100644 index 00000000..20546a78 --- /dev/null +++ b/maintenance/updateArticleCount.inc.php @@ -0,0 +1,68 @@ + + */ + +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 COUNT(*) AS count FROM {$page} + LEFT JOIN {$pagelinks} ON pl_from = page_id + WHERE page_namespace IN ( $nsset ) + AND page_is_redirect = 0 + AND page_len > 0 + AND pl_namespace IS NOT NULL"; + } + + /** + * 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 ) { + $row = $this->dbr->fetchObject( $res ); + $this->dbr->freeResult( $res ); + return (int)$row->count; + } else { + return false; # Look out for this when handling the result + } + } + +} + +?> \ No newline at end of file -- cgit v1.2.2