MediaWiki  master
CategoryPager.php
Go to the documentation of this file.
1 <?php
25 
30 
33 
40  public function __construct(
42  $from,
45  ) {
46  parent::__construct( $context, $linkRenderer );
47  $from = str_replace( ' ', '_', $from );
48  if ( $from !== '' ) {
49  $from = Title::capitalize( $from, NS_CATEGORY );
50  $this->setOffset( $from );
51  $this->setIncludeOffset( true );
52  }
53  $this->linkBatchFactory = $linkBatchFactory ?? MediaWikiServices::getInstance()->getLinkBatchFactory();
54  }
55 
56  public function getQueryInfo() {
57  return [
58  'tables' => [ 'category' ],
59  'fields' => [ 'cat_title', 'cat_pages' ],
60  'options' => [ 'USE INDEX' => 'cat_title' ],
61  ];
62  }
63 
64  public function getIndexField() {
65  return 'cat_title';
66  }
67 
68  public function getDefaultQuery() {
69  parent::getDefaultQuery();
70  unset( $this->mDefaultQuery['from'] );
71 
72  return $this->mDefaultQuery;
73  }
74 
75  /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
76  public function getBody() {
77  $batch = $this->linkBatchFactory->newLinkBatch();
78 
79  $this->mResult->rewind();
80 
81  foreach ( $this->mResult as $row ) {
82  $batch->add( NS_CATEGORY, $row->cat_title );
83  }
84  $batch->execute();
85  $this->mResult->rewind();
86 
87  return parent::getBody();
88  }
89 
90  public function formatRow( $result ) {
91  $title = new TitleValue( NS_CATEGORY, $result->cat_title );
92  $text = $title->getText();
93  $link = $this->getLinkRenderer()->makeLink( $title, $text );
94 
95  $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped();
96  return Html::rawElement( 'li', null, $this->getLanguage()->specialList( $link, $count ) ) . "\n";
97  }
98 
99  public function getStartForm( $from ) {
100  $formDescriptor = [
101  'from' => [
102  'type' => 'title',
103  'namespace' => NS_CATEGORY,
104  'relative' => true,
105  'label-message' => 'categoriesfrom',
106  'name' => 'from',
107  'id' => 'from',
108  'size' => 20,
109  'default' => $from,
110  ],
111  ];
112 
113  $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
114  ->setSubmitTextMsg( 'categories-submit' )
115  ->setWrapperLegendMsg( 'categories' )
116  ->setMethod( 'get' );
117  return $htmlForm->prepareForm()->getHTML( false );
118  }
119 
120 }
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:42
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:158
CategoryPager\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: CategoryPager.php:32
MediaWiki\Linker\LinkRenderer
Class that generates HTML links for pages.
Definition: LinkRenderer.php:41
AlphabeticPager
IndexPager with an alphabetic list and a formatted navigation bar Stable to extend.
Definition: AlphabeticPager.php:29
IndexPager\$linkRenderer
LinkRenderer $linkRenderer
Definition: IndexPager.php:167
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:140
CategoryPager\getBody
getBody()
Get the formatted result list.
Definition: CategoryPager.php:76
CategoryPager\getQueryInfo
getQueryInfo()
Provides all parameters needed for the main paged query.
Definition: CategoryPager.php:56
CategoryPager\getStartForm
getStartForm( $from)
Definition: CategoryPager.php:99
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:38
$title
$title
Definition: testCompression.php:38
CategoryPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition: CategoryPager.php:68
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:83
CategoryPager
Definition: CategoryPager.php:29
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
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:184
IndexPager\setOffset
setOffset( $offset)
Set the offset from an other source than the request.
Definition: IndexPager.php:312
IndexPager\getLinkRenderer
getLinkRenderer()
Definition: IndexPager.php:976
CategoryPager\formatRow
formatRow( $result)
Returns an HTML string representing the result row $row.
Definition: CategoryPager.php:90
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Title\capitalize
static capitalize( $text, $ns=NS_MAIN)
Capitalize a text string for a title if it belongs to a namespace that capitalizes.
Definition: Title.php:3276
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
CategoryPager\__construct
__construct(IContextSource $context, $from, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory=null)
Definition: CategoryPager.php:40
HTMLForm\factory
static factory( $displayFormat,... $arguments)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:315
IndexPager\$mDefaultQuery
array $mDefaultQuery
Definition: IndexPager.php:149
CategoryPager\getIndexField
getIndexField()
Returns the name of the index field.
Definition: CategoryPager.php:64
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:39