| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Pager; |
| 23 |
|
| 24 |
use MediaWiki\Cache\LinkBatchFactory; |
| 25 |
use MediaWiki\Context\IContextSource; |
| 26 |
use MediaWiki\Html\Html; |
| 27 |
use MediaWiki\HTMLForm\HTMLForm; |
| 28 |
use MediaWiki\Linker\LinkRenderer; |
| 29 |
use MediaWiki\Title\Title; |
| 30 |
use MediaWiki\Title\TitleValue; |
| 31 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class CategoryPager extends AlphabeticPager { |
| 37 |
|
| 38 |
private LinkBatchFactory $linkBatchFactory; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function __construct( |
| 48 |
IContextSource $context, |
| 49 |
LinkBatchFactory $linkBatchFactory, |
| 50 |
LinkRenderer $linkRenderer, |
| 51 |
IConnectionProvider $dbProvider, |
| 52 |
$from |
| 53 |
) { |
| 54 |
|
| 55 |
$this->mDb = $dbProvider->getReplicaDatabase(); |
| 56 |
parent::__construct( $context, $linkRenderer ); |
| 57 |
$this->linkBatchFactory = $linkBatchFactory; |
| 58 |
$from = str_replace( ' ', '_', $from ); |
| 59 |
if ( $from !== '' ) { |
| 60 |
$from = Title::capitalize( $from, NS_CATEGORY ); |
| 61 |
$this->setOffset( $from ); |
| 62 |
$this->setIncludeOffset( true ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public function getQueryInfo() { |
| 67 |
return [ |
| 68 |
'tables' => [ 'category' ], |
| 69 |
'fields' => [ 'cat_title', 'cat_pages' ], |
| 70 |
'options' => [ 'USE INDEX' => 'cat_title' ], |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
public function getIndexField() { |
| 75 |
return 'cat_title'; |
| 76 |
} |
| 77 |
|
| 78 |
public function getDefaultQuery() { |
| 79 |
parent::getDefaultQuery(); |
| 80 |
unset( $this->mDefaultQuery['from'] ); |
| 81 |
|
| 82 |
return $this->mDefaultQuery; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
public function getBody() { |
| 87 |
$batch = $this->linkBatchFactory->newLinkBatch(); |
| 88 |
|
| 89 |
$this->mResult->rewind(); |
| 90 |
|
| 91 |
foreach ( $this->mResult as $row ) { |
| 92 |
$batch->add( NS_CATEGORY, $row->cat_title ); |
| 93 |
} |
| 94 |
$batch->execute(); |
| 95 |
$this->mResult->rewind(); |
| 96 |
|
| 97 |
return parent::getBody(); |
| 98 |
} |
| 99 |
|
| 100 |
public function formatRow( $result ) { |
| 101 |
$title = new TitleValue( NS_CATEGORY, $result->cat_title ); |
| 102 |
$text = $title->getText(); |
| 103 |
$link = $this->getLinkRenderer()->makeLink( $title, $text ); |
| 104 |
|
| 105 |
$count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped(); |
| 106 |
return Html::rawElement( 'li', [], $this->getLanguage()->specialList( $link, $count ) ) . "\n"; |
| 107 |
} |
| 108 |
|
| 109 |
public function getStartForm( $from ) { |
| 110 |
$formDescriptor = [ |
| 111 |
'from' => [ |
| 112 |
'type' => 'title', |
| 113 |
'namespace' => NS_CATEGORY, |
| 114 |
'relative' => true, |
| 115 |
'label-message' => 'categoriesfrom', |
| 116 |
'name' => 'from', |
| 117 |
'id' => 'from', |
| 118 |
'size' => 20, |
| 119 |
'default' => $from, |
| 120 |
], |
| 121 |
]; |
| 122 |
|
| 123 |
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ) |
| 124 |
->setSubmitTextMsg( 'categories-submit' ) |
| 125 |
->setWrapperLegendMsg( 'categories' ) |
| 126 |
->setMethod( 'get' ); |
| 127 |
return $htmlForm->prepareForm()->getHTML( false ); |
| 128 |
} |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
class_alias( CategoryPager::class, 'CategoryPager' ); |