1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xtools; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A Page is a single wiki page in one project. |
7
|
|
|
*/ |
8
|
|
|
class Page extends Model |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** @var Project */ |
12
|
|
|
protected $project; |
13
|
|
|
|
14
|
|
|
/** @var string */ |
15
|
|
|
protected $unnormalizedPageName; |
16
|
|
|
|
17
|
|
|
/** @var string[] Metadata about this page. */ |
18
|
|
|
protected $pageInfo; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Page constructor. |
22
|
|
|
* @param Project $project |
23
|
|
|
* @param string $pageName |
24
|
|
|
*/ |
25
|
|
|
public function __construct(Project $project, $pageName) |
26
|
|
|
{ |
27
|
|
|
$this->project = $project; |
28
|
|
|
$this->unnormalizedPageName = $pageName; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get basic information about this page from the repository. |
33
|
|
|
* @return \string[] |
34
|
|
|
*/ |
35
|
|
|
protected function getPageInfo() |
36
|
|
|
{ |
37
|
|
|
if (!$this->pageInfo) { |
|
|
|
|
38
|
|
|
$this->pageInfo = $this->getRepository() |
|
|
|
|
39
|
|
|
->getPageInfo($this->project, $this->unnormalizedPageName); |
40
|
|
|
} |
41
|
|
|
return $this->pageInfo; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function getTitle() |
48
|
|
|
{ |
49
|
|
|
$info = $this->getPageInfo(); |
50
|
|
|
return isset($info['title']) ? $info['title'] : $this->unnormalizedPageName; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get this page's database ID. |
55
|
|
|
* @return int |
56
|
|
|
*/ |
57
|
|
|
public function getId() |
58
|
|
|
{ |
59
|
|
|
$info = $this->getPageInfo(); |
60
|
|
|
return isset($info['pageid']) ? $info['pageid'] : null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get HTML for the stylized display of the title. |
65
|
|
|
* The text will be the same as Page::getTitle(). |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getDisplayTitle() |
69
|
|
|
{ |
70
|
|
|
$info = $this->getPageInfo(); |
71
|
|
|
if (isset($info['displaytitle'])) { |
72
|
|
|
return $info['displaytitle']; |
73
|
|
|
} |
74
|
|
|
return $this->getTitle(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getUrl() |
81
|
|
|
{ |
82
|
|
|
$info = $this->getPageInfo(); |
83
|
|
|
return isset($info['fullurl']) ? $info['fullurl'] : null; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function exists() |
90
|
|
|
{ |
91
|
|
|
$info = $this->getPageInfo(); |
92
|
|
|
return !isset($info['missing']); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.