fix a problem by not inserting __MWTEMPLATESECTION for section titles that don't...
[lhc/web/wiklou.git] / extensions / SiteMatrix.php
1 <?php
2
3 # Make an HTML table showing all the wikis on the site
4
5
6 $wgExtensionFunctions[] = "wfSiteMatrix";
7
8 function wfSiteMatrix() {
9 class SiteMatrixPage extends SpecialPage
10 {
11 function SiteMatrixPage() {
12 SpecialPage::SpecialPage("SiteMatrix");
13 }
14
15 function execute( $par ) {
16 global $wgRequest, $wgOut, $wgTitle, $wgLocalDatabases;
17 $this->setHeaders();
18
19 $langlist = array_map( 'trim', file( '/home/wikipedia/common/langlist' ) );
20 sort( $langlist );
21 $xLanglist = array_flip( $langlist );
22
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'
29 );
30 $hosts = array(
31 'wiki' => 'wikipedia.org',
32 'wiktionary' => 'wiktionary.org',
33 'wikibooks' => 'wikibooks.org',
34 'wikiquote' => 'wikiquote.org'
35 );
36
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;
49 }
50 break;
51 }
52 }
53 }
54
55 # Construct the HTML
56
57 # Header row
58 $s = "<table><tr>";
59 foreach ( $names as $name ) {
60 $s .= "<td><strong>$name</strong></td>";
61 }
62 $s .= "</tr>\n";
63
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>";
75 }
76 }
77 $s .= "</tr>\n";
78 }
79 $s .= "</table>\n";
80
81 # Specials
82 $s .= "<ul>";
83 foreach ( $specials as $lang ) {
84 $s .= "<li><a href=\"http://$lang.wikipedia.org/\">$lang</a></li>\n";
85 }
86 $s .= "</ul>";
87 $wgOut->addHTML( $s );
88 }
89 }
90
91 SpecialPage::addPage( new SiteMatrixPage );
92 global $wgMessageCache;
93 $wgMessageCache->addMessage( "sitematrix", "List of Wikimedia wikis" );
94
95 } # End of extension function
96 ?>