MediaWiki
REL1_37
WikiPageFactory.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Page
;
4
5
use
DBAccessObjectUtils
;
6
use InvalidArgumentException;
7
use
MediaWiki\Linker\LinkTarget
;
8
use
MediaWiki\Page\Hook\WikiPageFactoryHook
;
9
use stdClass;
10
use
Title
;
11
use
TitleFactory
;
12
use
WikiCategoryPage
;
13
use
WikiFilePage
;
14
use
Wikimedia\Rdbms\ILoadBalancer
;
15
use
WikiPage
;
16
20
class
WikiPageFactory
{
21
23
private
$titleFactory
;
24
26
private
$wikiPageFactoryHookRunner
;
27
29
private
$loadBalancer
;
30
36
public
function
__construct
(
37
TitleFactory
$titleFactory
,
38
WikiPageFactoryHook
$wikiPageFactoryHookRunner
,
39
ILoadBalancer
$loadBalancer
40
) {
41
$this->titleFactory =
$titleFactory
;
42
$this->wikiPageFactoryHookRunner =
$wikiPageFactoryHookRunner
;
43
$this->loadBalancer =
$loadBalancer
;
44
}
45
53
public
function
newFromTitle
(
PageIdentity
$pageIdentity ) {
54
if
( $pageIdentity instanceof
WikiPage
) {
55
return
$pageIdentity;
56
}
57
58
if
( !$pageIdentity->
canExist
() ) {
59
// BC with the Title class
60
throw
new
InvalidArgumentException(
61
"The given PageIdentity does not represent a proper page"
62
);
63
}
64
65
$ns = $pageIdentity->
getNamespace
();
66
67
// TODO: remove the need for casting to Title. We'll have to create a new hook to
68
// replace the WikiPageFactory hook.
69
$title
= Title::castFromPageIdentity( $pageIdentity );
70
71
$page =
null
;
72
if
( !$this->wikiPageFactoryHookRunner->onWikiPageFactory(
$title
, $page ) ) {
73
return
$page;
74
}
75
76
switch
( $ns ) {
77
case
NS_FILE
:
78
$page =
new
WikiFilePage
(
$title
);
79
break
;
80
case
NS_CATEGORY
:
81
$page =
new
WikiCategoryPage
(
$title
);
82
break
;
83
default
:
84
$page =
new
WikiPage
(
$title
);
85
}
86
87
return
$page;
88
}
89
97
public
function
newFromLinkTarget
(
LinkTarget
$title
) {
98
return
$this->
newFromTitle
( $this->titleFactory->newFromLinkTarget(
$title
) );
99
}
100
112
public
function
newFromRow
( $row, $from =
'fromdb'
) {
113
$page = $this->
newFromTitle
( $this->titleFactory->newFromRow( $row ) );
114
$page->loadFromRow( $row, $from );
115
return
$page;
116
}
117
128
public
function
newFromID
( $id, $from =
'fromdb'
) {
129
// page ids are never 0 or negative, see T63166
130
if
( $id < 1 ) {
131
return
null
;
132
}
133
134
$from = WikiPage::convertSelectType( $from );
135
[ $index ] = DBAccessObjectUtils::getDBOptions( $from );
136
$db = $this->loadBalancer->getMaintenanceConnectionRef( $index );
137
$pageQuery = WikiPage::getQueryInfo();
138
$row = $db->selectRow(
139
$pageQuery[
'tables'
], $pageQuery[
'fields'
], [
'page_id'
=> $id ], __METHOD__,
140
[], $pageQuery[
'joins'
]
141
);
142
if
( !$row ) {
143
return
null
;
144
}
145
return
$this->
newFromRow
( $row, $from );
146
}
147
148
}
NS_FILE
const NS_FILE
Definition
Defines.php:70
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:78
DBAccessObjectUtils
Helper class for DAO classes.
Definition
DBAccessObjectUtils.php:29
MediaWiki\Page\WikiPageFactory
Definition
WikiPageFactory.php:20
MediaWiki\Page\WikiPageFactory\__construct
__construct(TitleFactory $titleFactory, WikiPageFactoryHook $wikiPageFactoryHookRunner, ILoadBalancer $loadBalancer)
Definition
WikiPageFactory.php:36
MediaWiki\Page\WikiPageFactory\$wikiPageFactoryHookRunner
WikiPageFactoryHook $wikiPageFactoryHookRunner
Definition
WikiPageFactory.php:26
MediaWiki\Page\WikiPageFactory\newFromID
newFromID( $id, $from='fromdb')
Create a WikiPage object from a page ID.
Definition
WikiPageFactory.php:128
MediaWiki\Page\WikiPageFactory\newFromTitle
newFromTitle(PageIdentity $pageIdentity)
Create a WikiPage object from a title.
Definition
WikiPageFactory.php:53
MediaWiki\Page\WikiPageFactory\newFromRow
newFromRow( $row, $from='fromdb')
Create a WikiPage object from a database row.
Definition
WikiPageFactory.php:112
MediaWiki\Page\WikiPageFactory\$titleFactory
TitleFactory $titleFactory
Definition
WikiPageFactory.php:23
MediaWiki\Page\WikiPageFactory\newFromLinkTarget
newFromLinkTarget(LinkTarget $title)
Create a WikiPage object from a link target.
Definition
WikiPageFactory.php:97
MediaWiki\Page\WikiPageFactory\$loadBalancer
ILoadBalancer $loadBalancer
Definition
WikiPageFactory.php:29
TitleFactory
Creates Title objects.
Definition
TitleFactory.php:35
Title
Represents a title within MediaWiki.
Definition
Title.php:48
WikiCategoryPage
Special handling for category pages.
Definition
WikiCategoryPage.php:26
WikiFilePage
Special handling for file pages.
Definition
WikiFilePage.php:31
WikiPage
Class representing a MediaWiki article and history.
Definition
WikiPage.php:60
MediaWiki\Linker\LinkTarget
Definition
LinkTarget.php:26
MediaWiki\Page\Hook\WikiPageFactoryHook
This is a hook handler interface, see docs/Hooks.md.
Definition
WikiPageFactoryHook.php:15
MediaWiki\Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition
PageIdentity.php:64
MediaWiki\Page\PageIdentity\canExist
canExist()
Checks whether this PageIdentity represents a "proper" page, meaning that it could exist as an editab...
MediaWiki\Page\PageReference\getNamespace
getNamespace()
Returns the page's namespace number.
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition
ILoadBalancer.php:81
MediaWiki\Page
Definition
ContentModelChangeFactory.php:23
$title
$title
Definition
testCompression.php:38
includes
page
WikiPageFactory.php
Generated on Fri Apr 5 2024 23:40:39 for MediaWiki by
1.9.8