Now use parserTests diff engine when an entry in the reference file given differs...
[lhc/web/wiklou.git] / maintenance / portal.php
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 ;
13
14 if ( isset ( $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ) )
15 $userlang = $HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] ;
16 else $userlang = '' ;
17
18 # Update local files
19 if ( isset ( $_GET["update"] ) )
20 {
21 copy ( $textsourcefile_web , $textsourcefile ) ;
22 copy ( $articlecountfile_web , $articlecountfile ) ;
23 }
24
25 /**
26 * Reads a file into a string
27 */
28 function readafile ( $filename )
29 {
30 $handle = fopen($filename, "r");
31 $contents = '';
32 while (!feof($handle))
33 $contents .= fread($handle, 8192);
34 fclose($handle);
35 return $contents ;
36 }
37
38 /** Parsing statistics file */
39 function get_numbers ( $filename )
40 {
41 $r = array () ;
42 $nt = readafile ( $filename ) ;
43 $nt = explode ( "\n" , $nt ) ;
44 foreach ( $nt AS $x )
45 {
46 $y = explode ( ":" , $x ) ;
47 if ( count ( $y ) == 2 )
48 $r[strtolower($y[0])] = $y[1] ;
49 }
50 return $r ;
51 }
52
53 /** Make shades for pref. language(s) */
54 function getshades ( $l )
55 {
56 $r = array () ;
57 $l = explode ( "," , $l ) ;
58 foreach ( $l AS $x )
59 {
60 $y = explode ( ";" , $x ) ;
61 if ( count ( $y ) == 2 ) $weight = array_pop ( explode ( "=" , $y[1] ) ) ;
62 else $weight = "1.0" ;
63
64 $lang = array_shift ( $y ) ;
65 $lang = explode ( "-" , $lang ) ;
66 $lang = trim ( strtolower ( array_shift ( $lang ) ) ) ;
67
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 ;
74 }
75 return $r ;
76 }
77
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 )
86 {
87 $y = explode ( ':' , $x , 2 ) ;
88 if ( count ( $y ) == 2 )
89 {
90 $language = trim ( strtolower ( $y[0] ) ) ; # language id
91 if ( isset ( $n[$language] ) ) # Only if there's a number to show
92 {
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 )
102 {
103 $l .= "</tr>" ;
104 $count = 0 ;
105 }
106 else $count++ ;
107 }
108 }
109 }
110 if ( $count != 0 ) $l .= "</tr>" ;
111 $l .= "</table>" ;
112
113 print "<html><head></head><body>" ;
114 print $l ;
115 print "</body></html>" ;
116
117 ?>