MediaWiki
REL1_39
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
LinkBatchFactory
$linkBatchFactory,
44
LinkRenderer
$linkRenderer,
45
ILoadBalancer
$loadBalancer,
46
$from
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
$this->linkBatchFactory = $linkBatchFactory;
52
$from = str_replace(
' '
,
'_'
, $from );
53
if
( $from !==
''
) {
54
$from = Title::capitalize( $from,
NS_CATEGORY
);
55
$this->
setOffset
( $from );
56
$this->
setIncludeOffset
(
true
);
57
}
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'
, [], $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\getStartForm
getStartForm( $from)
Definition
CategoryPager.php:103
CategoryPager\__construct
__construct(IContextSource $context, LinkBatchFactory $linkBatchFactory, LinkRenderer $linkRenderer, ILoadBalancer $loadBalancer, $from)
Definition
CategoryPager.php:41
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
ContextSource.php:209
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:164
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition
ContextSource.php:47
IndexPager\getLinkRenderer
getLinkRenderer()
Definition
IndexPager.php:1089
IndexPager\$mDefaultQuery
array $mDefaultQuery
Definition
IndexPager.php:150
IndexPager\setOffset
setOffset( $offset)
Set the offset from an other source than the request.
Definition
IndexPager.php:323
IndexPager\setIncludeOffset
setIncludeOffset( $include)
Set whether a row matching exactly the offset should be also included in the result or not.
Definition
IndexPager.php:363
MediaWiki\Cache\LinkBatchFactory
Definition
LinkBatchFactory.php:41
MediaWiki\Linker\LinkRenderer
Class that generates HTML anchor link elements 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
Create and track the database connections and transactions for a given database cluster.
Definition
ILoadBalancer.php:77
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
$title
$title
Definition
testCompression.php:38
includes
specials
pagers
CategoryPager.php
Generated on Sun Nov 24 2024 16:35:34 for MediaWiki by
1.10.0