File: Change.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 (43 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (7)
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
<?php

class Change {
	public $page;
	public $prevId, $nextId;
	public $prev, $next;

	public function __construct( $page, $prevId, $nextId ) {
		$this->page = $page;
		$this->prevId = $prevId;
		$this->nextId = $nextId;
	}

	public function load() {
		$data = Api::request(
			array(
				'action' => 'query',
				'prop' => 'revisions',
				'rvprop' => 'ids|content',
				'revids' => "{$this->prevId}|{$this->nextId}",
			)
		);
		foreach( $data['query']['pages'] as $page ) {
			if ( $page['title'] != $this->page ) {
				continue;
			}
			foreach ( $page['revisions'] as $rev ) {
				$revid = $rev['revid'];
				if ( !isset( $rev['*'] ) ) {
					echo "Revision $revid not found\n";
					return false;
				}
				$text = $rev['*'];
				if ( $revid == $this->prevId ) {
					$this->prev = $text;
				} elseif ( $revid == $this->nextId ) {
					$this->next = $text;
				}
			}
		}
		return !is_null( $this->prev ) && !is_null( $this->next );
	}
}