Completed
Pull Request — master (#49)
by Sam
03:09
created

PageWatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\DataModel\Page;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class PageWatcher extends Service {
14
15
	/**
16
	 * @param Page $page
17
	 *
18
	 * @return bool
19
	 */
20
	public function watch( Page $page ) {
21
		$params = [
22
			'token' => $this->api->getToken( 'watch' ),
23
		];
24
		if ( !is_null( $page->getPageIdentifier()->getId() ) ) {
25
			$params['pageids'] = $page->getPageIdentifier()->getId();
26
		} elseif ( !is_null( $page->getPageIdentifier()->getTitle() ) ) {
27
			$params['titles'] = $page->getPageIdentifier()->getTitle()->getTitle();
0 ignored issues
show
Deprecated Code introduced by
The method Mediawiki\DataModel\Title::getTitle() has been deprecated with message: in 0.6 use getText (makes things look cleaner)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
		} elseif ( !is_null( $page->getRevisions()->getLatest() ) ) {
29
			$params['revids'] = $page->getRevisions()->getLatest()->getId();
30
		}
31
32
		$this->api->postRequest( new SimpleRequest( 'watch', $params ) );
33
34
		return true;
35
	}
36
37
}
38