r54847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54846‎ | r54847 | r54848 >
Date:13:08, 12 August 2009
Author:siebrand
Status:deferred (Comments)
Tags:
Comment:
* new style magic words support for ParserFunctions
* add localisation support for ParserFunctions magic in Translate
* bump version
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions.i18n.magic.php (modified) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions.i18n.php (modified) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions.php (modified) (history)
  • /trunk/extensions/Translate/groups/mediawiki-defines.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions.i18n.magic.php
@@ -1,111 +1,96 @@
22 <?php
33
 4+$magicWords = array();
 5+
46 /**
5 - * Get translated magic words, if available
6 - *
7 - * @param string $lang Language code
8 - * @return array
 7+ * English
98 */
10 -function efParserFunctionsWords( $lang ) {
11 - $words = array();
 9+ 'expr' => array( 0, 'expr' ),
 10+ 'if' => array( 0, 'if' ),
 11+ 'ifeq' => array( 0, 'ifeq' ),
 12+ 'ifexpr' => array( 0, 'ifexpr' ),
 13+ 'iferror' => array( 0, 'iferror' ),
 14+ 'switch' => array( 0, 'switch' ),
 15+ 'default' => array( 0, '#default' ),
 16+ 'ifexist' => array( 0, 'ifexist' ),
 17+ 'time' => array( 0, 'time' ),
 18+ 'timel' => array( 0, 'timel' ),
 19+ 'rel2abs' => array( 0, 'rel2abs' ),
 20+ 'titleparts' => array( 0, 'titleparts' ),
 21+ 'len' => array( 0, 'len' ),
 22+ 'pos' => array( 0, 'pos' ),
 23+ 'rpos' => array( 0, 'rpos' ),
 24+ 'sub' => array( 0, 'sub' ),
 25+ 'count' => array( 0, 'count' ),
 26+ 'replace' => array( 0, 'replace' ),
 27+ 'explode' => array( 0, 'explode' ),
 28+);
1229
13 - /**
14 - * English
15 - */
16 - $words['en'] = array(
17 - 'expr' => array( 0, 'expr' ),
18 - 'if' => array( 0, 'if' ),
19 - 'ifeq' => array( 0, 'ifeq' ),
20 - 'ifexpr' => array( 0, 'ifexpr' ),
21 - 'iferror' => array( 0, 'iferror' ),
22 - 'switch' => array( 0, 'switch' ),
23 - 'default' => array( 0, '#default' ),
24 - 'ifexist' => array( 0, 'ifexist' ),
25 - 'time' => array( 0, 'time' ),
26 - 'timel' => array( 0, 'timel' ),
27 - 'rel2abs' => array( 0, 'rel2abs' ),
28 - 'titleparts' => array( 0, 'titleparts' ),
29 - 'len' => array( 0, 'len' ),
30 - 'pos' => array( 0, 'pos' ),
31 - 'rpos' => array( 0, 'rpos' ),
32 - 'sub' => array( 0, 'sub' ),
33 - 'count' => array( 0, 'count' ),
34 - 'replace' => array( 0, 'replace' ),
35 - 'explode' => array( 0, 'explode' ),
36 - );
 30+/**
 31+ * Farsi-Persian
 32+ */
 33+$magicWords['fa'] = array(
 34+ 'expr' => array( 0, 'حساب', 'expr' ),
 35+ 'if' => array( 0, 'اگر', 'if' ),
 36+ 'ifeq' => array( 0, 'اگرمساوی', 'ifeq' ),
 37+ 'ifexpr' => array( 0, 'اگرحساب', 'ifexpr' ),
 38+ 'iferror' => array( 0, 'اگرخطا', 'iferror' ),
 39+ 'switch' => array( 0, 'گزینه', 'switch' ),
 40+ 'default' => array( 0, '#پیش‌فرض', '#default' ),
 41+ 'ifexist' => array( 0, 'اگرموجود', 'ifexist' ),
 42+ 'time' => array( 0, 'زمان', 'time' ),
 43+ 'timel' => array( 0, 'زمان‌بلند', 'timel' ),
 44+ 'rel2abs' => array( 0, 'نسبی‌به‌مطلق', 'rel2abs' ),
 45+ 'titleparts' => array( 0, 'پاره‌عنوان', 'titleparts' ),
 46+);
3747
38 - /**
39 - * Farsi-Persian
40 - */
41 - $words['fa'] = array(
42 - 'expr' => array( 0, 'حساب', 'expr' ),
43 - 'if' => array( 0, 'اگر', 'if' ),
44 - 'ifeq' => array( 0, 'اگرمساوی', 'ifeq' ),
45 - 'ifexpr' => array( 0, 'اگرحساب', 'ifexpr' ),
46 - 'iferror' => array( 0, 'اگرخطا', 'iferror' ),
47 - 'switch' => array( 0, 'گزینه', 'switch' ),
48 - 'default' => array( 0, '#پیش‌فرض', '#default' ),
49 - 'ifexist' => array( 0, 'اگرموجود', 'ifexist' ),
50 - 'time' => array( 0, 'زمان', 'time' ),
51 - 'timel' => array( 0, 'زمان‌بلند', 'timel' ),
52 - 'rel2abs' => array( 0, 'نسبی‌به‌مطلق', 'rel2abs' ),
53 - 'titleparts' => array( 0, 'پاره‌عنوان', 'titleparts' ),
54 - );
 48+/**
 49+ * Hebrew
 50+ */
 51+$magicWords['he'] = array(
 52+ 'expr' => array( 0, 'חשב', 'expr' ),
 53+ 'if' => array( 0, 'תנאי', 'if' ),
 54+ 'ifeq' => array( 0, 'שווה', 'ifeq' ),
 55+ 'ifexpr' => array( 0, 'חשב תנאי', 'ifexpr' ),
 56+ 'iferror' => array( 0, 'תנאי שגיאה', 'iferror' ),
 57+ 'switch' => array( 0, 'בחר', 'switch' ),
 58+ 'default' => array( 0, '#ברירת מחדל', '#default' ),
 59+ 'ifexist' => array( 0, 'קיים', 'ifexist' ),
 60+ 'time' => array( 0, 'זמן', 'time' ),
 61+ 'timel' => array( 0, 'זמןמ', 'timel' ),
 62+ 'rel2abs' => array( 0, 'יחסי למוחלט', 'rel2abs' ),
 63+ 'titleparts' => array( 0, 'חלק בכותרת', 'titleparts' ),
 64+);
5565
56 - /**
57 - * Hebrew
58 - */
59 - $words['he'] = array(
60 - 'expr' => array( 0, 'חשב', 'expr' ),
61 - 'if' => array( 0, 'תנאי', 'if' ),
62 - 'ifeq' => array( 0, 'שווה', 'ifeq' ),
63 - 'ifexpr' => array( 0, 'חשב תנאי', 'ifexpr' ),
64 - 'iferror' => array( 0, 'תנאי שגיאה', 'iferror' ),
65 - 'switch' => array( 0, 'בחר', 'switch' ),
66 - 'default' => array( 0, '#ברירת מחדל', '#default' ),
67 - 'ifexist' => array( 0, 'קיים', 'ifexist' ),
68 - 'time' => array( 0, 'זמן', 'time' ),
69 - 'timel' => array( 0, 'זמןמ', 'timel' ),
70 - 'rel2abs' => array( 0, 'יחסי למוחלט', 'rel2abs' ),
71 - 'titleparts' => array( 0, 'חלק בכותרת', 'titleparts' ),
72 - );
 66+/**
 67+ * Indonesian
 68+ */
 69+$magicWords['id'] = array(
 70+ 'expr' => array( 0, 'hitung', 'expr' ),
 71+ 'if' => array( 0, 'jika', 'if' ),
 72+ 'ifeq' => array( 0, 'jikasama', 'ifeq' ),
 73+ 'ifexpr' => array( 0, 'jikahitung', 'ifexpr' ),
 74+ 'iferror' => array( 0, 'jikasalah', 'iferror' ),
 75+ 'switch' => array( 0, 'pilih', 'switch' ),
 76+ 'default' => array( 0, '#baku', '#default' ),
 77+ 'ifexist' => array( 0, 'jikaada', 'ifexist' ),
 78+ 'time' => array( 0, 'waktu', 'time' ),
 79+ 'timel' => array( 0, 'waktu1', 'timel' ),
 80+ 'rel2abs' => array( 0, 'rel2abs' ),
 81+ 'titleparts' => array( 0, 'bagianjudul', 'titleparts' ),
 82+);
7383
74 - /**
75 - * Indonesian
76 - */
77 - $words['id'] = array(
78 - 'expr' => array( 0, 'hitung', 'expr' ),
79 - 'if' => array( 0, 'jika', 'if' ),
80 - 'ifeq' => array( 0, 'jikasama', 'ifeq' ),
81 - 'ifexpr' => array( 0, 'jikahitung', 'ifexpr' ),
82 - 'iferror' => array( 0, 'jikasalah', 'iferror' ),
83 - 'switch' => array( 0, 'pilih', 'switch' ),
84 - 'default' => array( 0, '#baku', '#default' ),
85 - 'ifexist' => array( 0, 'jikaada', 'ifexist' ),
86 - 'time' => array( 0, 'waktu', 'time' ),
87 - 'timel' => array( 0, 'waktu1', 'timel' ),
88 - 'rel2abs' => array( 0, 'rel2abs' ),
89 - 'titleparts' => array( 0, 'bagianjudul', 'titleparts' ),
90 - );
91 -
92 - /**
93 - * Yiddish
94 - */
95 - $words['yi'] = array(
96 - 'expr' => array( 0, 'רעכן', 'expr' ),
97 - 'if' => array( 0, 'תנאי', 'if' ),
98 - 'ifeq' => array( 0, 'גלייך', 'ifeq' ),
99 - 'ifexpr' => array( 0, 'אויברעכן', 'ifexpr' ),
100 - 'switch' => array( 0, 'קלייב', 'switch' ),
101 - 'default' => array( 0, '#גרונט', '#default' ),
102 - 'ifexist' => array( 0, 'עקזיסט', 'ifexist' ),
103 - 'time' => array( 0, 'צייט', 'time' ),
104 - 'timel' => array( 0, 'צייטל', 'timel' ),
105 - );
106 -
107 - # English is used as a fallback, and the English synonyms are
108 - # used if a translation has not been provided for a given word
109 - return ( $lang == 'en' || !isset( $words[$lang] ) )
110 - ? $words['en']
111 - : array_merge( $words['en'], $words[$lang] );
112 -}
 84+/**
 85+ * Yiddish
 86+ */
 87+$magicWords['yi'] = array(
 88+ 'expr' => array( 0, 'רעכן', 'expr' ),
 89+ 'if' => array( 0, 'תנאי', 'if' ),
 90+ 'ifeq' => array( 0, 'גלייך', 'ifeq' ),
 91+ 'ifexpr' => array( 0, 'אויברעכן', 'ifexpr' ),
 92+ 'switch' => array( 0, 'קלייב', 'switch' ),
 93+ 'default' => array( 0, '#גרונט', '#default' ),
 94+ 'ifexist' => array( 0, 'עקזיסט', 'ifexist' ),
 95+ 'time' => array( 0, 'צייט', 'time' ),
 96+ 'timel' => array( 0, 'צייטל', 'timel' ),
 97+);
Index: trunk/extensions/ParserFunctions/ParserFunctions.i18n.php
@@ -5,6 +5,8 @@
66 * @addtogroup Extensions
77 */
88
 9+require_once( dirname(__FILE__) . '/ParserFunctions.i18n.magic.php' );
 10+
911 $messages = array();
1012
1113 $messages['en'] = array(
Index: trunk/extensions/ParserFunctions/ParserFunctions.php
@@ -30,13 +30,12 @@
3131 */
3232 $wgPFEnableStringFunctions = false;
3333
34 -
3534 /** REGISTRATION */
3635 $wgExtensionFunctions[] = 'wfSetupParserFunctions';
3736 $wgExtensionCredits['parserhook'][] = array(
3837 'path' => __FILE__,
3938 'name' => 'ParserFunctions',
40 - 'version' => '1.2.0',
 39+ 'version' => '1.3.0',
4140 'url' => 'http://www.mediawiki.org/wiki/Extension:ParserFunctions',
4241 'author' => array('Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic'),
4342 'description' => 'Enhance parser with logical functions',
@@ -45,11 +44,9 @@
4645
4746 $wgAutoloadClasses['ExtParserFunctions'] = dirname(__FILE__).'/ParserFunctions_body.php';
4847 $wgExtensionMessagesFiles['ParserFunctions'] = dirname(__FILE__) . '/ParserFunctions.i18n.php';
49 -$wgHooks['LanguageGetMagic'][] = 'wfParserFunctionsLanguageGetMagic';
5048
5149 $wgParserTestFiles[] = dirname( __FILE__ ) . "/funcsParserTests.txt";
5250
53 -
5451 function wfSetupParserFunctions() {
5552 global $wgParser, $wgPFHookStub, $wgHooks;
5653
@@ -68,13 +65,6 @@
6966 $wgHooks['ParserClearState'][] = array( &$wgPFHookStub, 'clearState' );
7067 }
7168
72 -function wfParserFunctionsLanguageGetMagic( &$magicWords, $langCode ) {
73 - require_once( dirname( __FILE__ ) . '/ParserFunctions.i18n.magic.php' );
74 - foreach( efParserFunctionsWords( $langCode ) as $word => $trans )
75 - $magicWords[$word] = $trans;
76 - return true;
77 -}
78 -
7969 /**
8070 * Stub class to defer loading of the bulk of the code until a parser function is
8171 * actually used.
Index: trunk/extensions/Translate/groups/mediawiki-defines.txt
@@ -670,6 +670,7 @@
671671
672672 Parser Functions
673673 descmsg = pfunc_desc
 674+magicfile = ParserFunctions/ParserFunctions.i18n.magic.php
674675
675676 Patroller
676677 aliasfile = Patroller/Patroller.alias.php

Follow-up revisions

RevisionCommit summaryAuthorDate
r54848Fix syntax error from r54847siebrand13:10, 12 August 2009
r55310Somehow the implementation of r54847 did not work. Now adding $wgExtensionMes...siebrand07:09, 19 August 2009

Comments

#Comment by Tim Starling (talk | contribs)   05:38, 4 September 2009

Why are the magic words in a separate file, not in ParserFunctions.i18n.php?

#Comment by Nikerabbit (talk | contribs)   05:55, 4 September 2009

Because the ad-hoc export code in Translate extension chokes on it.

Status & tagging log