From 6a5d22374ab6a80cf060c167335317ba4873acd3 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 12 Jun 2006 12:38:41 +0000 Subject: [PATCH] (bug 5932) Introduce {{PAGESINNAMESPACE}} magic word --- RELEASE-NOTES | 1 + includes/MagicWord.php | 2 ++ includes/Parser.php | 32 ++++++++++++++++++++++++++++++++ languages/Language.php | 1 + 4 files changed, 36 insertions(+) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a18f40d3b4..7e7f81d41c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -478,6 +478,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN themselves. Some minor tweaks to the actual message content. * Introduce $wgContentNamespaces which allows for articles to exist in namespaces other than the main namespace, and still be counted as valid content in the site statistics. +* (bug 5932) Introduce {{PAGESINNAMESPACE}} magic word == Compatibility == diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 030b52801b..a68407c735 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -93,6 +93,7 @@ $magicWords = array( 'MAG_DIRECTIONMARK', 'MAG_LANGUAGE', 'MAG_CONTENTLANGUAGE', + 'MAG_PAGESINNAMESPACE', ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) ); @@ -148,6 +149,7 @@ $wgVariableIDs = array( MAG_DIRECTIONMARK, MAG_LANGUAGE, MAG_CONTENTLANGUAGE, + MAG_PAGESINNAMESPACE, ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordwgVariableIDs', array( &$wgVariableIDs ) ); diff --git a/includes/Parser.php b/includes/Parser.php index f7e5f50bd7..4658d1c912 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2795,6 +2795,21 @@ class Parser } } } + + # PAGESINNAMESPACE + if( !$found ) { + $mwPagesInNs =& MagicWord::get( MAG_PAGESINNAMESPACE ); + if( $mwPagesInNs->matchStartAndRemove( $part1 ) ) { + $found = true; + $count = wfPagesInNs( intval( $part1 ) ); + $mwRawSuffix =& MagicWord::get( MAG_RAWSUFFIX ); + if( isset( $args[0] ) && $mwRawSuffix->match( $args[0] ) ) { + $text = $linestart . $count; + } else { + $text = $linestart . $wgContLang->formatNum( $count ); + } + } + } # #LANGUAGE: if( !$found ) { @@ -4640,6 +4655,23 @@ function wfNumberOfPages() { return (int)$count; } +/** + * Count the number of pages in a particular namespace + * + * @param $ns Namespace + * @return integer + */ +function wfPagesInNs( $ns ) { + static $pageCount = array(); + wfProfileIn( 'wfPagesInNs' ); + if( !isset( $pageCount[$ns] ) ) { + $dbr =& wfGetDB( DB_SLAVE ); + $pageCount[$ns] = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $ns ), 'wfPagesInNs' ); + } + wfProfileOut( 'wfPagesInNs' ); + return (int)$pageCount[$ns]; +} + /** * Get various statistics from the database * @private diff --git a/languages/Language.php b/languages/Language.php index 841fa55823..30d9044c81 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -291,6 +291,7 @@ $wgLanguageNamesEn =& $wgLanguageNames; MAG_DIRECTIONMARK => array( 1, 'DIRECTIONMARK', 'DIRMARK' ), MAG_LANGUAGE => array( 0, '#LANGUAGE:' ), MAG_CONTENTLANGUAGE => array( 1, 'CONTENTLANGUAGE', 'CONTENTLANG' ), + MAG_PAGESINNAMESPACE => array( 1, 'PAGESINNAMESPACE:', 'PAGESINNS:' ), ); if (!$wgCachedMessageArrays) { -- 2.20.1