File: test.php

package info (click to toggle)
wikidiff2 1.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,908 kB
  • sloc: cpp: 2,875; php: 417; makefile: 14; sh: 3
file content (119 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (3)
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
115
116
117
118
119
<?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" );
}
if ( !function_exists( 'wikidiff2_inline_json_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
<!DOCTYPE html>
<html>
<title>Diff changes</title>
<meta charset="UTF-8"/>
<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 AllDiffer;

$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;