/**
  * Add a static method to render results in a table format
  */
 public static function table(&$titles, $atts = array(), $fields = false)
 {
     // Open the table
     $html = "<table";
     if (array_key_exists('class', $atts)) {
         $atts['class'] .= ' ap_results';
     } else {
         $atts['class'] = 'ap_results';
     }
     foreach ($atts as $k => $v) {
         $html .= " {$k}=\"{$v}\"";
     }
     $html .= ">\n";
     // Get fields from the first title if none specified
     if (!is_array($fields)) {
         $ap = new ArticleProperties($titles[0]);
         $fields = array_keys($ap->properties());
     }
     // Render the table header
     $html .= "<tr>";
     foreach ($fields as $field) {
         $html .= "<th>{$field}</th>";
     }
     $html .= "</tr>\n";
     // Render the rows
     $html .= "<tr>";
     foreach ($titles as $title) {
         $ap = new ArticleProperties($title);
         foreach ($fields as $field) {
             $prop = array($field => null);
             $ap->properties($prop);
             $val = $prop[$field];
             $html .= "<td>{$val}</td>";
         }
     }
     $html .= "</tr>\n";
     // Close the table and return content
     $html .= "</table>\n";
     return $html;
 }
 /**
  * Migrates data from a single article_properties table into a class-specific table
  */
 function migrateArticleProperties($table, $prefix, $ns)
 {
     global $wgOut;
     $dbw =& wfGetDB(DB_MASTER);
     // Get all the properties of the given type and store in $props hash
     $tbl = $dbw->tableName('article_properties');
     $res = $dbw->select($tbl, 'ap_page,ap_propname,ap_value', "ap_namespace = {$ns}");
     $props = array();
     while ($row = $dbw->fetchRow($res)) {
         $k = $row[0];
         if (array_key_exists($k, $props)) {
             $props[$k][$row[1]] = $row[2];
         } else {
             $props[$k] = array($row[1] => $row[2]);
         }
     }
     $dbw->freeResult($res);
     // Insert them into the class-specific table
     $tbl = $dbw->tableName($table);
     foreach ($props as $page => $data) {
         $row = array($prefix . 'page' => $page);
         foreach ($data as $k => $v) {
             $col = ArticleProperties::getColumnName($k, $prefix);
             $wgOut->addHTML("\t{$k} = {$v}\n");
             if ($col != 'zp_region') {
                 $row[$col] = $v;
             }
         }
         $dbw->insert($tbl, $row);
     }
 }
 /**
  * Add a static method to render results in a table format
  */
 public static function table(&$titles, $atts = array(), $fields = false)
 {
     // If no titles, or no class bail
     if (count($titles) < 1 || !($class = ArticleProperties::getClass($titles[0]))) {
         return false;
     }
     // Open the table
     $html = "<table";
     if (array_key_exists('class', $atts)) {
         $atts['class'] .= ' ap_results';
     } else {
         $atts['class'] = 'ap_results';
     }
     foreach ($atts as $k => $v) {
         $html .= " {$k}=\"{$v}\"";
     }
     $html .= ">\n";
     // Get fields from the first title if none specified
     if (!is_array($fields)) {
         $ap = new $class($titles[0]);
         $fields = array_keys($ap->properties());
     }
     // Render the table header
     $html .= "<tr>";
     foreach ($fields as $field) {
         $html .= "<th>{$field}</th>";
     }
     $html .= "</tr>\n";
     // Render the rows
     foreach ($titles as $title) {
         $html .= "<tr>";
         $ap = new $class($title);
         foreach ($fields as $field) {
             $html .= "<td>" . $ap->getValue($field) . "</td>";
         }
         $html .= "</tr>\n";
     }
     // Close the table and return content
     $html .= "</table>\n";
     return $html;
 }