create schema mediawiki and store all objects in it
[mediawiki.git] / extensions / SiteMatrix.php
blob94beb5cd3e654a00f8e9b115720cf69608bf662f
1 <?php
3 # Make an HTML table showing all the wikis on the site
6 $wgExtensionFunctions[] = "wfSiteMatrix";
8 function wfSiteMatrix() {
9 class SiteMatrixPage extends SpecialPage
11 function SiteMatrixPage() {
12 SpecialPage::SpecialPage("SiteMatrix");
15 function execute( $par ) {
16 global $wgRequest, $wgOut, $wgTitle, $wgLocalDatabases;
17 $this->setHeaders();
19 $langlist = array_map( 'trim', file( '/home/wikipedia/common/langlist' ) );
20 sort( $langlist );
21 $xLanglist = array_flip( $langlist );
23 $sites = array( 'wiki', 'wiktionary', 'wikibooks', 'wikiquote' );
24 $names = array(
25 'wiki' => 'Wikipedia<br />w',
26 'wiktionary' => 'Wiktionary<br />wikt',
27 'wikibooks' => 'Wikibooks<br />b',
28 'wikiquote' => 'Wikiquote<br />q'
30 $hosts = array(
31 'wiki' => 'wikipedia.org',
32 'wiktionary' => 'wiktionary.org',
33 'wikibooks' => 'wikibooks.org',
34 'wikiquote' => 'wikiquote.org'
37 # Tabulate the matrix
38 $specials = array();
39 $matrix = array();
40 foreach( $wgLocalDatabases as $db ) {
41 # Find suffix
42 foreach ( $sites as $site ) {
43 if ( preg_match( "/(.*)$site\$/", $db, $m ) ) {
44 $lang = $m[1];
45 if ( empty( $xLanglist[$lang] ) && $site == 'wiki' ) {
46 $specials[] = $lang;
47 } else {
48 $matrix[$site][$lang] = 1;
50 break;
55 # Construct the HTML
57 # Header row
58 $s = "<table><tr>";
59 foreach ( $names as $name ) {
60 $s .= "<td><strong>$name</strong></td>";
62 $s .= "</tr>\n";
64 # Bulk of table
65 foreach ( $langlist as $lang ) {
66 $s .= "<tr>";
67 foreach ( $names as $site => $name ) {
68 $url = "http://$lang." . $hosts[$site] . "/";
69 if ( empty( $matrix[$site][$lang] ) ) {
70 # Non-existent wiki
71 $s .= "<td><a href=\"$url\" class=\"new\">$lang</a></td>";
72 } else {
73 # Wiki exists
74 $s .= "<td><a href=\"$url\">$lang</a></td>";
77 $s .= "</tr>\n";
79 $s .= "</table>\n";
81 # Specials
82 $s .= "<ul>";
83 foreach ( $specials as $lang ) {
84 $s .= "<li><a href=\"http://$lang.wikipedia.org/\">$lang</a></li>\n";
86 $s .= "</ul>";
87 $wgOut->addHTML( $s );
91 SpecialPage::addPage( new SiteMatrixPage );
92 global $wgMessageCache;
93 $wgMessageCache->addMessage( "sitematrix", "List of Wikimedia wikis" );
95 } # End of extension function