moving geo files to new experiments subdir
[lhc/web/wiklou.git] / maintenance / portal.php
1 <?
2
3 $textsourcefile_web = "http://meta.wikipedia.org/w/index.php?title=PortalText&action=raw" ;
4 $textsourcefile = "t.txt" ;
5 #$articlecountfile_web = "http://magnusmanske.de/wikipedia/num.txt" ;
6 $articlecountfile_web = "num.txt" ;
7 $articlecountfile = "n.txt" ;
8 $perrow = 3 ;
9
10 if ( isset ( $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ) )
11 $userlang = $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ;
12 else $userlang = "" ;
13
14 # Update local files
15 if ( isset ( $_GET["update"] ) )
16 {
17 copy ( $textsourcefile_web , $textsourcefile ) ;
18 copy ( $articlecountfile_web , $articlecountfile ) ;
19 }
20
21 # Reads a file into a string
22 function readafile ( $filename )
23 {
24 $handle = fopen($filename, "r");
25 $contents = '';
26 while (!feof($handle))
27 $contents .= fread($handle, 8192);
28 fclose($handle);
29 return $contents ;
30 }
31
32 # Parsing statistics file
33 function get_numbers ( $filename )
34 {
35 $r = array () ;
36 $nt = readafile ( $filename ) ;
37 $nt = explode ( "\n" , $nt ) ;
38 foreach ( $nt AS $x )
39 {
40 $y = explode ( ":" , $x ) ;
41 if ( count ( $y ) == 2 )
42 $r[strtolower($y[0])] = $y[1] ;
43 }
44 return $r ;
45 }
46
47 # Make shades for pref. language(s)
48 function getshades ( $l )
49 {
50 $r = array () ;
51 $l = explode ( "," , $l ) ;
52 foreach ( $l AS $x )
53 {
54 $y = explode ( ";" , $x ) ;
55 if ( count ( $y ) == 2 ) $weight = array_pop ( explode ( "=" , $y[1] ) ) ;
56 else $weight = "1.0" ;
57
58 $lang = array_shift ( $y ) ;
59 $lang = explode ( "-" , $lang ) ;
60 $lang = trim ( strtolower ( array_shift ( $lang ) ) ) ;
61
62 $w = 5 * $weight ;
63 $w = chr ( 70 - $w ) ;
64 $w = $w . $w ;
65 $w = $w.$w.$w ;
66 if ( !isset ( $r[$lang] ) || $r[$lang] < $w )
67 $r[$lang] = $w ;
68 }
69 return $r ;
70 }
71
72 # Parsing text file and generating output
73 $n = get_numbers ( $articlecountfile ) ;
74 $shade = getshades ( $userlang ) ;
75 $l = "<table align=center border=1 width='50%' cellpadding=2>" ;
76 $count = 0 ;
77 $t = readafile ( $textsourcefile ) ;
78 $t = explode ( "\n" , $t ) ;
79 foreach ( $t AS $x )
80 {
81 $y = explode ( ":" , $x , 2 ) ;
82 if ( count ( $y ) == 2 )
83 {
84 $language = trim ( strtolower ( $y[0] ) ) ; # language id
85 if ( isset ( $n[$language] ) ) # Only if there's a number to show
86 {
87 $ltext = $y[1] ; # Language text
88 $noa = $n[$language] ; # Number of articles
89 $ltext = str_replace ( "###" , "<b>{$noa}</b>" , $ltext ) ;
90 if ( isset ( $shade[$language] ) ) $s = " bgcolor='#" . $shade[$language] . "'" ;
91 else $s = "" ;
92 $ltext = "<td{$s}>{$ltext}</td>\n" ;
93 if ( $count == 0 ) $l .= "<tr>" ;
94 $l .= $ltext ;
95 if ( $count == $perrow-1 )
96 {
97 $l .= "</tr>" ;
98 $count = 0 ;
99 }
100 else $count++ ;
101 }
102 }
103 }
104 if ( $count != 0 ) $l .= "</tr>" ;
105 $l .= "</table>" ;
106
107 print "<html><head></head><body>" ;
108 print $l ;
109 print "</body></html>" ;
110
111 ?>