/** * @param $tokens - list of encoded SQL condition tokens * (infix or RPN - doesn't matter for localization) * comparsions are single-ops */ function __construct(array $tokens) { $this->src_tokens = $tokens; if (count($this->src_tokens) < 1) { $this->local_tokens = array(wfMsg('cb_all_op')); // localized default "all" return; } foreach ($tokens as &$token) { $op = $field = $num = ''; switch ($token->type) { case 'bracket': if ($token->value == '(') { $op = 'lbracket'; } else { // $token->value == ')' $op = 'rbracket'; } break; case 'logical': if ($token->value == 'or') { $op = 'or'; } else { // $token->value == 'and' $op = 'and'; } break; case 'comparsion': // comparsion subexpression $matches = array(); preg_match_all(CB_ENCODED_TOKEN_MATCH, $token->value, $matches, PREG_SET_ORDER); if (count($matches) == 1 && isset($matches[0]) && count($matches[0]) == 4) { // localize comparsion op list($expr, $cmp, $field, $num) = $matches[0]; $op = $cmp; $field = CB_SqlCond::$decoded_fields[$field]; } break; } if ($op == '') { $this->src_tokens = array(); // default "all" $this->local_tokens = array(wfMsg('cb_all_op')); // localized default "all" throw new MWException('Invalid operation ' . CB_Setup::entities($token) . ' in ' . __METHOD__); } if ($field == '') { $this->local_tokens[] = wfMsg("cb_{$op}_op"); } elseif ($num == '') { $this->local_tokens[] = wfMsg('cb_op1_template', wfMsg("cb_{$op}_op"), wfMsg("cb_{$field}")); } else { $this->local_tokens[] = wfMsg('cb_op2_template', wfMsg("cb_{$field}"), wfMsg("cb_{$op}_op"), $num); } } }
static function generateOption($range, $selectedValue, $nodeName = 'option') { # {{{ condition select's option template $condOptVal = ''; $condOptName = ''; $condOptInfix = ''; $condOptTpl = array('__tag' => $nodeName, 'value' => &$condOptVal, 'infixexpr' => &$condOptInfix, 0 => &$condOptName, '__end' => "\n"); # }}} $le = new CB_LocalExpr($range->infix_tokens); $condOptVal = CB_Setup::specialchars($range->rpn_queue); $sqlCond = CB_SqlCond::newFromEncodedPolishQueue($range->rpn_queue); $condOptInfix = CB_Setup::specialchars($sqlCond->getEncodedQueue(true)); if ($range->rpn_queue == $selectedValue) { $condOptTpl['selected'] = null; } $condOptName = CB_Setup::entities($le->toString()); return CB_XML::toText($condOptTpl); }