/** * Render the #get_db_data parser function */ static function doGetDBData(&$parser) { global $wgTitle, $edgCurPageName, $edgValues; // if we're handling multiple pages, reset $edgValues // when we move from one page to another $cur_page_name = $wgTitle->getText(); if (!isset($edgCurPageName) || $edgCurPageName != $cur_page_name) { $edgValues = array(); $edgCurPageName = $cur_page_name; } $params = func_get_args(); array_shift($params); // we already know the $parser ... $args = EDUtils::parseParams($params); // parse params into name-value pairs $data = array_key_exists('data', $args) ? $args['data'] : null; $dbID = array_key_exists('db', $args) ? $args['db'] : null; // For backwards-compatibility - 'db' parameter was added // in External Data version 1.3. if (is_null($dbID)) { $dbID = array_key_exists('server', $args) ? $args['server'] : null; } $table = array_key_exists('from', $args) ? $args['from'] : null; $conds = array_key_exists('where', $args) ? $args['where'] : null; $limit = array_key_exists('limit', $args) ? $args['limit'] : null; $orderBy = array_key_exists('order by', $args) ? $args['order by'] : null; $options = array('LIMIT' => $limit, 'ORDER BY' => $orderBy); $mappings = EDUtils::paramToArray($data); // parse the data arg into mappings $external_values = EDUtils::getDBData($dbID, $table, array_values($mappings), $conds, $options); // handle error cases if (is_null($external_values)) { return; } // Build $edgValues foreach ($mappings as $local_var => $external_var) { if (array_key_exists($external_var, $external_values)) { foreach ($external_values[$external_var] as $value) { $edgValues[$local_var][] = $value; } } } return; }
/** * Render the #display_external_table parser function * * @author Dan Bolser */ static function doDisplayExternalTable(&$parser) { global $edgValues; $params = func_get_args(); array_shift($params); // we already know the $parser ... $args = EDUtils::parseParams($params); // parse params into name-value pairs if (array_key_exists('template', $args)) { $template = $args['template']; } else { return EDUtils::formatErrorMessage("No template specified"); } if (array_key_exists('data', $args)) { // parse the 'data' arg into mappings $mappings = EDUtils::paramToArray($args['data'], false, false); } else { // or just use keys from edgValues foreach ($edgValues as $local_variable => $values) { $mappings[$local_variable] = $local_variable; } } // The string placed in the wikitext between template calls - // default is a newline. if (array_key_exists('delimiter', $args)) { $delimiter = str_replace('\\n', "\n", $args['delimiter']); } else { $delimiter = "\n"; } $num_loops = 0; // May differ when multiple '#get_'s are used in one page foreach ($mappings as $template_param => $local_variable) { $num_loops = max($num_loops, count($edgValues[$local_variable])); } $text = ""; for ($i = 0; $i < $num_loops; $i++) { if ($i > 0) { $text .= $delimiter; } $text .= '{{' . $template; foreach ($mappings as $template_param => $local_variable) { $value = self::getIndexedValue($local_variable, $i); $text .= "|{$template_param}={$value}"; } $text .= "}}"; } // This actually 'calls' the template that we built above return array($text, 'noparse' => false); }