Remove bundled copy of PHPTAL, no longer needed for MonoBook. The user can install...
[lhc/web/wiklou.git] / extensions / SiteMatrix.php
1 <?php
2
3 # Make an HTML table showing all the wikis on the site
4
5 # Not a valid entry point, skip unless MEDIAWIKI is defined
6 if (defined('MEDIAWIKI')) {
7
8 $wgExtensionFunctions[] = "wfSiteMatrix";
9
10 function wfSiteMatrix() {
11 global $IP;
12 require_once( "$IP/includes/SpecialPage.php" );
13
14 class SiteMatrixPage extends SpecialPage
15 {
16 function SiteMatrixPage() {
17 SpecialPage::SpecialPage("SiteMatrix");
18 }
19
20 function execute( $par ) {
21 global $wgRequest, $wgOut, $wgTitle, $wgLocalDatabases;
22 $this->setHeaders();
23
24 $langlist = array_map( 'trim', file( '/home/wikipedia/common/langlist' ) );
25 sort( $langlist );
26 $xLanglist = array_flip( $langlist );
27
28 $sites = array( 'wiki', 'wiktionary', 'wikibooks', 'wikiquote' );
29 $names = array(
30 'wiki' => 'Wikipedia<br />w',
31 'wiktionary' => 'Wiktionary<br />wikt',
32 'wikibooks' => 'Wikibooks<br />b',
33 'wikiquote' => 'Wikiquote<br />q'
34 );
35 $hosts = array(
36 'wiki' => 'wikipedia.org',
37 'wiktionary' => 'wiktionary.org',
38 'wikibooks' => 'wikibooks.org',
39 'wikiquote' => 'wikiquote.org'
40 );
41
42 # Tabulate the matrix
43 $specials = array();
44 $matrix = array();
45 foreach( $wgLocalDatabases as $db ) {
46 # Find suffix
47 foreach ( $sites as $site ) {
48 if ( preg_match( "/(.*)$site\$/", $db, $m ) ) {
49 $lang = $m[1];
50 if ( empty( $xLanglist[$lang] ) && $site == 'wiki' ) {
51 $specials[] = $lang;
52 } else {
53 $matrix[$site][$lang] = 1;
54 }
55 break;
56 }
57 }
58 }
59
60 # Construct the HTML
61
62 # Header row
63 $s = "<table><tr>";
64 foreach ( $names as $name ) {
65 $s .= "<td><strong>$name</strong></td>";
66 }
67 $s .= "</tr>\n";
68
69 # Bulk of table
70 foreach ( $langlist as $lang ) {
71 $s .= "<tr>";
72 foreach ( $names as $site => $name ) {
73 $url = "http://$lang." . $hosts[$site] . "/";
74 if ( empty( $matrix[$site][$lang] ) ) {
75 # Non-existent wiki
76 $s .= "<td><a href=\"$url\" class=\"new\">$lang</a></td>";
77 } else {
78 # Wiki exists
79 $s .= "<td><a href=\"$url\">$lang</a></td>";
80 }
81 }
82 $s .= "</tr>\n";
83 }
84 $s .= "</table>\n";
85
86 # Specials
87 $s .= "<ul>";
88 foreach ( $specials as $lang ) {
89 $s .= "<li><a href=\"http://$lang.wikipedia.org/\">$lang</a></li>\n";
90 }
91 $s .= "</ul>";
92 $wgOut->addHTML( $s );
93 }
94 }
95
96 SpecialPage::addPage( new SiteMatrixPage );
97 global $wgMessageCache;
98 $wgMessageCache->addMessage( "sitematrix", "List of Wikimedia wikis" );
99
100 } # End of extension function
101 } # End of invocation protection
102 ?>