MediaWiki
REL1_35
CategoryPager.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\Linker\LinkRenderer
;
22
26
class
CategoryPager
extends
AlphabeticPager
{
27
33
public
function
__construct
(
IContextSource
$context
, $from,
LinkRenderer
$linkRenderer
34
) {
35
parent::__construct(
$context
,
$linkRenderer
);
36
$from = str_replace(
' '
,
'_'
, $from );
37
if
( $from !==
''
) {
38
$from = Title::capitalize( $from,
NS_CATEGORY
);
39
$this->
setOffset
( $from );
40
$this->
setIncludeOffset
(
true
);
41
}
42
}
43
44
public
function
getQueryInfo
() {
45
return
[
46
'tables'
=> [
'category'
],
47
'fields'
=> [
'cat_title'
,
'cat_pages'
],
48
'options'
=> [
'USE INDEX'
=>
'cat_title'
],
49
];
50
}
51
52
public
function
getIndexField
() {
53
return
'cat_title'
;
54
}
55
56
public
function
getDefaultQuery
() {
57
parent::getDefaultQuery();
58
unset( $this->mDefaultQuery[
'from'
] );
59
60
return
$this->mDefaultQuery
;
61
}
62
63
/* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
64
public
function
getBody
() {
65
$batch =
new
LinkBatch
;
66
67
$this->mResult->rewind();
68
69
foreach
( $this->mResult as $row ) {
70
$batch->
addObj
(
new
TitleValue
(
NS_CATEGORY
, $row->cat_title ) );
71
}
72
$batch->execute();
73
$this->mResult->rewind();
74
75
return
parent::getBody();
76
}
77
78
public
function
formatRow
( $result ) {
79
$title
=
new
TitleValue
(
NS_CATEGORY
, $result->cat_title );
80
$text =
$title
->getText();
81
$link = $this->
getLinkRenderer
()->makeLink(
$title
, $text );
82
83
$count = $this->
msg
(
'nmembers'
)->numParams( $result->cat_pages )->escaped();
84
return
Html::rawElement(
'li'
,
null
, $this->
getLanguage
()->specialList( $link, $count ) ) .
"\n"
;
85
}
86
87
public
function
getStartForm
( $from ) {
88
$formDescriptor = [
89
'from'
=> [
90
'type'
=>
'title'
,
91
'namespace'
=>
NS_CATEGORY
,
92
'relative'
=>
true
,
93
'label-message'
=>
'categoriesfrom'
,
94
'name'
=>
'from'
,
95
'id'
=>
'from'
,
96
'size'
=> 20,
97
'default'
=> $from,
98
],
99
];
100
101
$htmlForm = HTMLForm::factory(
'ooui'
, $formDescriptor, $this->
getContext
() )
102
->setSubmitTextMsg(
'categories-submit'
)
103
->setWrapperLegendMsg(
'categories'
)
104
->setMethod(
'get'
);
105
return
$htmlForm->prepareForm()->getHTML(
false
);
106
}
107
108
}
AlphabeticPager
IndexPager with an alphabetic list and a formatted navigation bar Stable to extend.
Definition
AlphabeticPager.php:29
CategoryPager
Definition
CategoryPager.php:26
CategoryPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition
CategoryPager.php:56
CategoryPager\getBody
getBody()
Get the formatted result list.
Definition
CategoryPager.php:64
CategoryPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition
CategoryPager.php:52
CategoryPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition
CategoryPager.php:44
CategoryPager\__construct
__construct(IContextSource $context, $from, LinkRenderer $linkRenderer)
Definition
CategoryPager.php:33
CategoryPager\formatRow
formatRow( $result)
Returns an HTML string representing the result row $row.
Definition
CategoryPager.php:78
CategoryPager\getStartForm
getStartForm( $from)
Definition
CategoryPager.php:87
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
ContextSource.php:184
ContextSource\$context
IContextSource $context
Definition
ContextSource.php:34
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:140
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition
ContextSource.php:42
IndexPager\getLinkRenderer
getLinkRenderer()
Definition
IndexPager.php:976
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:312
IndexPager\setIncludeOffset
setIncludeOffset( $include)
Set whether a row matching exactly the offset should be also included in the result or not.
Definition
IndexPager.php:352
IndexPager\$linkRenderer
LinkRenderer $linkRenderer
Definition
IndexPager.php:167
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition
LinkBatch.php:35
LinkBatch\addObj
addObj( $linkTarget)
Definition
LinkBatch.php:118
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:39
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:84
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:55
$title
$title
Definition
testCompression.php:38
includes
specials
pagers
CategoryPager.php
Generated on Sat Apr 6 2024 00:07:56 for MediaWiki by
1.9.8