(bug 5932) Introduce {{PAGESINNAMESPACE}} magic word
authorRob Church <robchurch@users.mediawiki.org>
Mon, 12 Jun 2006 12:38:41 +0000 (12:38 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 12 Jun 2006 12:38:41 +0000 (12:38 +0000)
RELEASE-NOTES
includes/MagicWord.php
includes/Parser.php
languages/Language.php

index a18f40d..7e7f81d 100644 (file)
@@ -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 ==
 
index 030b528..a68407c 100644 (file)
@@ -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 ) );
index f7e5f50..4658d1c 100644 (file)
@@ -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
index 841fa55..30d9044 100644 (file)
@@ -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) {