-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
114 lines (94 loc) · 2.13 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* wikidiff2 PHP extension test suite. Loads a lot of real changes
* from Wikipedia and generates diffs of it.
*
* License: WTFPL
*/
if ( !function_exists( 'wikidiff2_inline_diff' ) ) {
die( "wikidiff2 not found, nothing to test\n" );
}
ini_set( 'user_agent', 'Hi, Domas!' );
// Bail out early in case of any problems
error_reporting( E_ALL | E_STRICT );
set_error_handler( function( $errno , $errstr ) {
echo htmlspecialchars( $errstr );
die ( 1 );
} );
echo <<<HTML
<html>
<title>Diff changes</title>
<style>
body {
font-family: sans-serif;
}
table,
td {
border:1px solid #000
}
ins,
del {
padding-left: 0;
color: black;
text-decoration: none;
}
span {
margin-right: 2px;
}
ins {
background-color: #75C877;
}
del {
background-color: #E07076;
}
</style>
<body>
HTML;
require 'Api.php';
require 'Change.php';
require 'Differ.php';
$differ = new BothDiffer;
$site = "http://en.wikipedia.org/w";
$apiUrl = "$site/api.php";
$indexUrl = "$site/index.php";
$recentChanges = Api::request( array(
'action' => 'query',
'list' => 'recentchanges',
'rctype' => 'edit',
'rclimit' => 'max',
) );
$changes = array();
foreach ( $recentChanges['query']['recentchanges'] as $rc ) {
$changes[] = new Change( $rc['title'], $rc['old_revid'], $rc['revid'] );
}
$count = count( $changes );
echo "<h1>Found $count changes</h1>\n";
$count = 0;
$numProcessed = 0;
$totalTime = 0;
foreach ( $changes as $change ) {
$id = sprintf( "%04d", $count );
$page = htmlspecialchars( $change->page );
echo "\n<h2>[$id] {$page}</h2>\n";
if ( !$change->load() ) {
echo "<b>Not all content loaded, skipping</b><br>\n";
}
$time = microtime( true );
$diff = $differ->diff( $change->prev, $change->next );
$time = microtime( true ) - $time;
$totalTime += $time;
$numProcessed++;
echo "Diffed in {$time}s<br>\n";
$url = htmlspecialchars( "$indexUrl?diff={$change->nextId}&oldid={$change->prevId}" );
echo "<a href='$url'>$url</a>";
echo $diff;
$count++;
}
$avg = $numProcessed ? $totalTime / $numProcessed : 0;
echo <<<HTML
<table>
<tr><td>Total processed</td><td>$numProcessed</td></tr>
<tr><td>Average diff time</td><td>$avg</td></tr>
</table>
</html>
HTML;