function execute($par) { global $wgOut; $langNames = Language::getLanguageNames(); $this->setHeaders(); $this->outputHeader(); $matrix = new SiteMatrix(); $localLanguageNames = self::getLocalLanguageNames(); # Construct the HTML # Header row $s = Xml::openElement('table', array('class' => 'wikitable', 'id' => 'mw-sitematrix-table')) . "<tr>" . Xml::element('th', array('rowspan' => 2), wfMsg('sitematrix-language')) . Xml::element('th', array('colspan' => count($matrix->getSites())), wfMsg('sitematrix-project')) . "</tr>\n\t\t\t<tr>"; foreach ($matrix->getNames() as $id => $name) { $url = $matrix->getSiteUrl($id); $s .= Xml::tags('th', null, "<a href=\"{$url}\">{$name}</a>"); } $s .= "</tr>\n"; # Bulk of table foreach ($matrix->getLangList() as $lang) { $anchor = strtolower('<a id="' . htmlspecialchars($lang) . '" name="' . htmlspecialchars($lang) . '"></a>'); $s .= '<tr>'; $attribs = array(); if (isset($localLanguageNames[$lang])) { $attribs['title'] = $localLanguageNames[$lang]; } $langDisplay = isset($langNames[$lang]) ? $langNames[$lang] : ''; if (isset($localLanguageNames[$lang]) && strlen($localLanguageNames[$lang]) && $langDisplay != $localLanguageNames[$lang]) { $langDisplay .= ' (' . $localLanguageNames[$lang] . ')'; } $s .= '<td>' . $anchor . Xml::element('strong', $attribs, $langDisplay) . '</td>'; foreach ($matrix->getNames() as $site => $name) { $url = $matrix->getUrl($lang, $site); if ($matrix->exist($lang, $site)) { # Wiki exists $closed = $matrix->isClosed($lang, $site); $s .= "<td>" . ($closed ? "<del>" : '') . "<a href=\"{$url}\">{$lang}</a>" . ($closed ? "</del>" : '') . '</td>'; } else { # Non-existent wiki $s .= "<td><a href=\"{$url}\" class=\"new\">{$lang}</a></td>"; } } $s .= "</tr>\n"; } $language = $this->getLanguage(); # Total $totalCount = 0; $s .= '<tr><th rowspan="2"><a id="total" name="total"></a>' . wfMsgHtml('sitematrix-sitetotal') . '</th>'; foreach ($matrix->getNames() as $site => $name) { $url = $matrix->getSiteUrl($site); $count = $matrix->getCountPerSite($site); $totalCount += $count; $count = $language->formatNum($count); $s .= "<th><a href=\"{$url}\">{$count}</a></th>"; } $s .= '</tr>'; $s .= '<tr>'; $noProjects = count($matrix->getNames()); $totalCount = $language->formatNum($totalCount); $s .= "<th colspan=\"{$noProjects}\">{$totalCount}</th>"; $s .= '</tr>'; $s .= Xml::closeElement('table') . "\n"; # Specials $s .= '<h2 id="mw-sitematrix-others">' . wfMsg('sitematrix-others') . '</h2>'; $s .= Xml::openElement('table', array('class' => 'wikitable', 'id' => 'mw-sitematrix-other-table')) . "<tr>" . Xml::element('th', null, wfMsg('sitematrix-other-projects')) . "</tr>"; foreach ($matrix->getSpecials() as $special) { list($lang, $site) = $special; $langhost = str_replace('_', '-', $lang); $url = $matrix->getUrl($lang, $site); # Handle options $flags = array(); if ($matrix->isPrivate($lang . $site)) { $flags[] = wfMsgHtml('sitematrix-private'); } if ($matrix->isFishbowl($lang . $site)) { $flags[] = wfMsgHtml('sitematrix-fishbowl'); } $flagsStr = implode(', ', $flags); if ($site != 'wiki') { $langhost .= $site; } $closed = $matrix->isClosed($lang, $site); $s .= '<tr><td>' . ($closed ? '<del>' : '') . $language->specialList('<a href="' . $url . '/">' . $langhost . "</a>", $flagsStr) . ($closed ? '</del>' : '') . "</td></tr>\n"; } $s .= Xml::closeElement('table') . "\n"; $wgOut->addHTML($s); $wgOut->addWikiMsg('sitematrix-total', $language->formatNum($matrix->getCount())); }
public function execute() { $result = $this->getResult(); $matrix = new SiteMatrix(); $langNames = Language::getLanguageNames(); $matrix_out = array('count' => $matrix->getCount()); $localLanguageNames = SiteMatrixPage::getLocalLanguageNames(); $params = $this->extractRequestParams(); $type = array_flip($params['type']); $state = array_flip($params['state']); $all = isset($state['all']); $closed = isset($state['closed']); $private = isset($state['private']); $fishbowl = isset($state['fishbowl']); if (isset($type['language'])) { foreach ($matrix->getLangList() as $lang) { $langhost = str_replace('_', '-', $lang); $language = array('code' => $langhost, 'name' => $langNames[$lang], 'site' => array()); if (isset($localLanguageNames[$lang])) { $language['localname'] = $localLanguageNames[$lang]; } foreach ($matrix->getSites() as $site) { if ($matrix->exist($lang, $site)) { $skip = true; if ($all) { $skip = false; } $url = $matrix->getCanonicalUrl($lang, $site); $site_out = array('url' => $url, 'dbname' => $matrix->getDBName($lang, $site), 'code' => $site); if ($matrix->isClosed($lang, $site)) { $site_out['closed'] = ''; if ($closed) { $skip = false; } } if ($skip) { continue; } $language['site'][] = $site_out; } } $result->setIndexedTagName($language['site'], 'site'); $matrix_out[] = $language; } } $result->setIndexedTagName($matrix_out, 'language'); $result->addValue(null, "sitematrix", $matrix_out); if (isset($type['special'])) { $specials = array(); foreach ($matrix->getSpecials() as $special) { list($lang, $site) = $special; $url = $matrix->getCanonicalUrl($lang, $site); $wiki = array(); $wiki['url'] = $url; $wiki['dbname'] = $matrix->getDBName($lang, $site); $wiki['code'] = str_replace('_', '-', $lang) . ($site != 'wiki' ? $site : ''); $skip = true; if ($all) { $skip = false; } if ($matrix->isPrivate($lang . $site)) { $wiki['private'] = ''; if ($private) { $skip = false; } } if ($matrix->isFishbowl($lang . $site)) { $wiki['fishbowl'] = ''; if ($fishbowl) { $skip = false; } } if ($matrix->isClosed($lang, $site)) { $wiki['closed'] = ''; if ($closed) { $skip = false; } } if ($skip) { continue; } $specials[] = $wiki; } $result->setIndexedTagName($specials, 'special'); $result->addValue("sitematrix", "specials", $specials); } }