Index: SiteMatrix.php =================================================================== --- SiteMatrix.php (revision 26031) +++ SiteMatrix.php (working copy) @@ -21,3 +21,5 @@ } extAddSpecialPage( dirname(__FILE__) . '/SiteMatrix_body.php', 'SiteMatrix', 'SiteMatrixPage' ); +$wgAutoloadClasses['ApiQuerySiteMatrix'] = dirname( __FILE__ ) . '/SiteMatrix_body.php'; +$wgAPIModules['sitematrix'] = 'ApiQuerySiteMatrix'; Index: SiteMatrix_body.php =================================================================== --- SiteMatrix_body.php (revision 26031) +++ SiteMatrix_body.php (working copy) @@ -14,21 +14,20 @@ global $IP; require_once( $IP.'/languages/Names.php' ); -class SiteMatrixPage extends SpecialPage { - - function SiteMatrixPage() { - SpecialPage::SpecialPage('SiteMatrix'); - } - - function execute( $par ) { - global $wgOut, $wgLocalDatabases; - $this->setHeaders(); - - $langlist = array_map( 'trim', file( '/home/wikipedia/common/langlist' ) ); - sort( $langlist ); - $xLanglist = array_flip( $langlist ); - - $sites = array( +class SiteMatrix +{ + public $langlist, $sites, $names, $hosts; + public $wikipediaSpecial, $hidden, $specials, $matrix; + + public function __construct() + { + global $wgLocalDatabases, $IP; + + $this->langlist = array_map( 'trim', file( '/home/wikipedia/common/langlist' ) ); + sort( $this->langlist ); + $xLanglist = array_flip( $this->langlist ); + + $this->sites = array( 'wiki', 'wiktionary', 'wikibooks', @@ -37,7 +36,7 @@ 'wikiquote', 'wikiversity', ); - $names = array( + $this->names = array( 'wiki' => 'Wikipedia
w', 'wiktionary' => 'Wiktionary
wikt', 'wikibooks' => 'Wikibooks
b', @@ -46,7 +45,7 @@ 'wikisource' => 'Wikisource
s', 'wikiversity' => 'Wikiversity
v', ); - $hosts = array( + $this->hosts = array( 'wiki' => 'wikipedia.org', 'wiktionary' => 'wiktionary.org', 'wikibooks' => 'wikibooks.org', @@ -57,58 +56,107 @@ ); # Special wikis that should point to wikiPedia, not wikiMedia - $wikipediaSpecial = array( + $this->wikipediaSpecial = array( 'dk', 'sources', 'species', 'test', ); # Some internal databases for other domains. - $hidden = array( + $this->hidden = array( 'foundation', 'mediawiki', ); - + # Tabulate the matrix - $specials = array(); - $matrix = array(); + $this->specials = array(); + $this->matrix = array(); foreach( $wgLocalDatabases as $db ) { # Find suffix - foreach ( $sites as $site ) { + foreach ( $this->sites as $site ) { $m = array(); if ( preg_match( "/(.*)$site\$/", $db, $m ) ) { $lang = str_replace( '_', '-', $m[1] ); if ( !isset( $xLanglist[$lang] ) && $site == 'wiki' ) { - $specials[] = $lang; + $this->specials[] = $lang; } else { - $matrix[$site][$lang] = 1; + $this->matrix[$site][$lang] = 1; } break; } } } + } +} +class SiteMatrixPage extends SpecialPage { + + function SiteMatrixPage() { + SpecialPage::SpecialPage('SiteMatrix'); + } + + function execute( $par ) { + global $wgOut, $wgRequest, $wgLanguageNames; + $this->setHeaders(); + + $matrix = new SiteMatrix(); + + if ($wgRequest->getVal( 'action' ) == "raw") + { + $wgOut->disable(); + header("Content-Type: text/xml; charset=utf-8"); + echo "\n"; + echo "\n"; + echo "\t\n"; + foreach ( $matrix->langlist as $lang ) { + $langhost = str_replace("_", "-", $lang); + echo "\t\t\n"; + foreach ( $matrix->sites as $site ) { + if ( isset($matrix->matrix[$site][$lang]) ) { + $url = "http://{$langhost}.{$matrix->hosts[$site]}/"; + echo "\t\t\t\n"; + } + } + echo "\t\t\n"; + } + echo "\t\n"; + echo "\t\n"; + foreach ( $matrix->specials as $lang ) { + if ( in_array($lang, $matrix->hidden) ) { + continue; + } + + $langhost = str_replace("_", "-", $lang); + $domain = in_array($lang, $matrix->wikipediaSpecial) ? ".wikipedia.org" : ".wikimedia.org"; + $url = "http://{$langhost}{$domain}/"; + + echo "\t\t\n"; + } + echo "\t\n"; + echo ""; + return; + } + # Construct the HTML # Header row $s = ' - + '; - foreach ( $names as $name ) { + foreach ( $matrix->names as $name ) { $s .= ''; } $s .= "\n"; - global $wgLanguageNames; # Bulk of table - foreach ( $langlist as $lang ) { + foreach ( $matrix->langlist as $lang ) { $anchor = strtolower( '' ); $s .= ''; $s .= ''; $langhost = str_replace( '_', '-', $lang ); - foreach ( $names as $site => $name ) { - $url = "http://$langhost." . $hosts[$site] . '/'; - if ( empty( $matrix[$site][$lang] ) ) { + foreach ( $matrix->names as $site => $name ) { + $url = "http://$langhost." . $matrix->hosts[$site] . '/'; + if ( empty( $matrix->matrix[$site][$lang] ) ) { # Non-existent wiki $s .= ''; } else { @@ -123,17 +171,17 @@ # Specials $s .= '

' . wfMsg( 'sitematrix-others' ) . '

'; $s .= '
' . wfMsg( 'sitematrix-language' ) . '' . wfMsg( 'sitematrix-project' ) . '' . wfMsg( 'sitematrix-project' ) . '
 ' . $name . '
' . $anchor . '' . $wgLanguageNames[$lang] . '' . $lang . '