MediaWiki
REL1_31
CategoryPager.php
Go to the documentation of this file.
1
<?php
21
use
MediaWiki\Linker\LinkRenderer
;
22
26
class
CategoryPager
extends
AlphabeticPager
{
27
31
protected
$linkRenderer
;
32
38
public
function
__construct
(
IContextSource
$context
, $from,
LinkRenderer
$linkRenderer
39
) {
40
parent::__construct(
$context
);
41
$from = str_replace(
' '
,
'_'
, $from );
42
if
( $from !==
''
) {
43
$from = Title::capitalize( $from,
NS_CATEGORY
);
44
$this->
setOffset
( $from );
45
$this->
setIncludeOffset
(
true
);
46
}
47
48
$this->linkRenderer =
$linkRenderer
;
49
}
50
51
function
getQueryInfo
() {
52
return
[
53
'tables'
=> [
'category'
],
54
'fields'
=> [
'cat_title'
,
'cat_pages'
],
55
'options'
=> [
'USE INDEX'
=>
'cat_title'
],
56
];
57
}
58
59
function
getIndexField
() {
60
return
'cat_title'
;
61
}
62
63
function
getDefaultQuery
() {
64
parent::getDefaultQuery();
65
unset( $this->mDefaultQuery[
'from'
] );
66
67
return
$this->mDefaultQuery
;
68
}
69
70
/* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
71
public
function
getBody
() {
72
$batch
=
new
LinkBatch
;
73
74
$this->mResult->rewind();
75
76
foreach
( $this->mResult as $row ) {
77
$batch
->
addObj
(
new
TitleValue
(
NS_CATEGORY
, $row->cat_title ) );
78
}
79
$batch
->execute();
80
$this->mResult->rewind();
81
82
return
parent::getBody();
83
}
84
85
function
formatRow
( $result ) {
86
$title =
new
TitleValue
(
NS_CATEGORY
, $result->cat_title );
87
$text = $title->getText();
88
$link
= $this->linkRenderer->makeLink( $title, $text );
89
90
$count = $this->
msg
(
'nmembers'
)->numParams( $result->cat_pages )->escaped();
91
return
Html::rawElement(
'li'
,
null
, $this->
getLanguage
()->specialList(
$link
, $count ) ) .
"\n"
;
92
}
93
94
public
function
getStartForm
( $from ) {
95
$formDescriptor = [
96
'from'
=> [
97
'type'
=>
'title'
,
98
'namespace'
=>
NS_CATEGORY
,
99
'relative'
=>
true
,
100
'label-message'
=>
'categoriesfrom'
,
101
'name'
=>
'from'
,
102
'id'
=>
'from'
,
103
'size'
=> 20,
104
'default'
=> $from,
105
],
106
];
107
108
$htmlForm = HTMLForm::factory(
'ooui'
, $formDescriptor, $this->
getContext
() )
109
->setSubmitTextMsg(
'categories-submit'
)
110
->setWrapperLegendMsg(
'categories'
)
111
->setMethod(
'get'
);
112
return
$htmlForm->prepareForm()->getHTML(
false
);
113
}
114
115
}
AlphabeticPager
IndexPager with an alphabetic list and a formatted navigation bar.
Definition
AlphabeticPager.php:28
CategoryPager
Definition
CategoryPager.php:26
CategoryPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition
CategoryPager.php:63
CategoryPager\getBody
getBody()
Get the formatted result list.
Definition
CategoryPager.php:71
CategoryPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition
CategoryPager.php:59
CategoryPager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition
CategoryPager.php:51
CategoryPager\__construct
__construct(IContextSource $context, $from, LinkRenderer $linkRenderer)
Definition
CategoryPager.php:38
CategoryPager\formatRow
formatRow( $result)
Abstract formatting function.
Definition
CategoryPager.php:85
CategoryPager\$linkRenderer
LinkRenderer $linkRenderer
Definition
CategoryPager.php:31
CategoryPager\getStartForm
getStartForm( $from)
Definition
CategoryPager.php:94
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition
ContextSource.php:168
ContextSource\$context
IContextSource $context
Definition
ContextSource.php:33
ContextSource\getLanguage
getLanguage()
Definition
ContextSource.php:128
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition
ContextSource.php:40
IndexPager\setOffset
setOffset( $offset)
Set the offset from an other source than the request.
Definition
IndexPager.php:246
IndexPager\setIncludeOffset
setIncludeOffset( $include)
Set whether a row matching exactly the offset should be also included in the result or not.
Definition
IndexPager.php:284
IndexPager\$mDefaultQuery
$mDefaultQuery
Definition
IndexPager.php:117
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition
LinkBatch.php:34
LinkBatch\addObj
addObj( $linkTarget)
Definition
LinkBatch.php:68
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition
LinkRenderer.php:41
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition
TitleValue.php:35
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition
hooks.txt:3021
NS_CATEGORY
const NS_CATEGORY
Definition
Defines.php:88
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:53
$batch
$batch
Definition
linkcache.txt:23
includes
specials
pagers
CategoryPager.php
Generated on Mon Nov 25 2024 15:35:24 for MediaWiki by
1.10.0