Example #1
0
 public function execute()
 {
     if (!defined('WIKIHIERO_VERSION')) {
         $this->error("Please install WikiHiero first!\n", true);
     }
     $wh_prefabs = "\$wh_prefabs = array(\n";
     $wh_files = "\$wh_files   = array(\n";
     $imgDir = dirname(__FILE__) . '/img/';
     if (is_dir($imgDir)) {
         $dh = opendir($imgDir);
         if ($dh) {
             while (($file = readdir($dh)) !== false) {
                 if (stristr($file, WikiHiero::IMAGE_EXT)) {
                     list($width, $height, $type, $attr) = getimagesize($imgDir . $file);
                     $wh_files .= "  \"" . WikiHiero::getCode($file) . "\" => array( {$width}, {$height} ),\n";
                     if (strchr($file, '&')) {
                         $wh_prefabs .= "  \"" . WikiHiero::getCode($file) . "\",\n";
                     }
                 }
             }
             closedir($dh);
         }
     } else {
         $this->error("Images directory {$imgDir} not found!\n", true);
     }
     $wh_prefabs .= ");";
     $wh_files .= ");";
     $file = fopen('data/tables.php', 'w+');
     fwrite($file, "<?php\n\n");
     fwrite($file, '// File created by generateTables.php version ' . WIKIHIERO_VERSION . "\n");
     fwrite($file, '// ' . date('Y-m-d \\a\\t H:i') . "\n\n");
     fwrite($file, "{$wh_prefabs}\n\n{$wh_files}\n\n{$this->moreTables}\n");
     fclose($file);
     $this->serialize();
 }
Example #2
0
 /**
  * Returns a HTML list of hieroglyphs
  */
 private function listHieroglyphs()
 {
     global $wgMemc;
     $key = wfMemcKey('hiero-list', $this->getContext()->getLang()->getExtraHashOptions(), WikiHiero::getImagePath(), WIKIHIERO_VERSION);
     $html = $wgMemc->get($key);
     if ($html) {
         return $html;
     }
     $html = '';
     $html .= $this->getHeading('wikihiero-syntax', 'syntax');
     $html .= '<table class="wikitable"><tr>';
     foreach ($this->helpColumns as $col) {
         $html .= '<th>' . wfMessage("wikihiero-th-{$col}")->escaped() . '</th>';
     }
     $html .= '</tr>';
     foreach ($this->syntaxHelp as $e) {
         $html .= $this->getSyntaxHelp($e['code'], $e['message'], $e['example']);
     }
     $html .= "</table>\n";
     $files = array_keys($this->hiero->getFiles());
     natsort($files);
     foreach ($this->getCategories() as $cat) {
         $alnum = strlen($cat) == 1;
         $html .= $this->getHeading("wikihiero-category-{$cat}", "cat-{$cat}");
         $html .= "<table class=\"wikitable\">\n";
         $upperRow = $lowerRow = '';
         $columns = 0;
         $rows = 0;
         foreach ($files as $code) {
             if (strpos($code, '&') !== false) {
                 continue;
                 // prefab
             }
             if (strpos($code, $cat) !== 0 || $alnum && !ctype_digit($code[1])) {
                 continue;
                 // wrong category
             }
             $upperRow .= '<td>' . $this->hiero->render($code) . '</td>';
             $lowerRow .= '<th>' . htmlspecialchars($code) . '</th>';
             $columns++;
             if ($columns == self::HIEROGLYPHS_PER_ROW) {
                 $html .= "<tr>{$upperRow}</tr>\n<tr>{$lowerRow}</tr>\n";
                 $upperRow = $lowerRow = '';
                 $columns = 0;
                 $rows++;
             }
         }
         if ($columns) {
             $html .= "<tr>{$upperRow}" . ($columns && $rows ? '<td colspan="' . (self::HIEROGLYPHS_PER_ROW - $columns) . '">&#160;</td>' : '') . "</tr>\n";
             $html .= "<tr>{$lowerRow}" . ($columns && $rows ? '<th colspan="' . (self::HIEROGLYPHS_PER_ROW - $columns) . '">&#160;</th>' : '') . "</tr>\n";
         }
         $html .= "</table>\n";
     }
     $wgMemc->set($key, $html, self::CACHE_EXPIRY);
     return $html;
 }
Example #3
0
 /**
  *
  */
 public static function parserHook($input)
 {
     $hiero = new WikiHiero();
     // Strip newlines to avoid breakage in the wiki parser block pass
     return str_replace("\n", " ", $hiero->render($input));
 }