* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / portal.php
bloba2342c837bceeb1d236fc0979875086680bac55f
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 * @todo document
6 */
7 $textsourcefile_web = "http://meta.wikipedia.org/w/index.php?title=PortalText&action=raw" ;
8 $textsourcefile = "t.txt" ;
9 #$articlecountfile_web = "http://magnusmanske.de/wikipedia/num.txt" ;
10 $articlecountfile_web = "num.txt" ;
11 $articlecountfile = "n.txt" ;
12 $perrow = 3 ;
14 if ( isset ( $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ) )
15 $userlang = $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ;
16 else $userlang = '' ;
18 # Update local files
19 if ( isset ( $_GET["update"] ) )
21 copy ( $textsourcefile_web , $textsourcefile ) ;
22 copy ( $articlecountfile_web , $articlecountfile ) ;
25 /**
26 * Reads a file into a string
28 function readafile ( $filename )
30 $handle = fopen($filename, "r");
31 $contents = '';
32 while (!feof($handle))
33 $contents .= fread($handle, 8192);
34 fclose($handle);
35 return $contents ;
38 /** Parsing statistics file */
39 function get_numbers ( $filename )
41 $r = array () ;
42 $nt = readafile ( $filename ) ;
43 $nt = explode ( "\n" , $nt ) ;
44 foreach ( $nt AS $x )
46 $y = explode ( ":" , $x ) ;
47 if ( count ( $y ) == 2 )
48 $r[strtolower($y[0])] = $y[1] ;
50 return $r ;
53 /** Make shades for pref. language(s) */
54 function getshades ( $l )
56 $r = array () ;
57 $l = explode ( "," , $l ) ;
58 foreach ( $l AS $x )
60 $y = explode ( ";" , $x ) ;
61 if ( count ( $y ) == 2 ) $weight = array_pop ( explode ( "=" , $y[1] ) ) ;
62 else $weight = "1.0" ;
64 $lang = array_shift ( $y ) ;
65 $lang = explode ( "-" , $lang ) ;
66 $lang = trim ( strtolower ( array_shift ( $lang ) ) ) ;
68 $w = 5 * $weight ;
69 $w = chr ( 70 - $w ) ;
70 $w = $w . $w ;
71 $w = $w.$w.$w ;
72 if ( !isset ( $r[$lang] ) || $r[$lang] < $w )
73 $r[$lang] = $w ;
75 return $r ;
78 # Parsing text file and generating output
79 $n = get_numbers ( $articlecountfile ) ;
80 $shade = getshades ( $userlang ) ;
81 $l = "<table align=center border=1 width='50%' cellpadding=2>" ;
82 $count = 0 ;
83 $t = readafile ( $textsourcefile ) ;
84 $t = explode ( "\n" , $t ) ;
85 foreach ( $t AS $x )
87 $y = explode ( ':' , $x , 2 ) ;
88 if ( count ( $y ) == 2 )
90 $language = trim ( strtolower ( $y[0] ) ) ; # language id
91 if ( isset ( $n[$language] ) ) # Only if there's a number to show
93 $ltext = $y[1] ; # Language text
94 $noa = $n[$language] ; # Number of articles
95 $ltext = str_replace ( "###" , "<b>{$noa}</b>" , $ltext ) ;
96 if ( isset ( $shade[$language] ) ) $s = " bgcolor='#" . $shade[$language] . "'" ;
97 else $s = "" ;
98 $ltext = "<td{$s}>{$ltext}</td>\n" ;
99 if ( $count == 0 ) $l .= "<tr>" ;
100 $l .= $ltext ;
101 if ( $count == $perrow-1 )
103 $l .= "</tr>" ;
104 $count = 0 ;
106 else $count++ ;
110 if ( $count != 0 ) $l .= "</tr>" ;
111 $l .= "</table>" ;
113 print "<html><head></head><body>" ;
114 print $l ;
115 print "</body></html>" ;