MediaWiki
REL1_37
CategoryPager.php
Go to the documentation of this file.
1
<?php
22
use
MediaWiki\Cache\LinkBatchFactory
;
23
use
MediaWiki\Linker\LinkRenderer
;
24
use
Wikimedia\Rdbms\ILoadBalancer
;
25
29
class
CategoryPager
extends
AlphabeticPager
{
30
32
private
$linkBatchFactory
;
33
41
public
function
__construct
(
42
IContextSource
$context
,
43
$from,
44
LinkRenderer
$linkRenderer
,
45
LinkBatchFactory
$linkBatchFactory
,
46
ILoadBalancer
$loadBalancer
47
) {
48
// Set database before parent constructor to avoid setting it there with wfGetDB
49
$this->mDb = $loadBalancer->
getConnectionRef
( ILoadBalancer::DB_REPLICA );
50
parent::__construct(
$context
,
$linkRenderer
);
51
$from = str_replace(
' '
,
'_'
, $from );
52
if
( $from !==
''
) {
53
$from = Title::capitalize( $from,
NS_CATEGORY
);
54
$this->
setOffset
( $from );
55
$this->
setIncludeOffset
(
true
);
56
}
57
$this->linkBatchFactory =
$linkBatchFactory
;
58
}
59
60
public
function
getQueryInfo
() {
61
return
[
62
'tables'
=> [
'category'
],
63
'fields'
=> [
'cat_title'
,
'cat_pages'
],
64
'options'
=> [
'USE INDEX'
=>
'cat_title'
],
65
];
66
}
67
68
public
function
getIndexField
() {
69
return
'cat_title'
;
70
}
71
72
public
function
getDefaultQuery
() {
73
parent::getDefaultQuery();
74
unset( $this->mDefaultQuery[
'from'
] );
75
76
return
$this->mDefaultQuery
;
77
}
78
79
/* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
80
public
function
getBody
() {
81
$batch = $this->linkBatchFactory->newLinkBatch();
82
83
$this->mResult->rewind();
84
85
foreach
( $this->mResult as $row ) {
86
$batch->add(
NS_CATEGORY
, $row->cat_title );
87
}
88
$batch->execute();
89
$this->mResult->rewind();
90
91
return
parent::getBody();
92
}
93
94
public
function
formatRow
( $result ) {
95
$title
=
new
TitleValue
(
NS_CATEGORY
, $result->cat_title );
96
$text =
$title
->getText();
97
$link = $this->
getLinkRenderer
()->makeLink(
$title
, $text );
98
99
$count = $this->
msg
(
'nmembers'
)->numParams( $result->cat_pages )->escaped();
100
return
Html::rawElement(
'li'
,
null
, $this->
getLanguage
()->specialList( $link, $count ) ) .
"\n"
;
101
}
102
103
public
function
getStartForm
( $from ) {
104
$formDescriptor = [
105
'from'
=> [
106
'type'
=>
'title'
,
107
'namespace'
=>
NS_CATEGORY
,
108
'relative'
=>
true
,
109
'label-message'
=>
'categoriesfrom'
,
110
'name'
=>
'from'
,
111
'id'
=>
'from'
,
112
'size'
=> 20,
113
'default'
=> $from,
114
],
115
];
116
117
$htmlForm = HTMLForm::factory(
'ooui'
, $formDescriptor, $this->
getContext
() )
118
->setSubmitTextMsg(
'categories-submit'
)
119
->setWrapperLegendMsg(
'categories'
)
120
->setMethod(
'get'
);
121
return
$htmlForm->prepareForm()->getHTML(
false
);
122
}
123
124
}
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:78
AlphabeticPager
IndexPager with an alphabetic list and a formatted navigation bar.
Definition
AlphabeticPager.php:29
CategoryPager
Definition
CategoryPager.php:29
CategoryPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition
CategoryPager.php:72
CategoryPager\getBody
getBody()
Get the formatted result list.
Definition
CategoryPager.php:80
CategoryPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition
CategoryPager.php:68
CategoryPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition
CategoryPager.php:60
CategoryPager\formatRow
formatRow( $result)
Returns an HTML string representing the result row $row.
Definition
CategoryPager.php:94
CategoryPager\__construct
__construct(IContextSource $context, $from, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, ILoadBalancer $loadBalancer)
Definition
CategoryPager.php:41
CategoryPager\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition
CategoryPager.php:32
CategoryPager\getStartForm
getStartForm( $from)
Definition
CategoryPager.php:103
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
ContextSource.php:197
ContextSource\$context
IContextSource $context
Definition
ContextSource.php:39
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:153
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition
ContextSource.php:47
IndexPager\getLinkRenderer
getLinkRenderer()
Definition
IndexPager.php:982
IndexPager\$mDefaultQuery
array $mDefaultQuery
Definition
IndexPager.php:149
IndexPager\setOffset
setOffset( $offset)
Set the offset from an other source than the request.
Definition
IndexPager.php:314
IndexPager\setIncludeOffset
setIncludeOffset( $include)
Set whether a row matching exactly the offset should be also included in the result or not.
Definition
IndexPager.php:354
IndexPager\$linkRenderer
LinkRenderer $linkRenderer
Definition
IndexPager.php:167
MediaWiki\Cache\LinkBatchFactory
Definition
LinkBatchFactory.php:39
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition
LinkRenderer.php:43
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition
TitleValue.php:40
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:58
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition
ILoadBalancer.php:81
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a live database handle reference for a server index.
$title
$title
Definition
testCompression.php:38
includes
specials
pagers
CategoryPager.php
Generated on Fri Apr 5 2024 23:40:56 for MediaWiki by
1.9.8