48 $this->mConverter = $converter;
58 $variants = (
array)$variants;
62 foreach ( $variants
as $variant ) {
63 if ( isset( $this->mBidtable[$variant] ) ) {
64 return $this->mBidtable[$variant];
77 $variantFlags =
array();
79 $sepPos = strpos( $text,
'|' );
80 if ( $sepPos !==
false ) {
81 $validFlags = $this->mConverter->mFlags;
83 foreach (
$f as $ff ) {
85 if ( isset( $validFlags[$ff] ) ) {
86 $flags[$validFlags[$ff]] =
true;
89 $text = strval( substr( $text, $sepPos + 1 ) );
94 } elseif ( isset(
$flags[
'R'] ) ) {
96 } elseif ( isset(
$flags[
'N'] ) ) {
98 } elseif ( isset(
$flags[
'-'] ) ) {
100 } elseif ( count(
$flags ) == 1 && isset(
$flags[
'T'] ) ) {
102 } elseif ( isset(
$flags[
'H'] ) ) {
104 $temp =
array(
'+' =>
true,
'H' =>
true );
105 if ( isset(
$flags[
'T'] ) ) {
108 if ( isset(
$flags[
'D'] ) ) {
113 if ( isset(
$flags[
'A'] ) ) {
117 if ( isset(
$flags[
'D'] ) ) {
122 $variantFlags = array_intersect( array_keys(
$flags ), $this->mConverter->mVariants );
123 if ( $variantFlags ) {
124 $variantFlags = array_flip( $variantFlags );
128 $this->mVariantFlags = $variantFlags;
129 $this->mRules = $text;
140 $unidtable =
array();
141 $variants = $this->mConverter->mVariants;
142 $varsep_pattern = $this->mConverter->getVarSeparatorPattern();
145 $rules = preg_replace(
'/(&[#a-zA-Z0-9]+);/',
"$1\x01", $rules );
146 $choice = preg_split( $varsep_pattern, $rules );
147 $choice = str_replace(
"\x01",
';', $choice );
149 foreach ( $choice
as $c ) {
150 $v = explode(
':', $c, 2 );
151 if ( count( $v ) != 2 ) {
157 $u = explode(
'=>', $v, 2 );
159 if ( count( $u ) == 1 && $to && in_array( $v, $variants ) ) {
161 } elseif ( count( $u ) == 2 ) {
162 $from = trim( $u[0] );
164 if ( array_key_exists( $v, $unidtable )
165 && !is_array( $unidtable[$v] )
167 && in_array( $v, $variants ) ) {
169 } elseif ( $to && in_array( $v, $variants ) ) {
170 $unidtable[$v][
$from] = $to;
174 if ( !isset( $this->mConverter->mVariantNames[$v] ) ) {
176 $unidtable =
array();
180 $this->mBidtable = $bidtable;
181 $this->mUnidtable = $unidtable;
190 $codesep = $this->mConverter->mDescCodeSep;
191 $varsep = $this->mConverter->mDescVarSep;
193 foreach ( $this->mBidtable
as $k => $v ) {
194 $text .= $this->mConverter->mVariantNames[$k] .
"$codesep$v$varsep";
196 foreach ( $this->mUnidtable
as $k => $a ) {
197 foreach ( $a
as $from => $to ) {
198 $text .=
$from .
'⇒' . $this->mConverter->mVariantNames[$k] .
199 "$codesep$to$varsep";
217 if ( count( $bidtable ) + count( $unidtable ) == 0 ) {
225 $this->mConverter->getVariantFallbacks( $variant ) );
228 if ( !$disp && array_key_exists( $variant, $unidtable ) ) {
229 $disp = array_values( $unidtable[$variant] );
233 if ( !$disp && $this->mConverter->mManualLevel[$variant] ==
'disable' ) {
234 if ( count( $bidtable ) > 0 ) {
235 $disp = array_values( $bidtable );
238 $disp = array_values( $unidtable );
239 $disp = array_values( $disp[0] );
258 if ( $variant === $this->mConverter->mMainLanguageCode ) {
267 if ( array_key_exists( $variant, $this->mUnidtable ) ) {
268 $disp = array_values( $this->mUnidtable[$variant] );
284 if ( !$this->mBidtable && !$this->mUnidtable ) {
285 $this->mConvTable =
array();
291 $manLevel = $this->mConverter->mManualLevel;
294 foreach ( $this->mConverter->mVariants
as $v ) {
298 if ( !isset( $bidtable[$v] ) ) {
300 $this->mConverter->getVariantFallbacks( $v );
307 if ( isset( $bidtable[$v] ) ) {
308 foreach ( $vmarked
as $vo ) {
314 if ( $manLevel[$v] ==
'bidirectional' ) {
315 $this->mConvTable[$v][$bidtable[$vo]] = $bidtable[$v];
317 if ( $manLevel[$vo] ==
'bidirectional' ) {
318 $this->mConvTable[$vo][$bidtable[$v]] = $bidtable[$vo];
324 if ( ( $manLevel[$v] ==
'bidirectional' || $manLevel[$v] ==
'unidirectional' )
325 && isset( $unidtable[$v] )
327 if ( isset( $this->mConvTable[$v] ) ) {
328 $this->mConvTable[$v] = array_merge( $this->mConvTable[$v], $unidtable[$v] );
330 $this->mConvTable[$v] = $unidtable[$v];
340 public function parse( $variant =
null ) {
342 $variant = $this->mConverter->getPreferredVariant();
350 if ( $this->mVariantFlags ) {
352 if ( isset( $this->mVariantFlags[$variant] ) ) {
354 $this->mRules = $this->mConverter->autoConvert( $this->mRules,
360 $this->mConverter->getVariantFallbacks( $variant );
361 if ( is_array( $variantFallbacks ) ) {
362 foreach ( $variantFallbacks
as $variantFallback ) {
364 if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
367 $this->mConverter->autoConvert( $this->mRules,
379 $this->mRules = str_replace(
'=>',
'=>', $this->mRules );
384 if ( !$this->mBidtable && !$this->mUnidtable ) {
387 foreach ( $this->mConverter->mVariants
as $v ) {
388 $this->mBidtable[$v] = $rules;
390 } elseif ( !isset(
$flags[
'N'] ) && !isset(
$flags[
'T'] ) ) {
395 $this->mRuleDisplay =
false;
396 foreach (
$flags as $flag => $unused ) {
400 $this->mRuleDisplay = $rules;
404 $ruleVar = trim( $rules );
405 if ( isset( $this->mConverter->mVariantNames[$ruleVar] ) ) {
406 $this->mRuleDisplay = $this->mConverter->mVariantNames[$ruleVar];
408 $this->mRuleDisplay =
'';
417 $this->mRuleDisplay =
'';
420 $this->mRulesAction =
'remove';
421 $this->mRuleDisplay =
'';
424 $this->mRulesAction =
'add';
425 $this->mRuleDisplay =
'';
432 $this->mRuleDisplay =
'';
438 if ( $this->mRuleDisplay ===
false ) {
439 $this->mRuleDisplay =
'<span class="error">'
440 .
wfMessage(
'converter-manual-rule-error' )->inContentLanguage()->escaped()