User:Jiangxin/Patch magic word of numberheadings

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

New magic word __NUMBERHEADINGS__

Section headings are not numbered in wiki pages, only if user changed his/her default settings in Preferences.

the following wiki code:


__NUMBERHEADINGS__
==title1==
==title2==

will be rendered as:

1 title1

1 title2

文章中章节的标题缺省不添加编号。用户可以修改 Preferences,则每一篇文章中章节标题都会显示编号。

下面的扩展将添加一个新的关键字 __NUMBERHEADINGS__,则该文章无论用户设置如何都为章节标题添加编号。

下面的Wiki 代码


__NUMBERHEADINGS__
==标题1==
==标题2==

将会显示为:

1 标题1

1 标题2

Patch


Index: includes/MagicWord.php
===================================================================
RCS file: /user/jiangxin/project/wiki/mediawiki/src/includes/MagicWord.php,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 MagicWord.php
--- includes/MagicWord.php	16 Oct 2005 19:04:40 -0000	1.1.1.1
+++ includes/MagicWord.php	23 Nov 2005 08:12:29 -0000
@@ -55,6 +55,7 @@
 define('MAG_SCRIPTPATH',		41);
 define('MAG_SERVERNAME',		42);
 define('MAG_NUMBEROFFILES',		43);
+define('MAG_NUMBERHEADINGS',		44);
 
 $wgVariableIDs = array(
 	MAG_CURRENTMONTH,
Index: includes/Parser.php
===================================================================
RCS file: /user/jiangxin/project/wiki/mediawiki/src/includes/Parser.php,v
retrieving revision 1.15
diff -u -r1.15 Parser.php
--- includes/Parser.php	17 Nov 2005 08:51:13 -0000	1.15
+++ includes/Parser.php	23 Nov 2005 08:12:29 -0000
@@ -2577,6 +2577,12 @@
 			$showEditLink = $this->mOptions->getEditSection();
 		}
 
+		# OpenSourceXpress: MAG_NUMBERHEADINGS 强制显示编号 
+		$mnh =& MagicWord::get( MAG_NUMBERHEADINGS );
+		if( $mnh->matchAndRemove( $text ) ) {
+			$doNumberHeadings = true;
+		}
+
 		# Inhibit editsection links if requested in the page
 		$esw =& MagicWord::get( MAG_NOEDITSECTION );
 		if( $esw->matchAndRemove( $text ) ) {
Index: languages/Language.php
===================================================================
RCS file: /user/jiangxin/project/wiki/mediawiki/src/languages/Language.php,v
retrieving revision 1.5
diff -u -r1.5 Language.php
--- languages/Language.php	14 Nov 2005 02:04:08 -0000	1.5
+++ languages/Language.php	23 Nov 2005 08:12:29 -0000
@@ -232,6 +232,7 @@
 	MAG_CURRENTWEEK          => array( 1,    'CURRENTWEEK'            ),
 	MAG_CURRENTDOW           => array( 1,    'CURRENTDOW'             ),
 	MAG_REVISIONID           => array( 1,    'REVISIONID'             ),
+	MAG_NUMBERHEADINGS       => array( 0,    '__NUMBERHEADINGS__'  ),
 );
 
 #-------------------------------------------------------------------

--Jiangxin 14:25, 29 November 2005 (UTC)