Index: trunk/extensions/ParserFunctions/Expr.php |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | define( 'EXPR_POW', 35 ); |
48 | 48 | define( 'EXPR_PI', 36 ); |
49 | 49 | |
50 | | -class ExprError extends Exception { |
| 50 | +class ExprError extends MWException { |
51 | 51 | public function __construct( $msg, $parameter = '' ) { |
52 | 52 | $this->message = '<strong class="error">' . wfMsgForContent( "pfunc_expr_$msg", htmlspecialchars( $parameter ) ) . '</strong>'; |
53 | 53 | } |
Index: trunk/extensions/ParserFunctions/Convert.php |
— | — | @@ -4,11 +4,12 @@ |
5 | 5 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
6 | 6 | } |
7 | 7 | |
8 | | -class ConvertError extends Exception { |
| 8 | +class ConvertError extends MWException { |
9 | 9 | public function __construct( $msg /*...*/ ) { |
10 | 10 | $args = func_get_args(); |
11 | 11 | array_shift( $args ); |
12 | | - $this->message = '<strong class="error">' . wfMsgExt( "pfunc-convert-$msg", 'parseinline', $args ) . '</strong>'; |
| 12 | + array_map( 'htmlspecialchars', $args ); |
| 13 | + $this->message = '<strong class="error">' . wfMsgForContent( "pfunc-convert-$msg", $args ) . '</strong>'; |
13 | 14 | } |
14 | 15 | } |
15 | 16 | |
— | — | @@ -74,48 +75,62 @@ |
75 | 76 | $string = trim( array_shift( $args ) ); |
76 | 77 | |
77 | 78 | # Process the rest of the args |
78 | | - $sourceUnit =& MagicWord::get( 'sourceunit' ); |
79 | | - $targetUnit =& MagicWord::get( 'targetunit' ); |
80 | | - $linkUnit =& MagicWord::get( 'linkunit' ); |
81 | | - $dp =& MagicWord::get( 'decimalplaces' ); |
82 | | - $sf =& MagicWord::get( 'significantfigures' ); |
83 | | - $abbr =& MagicWord::get( 'abbreviate' ); |
84 | | - $raw =& MagicWord::get( 'rawsuffix' ); |
| 79 | + static $magicWords = array( |
| 80 | + 'sourceunit' => null, |
| 81 | + 'targetunit' => null, |
| 82 | + 'linkunit' => null, |
| 83 | + 'decimalplaces' => null, |
| 84 | + 'significantfigures' => null, |
| 85 | + 'abbreviate' => null, |
| 86 | + 'rawsuffix' => null, |
| 87 | + ); |
| 88 | + if( !is_object( $magicWords ) ){ |
| 89 | + foreach( $magicWords as $key => &$val ){ |
| 90 | + $magicWords[$key] =& MagicWord::get( $key ); |
| 91 | + } |
| 92 | + # The $magicWords[key]->function() syntax doesn't work, so cast to |
| 93 | + # object so we can use $magicWords->key->function() instead |
| 94 | + $magicWords = (object)$magicWords; |
| 95 | + } |
85 | 96 | |
86 | 97 | $n = 0; # Count of unnamed parameters |
87 | 98 | foreach ( $args as $arg ) { |
88 | 99 | $parts = array_map( 'trim', explode( '=', $arg, 2 ) ); |
89 | 100 | if ( count( $parts ) == 2 ) { |
90 | 101 | # Found "=" |
91 | | - if ( $sourceUnit->matchStartAndRemove( $parts[0] ) ) { |
92 | | - if( $targetUnit->matchStartAndRemove( $parts[1] ) ){ |
| 102 | + if ( $magicWords->sourceunit->matchStartAndRemove( $parts[0] ) ) { |
| 103 | + if( $magicWords->targetunit->matchStartAndRemove( $parts[1] ) ){ |
93 | 104 | $this->targetUnit =& $this->sourceUnit; |
94 | 105 | } else { |
95 | 106 | $this->sourceUnit = new ConvertUnit( $parts[1] ); |
96 | 107 | } |
97 | 108 | |
98 | | - } elseif ( $targetUnit->matchStartAndRemove( $parts[0] ) ) { |
99 | | - if( $sourceUnit->matchStartAndRemove( $parts[1] ) ){ |
| 109 | + } elseif ( $magicWords->targetunit->matchStartAndRemove( $parts[0] ) ) { |
| 110 | + if( $magicWords->sourceunit->matchStartAndRemove( $parts[1] ) ){ |
100 | 111 | $this->targetUnit =& $this->sourceUnit; |
101 | 112 | } else { |
102 | 113 | $this->targetUnit = new ConvertUnit( $parts[1] ); |
103 | 114 | } |
104 | 115 | |
105 | | - } elseif( $dp->matchStartAndRemove( $parts[0] ) ) { |
| 116 | + } elseif( $magicWords->decimalplaces->matchStartAndRemove( $parts[0] ) ) { |
106 | 117 | $this->decimalPlaces = intval( $parts[1] ); |
107 | 118 | |
108 | | - } elseif( $sf->matchStartAndRemove( $parts[0] ) ) { |
| 119 | + } elseif( $magicWords->significantfigures->matchStartAndRemove( $parts[0] ) ) { |
109 | 120 | # It doesn't make any sense to have negative sig-figs |
110 | 121 | if( intval( $parts[1] ) > 0 ){ |
111 | 122 | $this->significantFigures = intval( $parts[1] ); |
112 | 123 | } |
113 | 124 | } |
114 | | - } elseif( $linkUnit->matchStartAndRemove( $parts[0] ) ) { |
| 125 | + |
| 126 | + } elseif( $magicWords->linkunit->matchStartAndRemove( $parts[0] ) ) { |
115 | 127 | $this->link = true; |
116 | | - } elseif( $abbr->matchStartAndRemove( $parts[0] ) ) { |
| 128 | + |
| 129 | + } elseif( $magicWords->abbreviate->matchStartAndRemove( $parts[0] ) ) { |
117 | 130 | $this->abbreviate = true; |
118 | | - } elseif( $raw->matchStartAndRemove( $parts[0] ) ) { |
| 131 | + |
| 132 | + } elseif( $magicWords->rawsuffix->matchStartAndRemove( $parts[0] ) ) { |
119 | 133 | $this->raw = true; |
| 134 | + |
120 | 135 | } elseif( $parts[0] != '' && !$n++ && !$this->targetUnit instanceof ConvertUnit ){ |
121 | 136 | # First unnamed parameter = output unit |
122 | 137 | $this->targetUnit = new ConvertUnit( $parts[0] ); |