Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 63 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| TemplatePager | |
0.00% |
0 / 63 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| getQueryInfo | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
| getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| formatRow | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| getStartBody | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| getEndBody | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | use MediaWiki\Html\Html; |
| 4 | use MediaWiki\Pager\ReverseChronologicalPager; |
| 5 | use MediaWiki\SpecialPage\SpecialPage; |
| 6 | use MediaWiki\Title\Title; |
| 7 | use Wikimedia\Rdbms\IExpression; |
| 8 | use Wikimedia\Rdbms\LikeValue; |
| 9 | |
| 10 | /** |
| 11 | * Provides pagination functionality for viewing banner lists in the CentralNotice admin interface. |
| 12 | * |
| 13 | * @deprecated 2.3 -- We're moving to an HTML form model and this is no longer used directly. |
| 14 | * We still need to move the Campaign manager to HTMLForm though and so this still exists for |
| 15 | * that part of CN. |
| 16 | */ |
| 17 | class TemplatePager extends ReverseChronologicalPager { |
| 18 | /** @var string */ |
| 19 | public $onRemoveChange; |
| 20 | /** @var Title */ |
| 21 | public $viewPage; |
| 22 | /** @var bool */ |
| 23 | public $editable; |
| 24 | |
| 25 | public function __construct( |
| 26 | CentralNotice $special, |
| 27 | protected readonly string $filter = '', |
| 28 | ) { |
| 29 | $this->editable = $special->editable; |
| 30 | parent::__construct(); |
| 31 | |
| 32 | // Override paging defaults |
| 33 | [ $this->mLimit, ] = $this->mRequest->getLimitOffsetForUser( |
| 34 | $this->getUser(), |
| 35 | 20, |
| 36 | '' |
| 37 | ); |
| 38 | $this->mLimitsShown = [ 20, 50, 100 ]; |
| 39 | |
| 40 | $msg = Html::encodeJsVar( $this->msg( 'centralnotice-confirm-delete' )->text() ); |
| 41 | $this->onRemoveChange = "if( this.checked ) { this.checked = confirm( $msg ) }"; |
| 42 | $this->viewPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Set the database query to retrieve all the banners in the database |
| 47 | * |
| 48 | * @return array of query settings |
| 49 | */ |
| 50 | public function getQueryInfo() { |
| 51 | $dbr = CNDatabase::getReplicaDb(); |
| 52 | |
| 53 | // When the filter comes in it is space delimited, so break that... |
| 54 | $likeArray = preg_split( '/\s+/', $this->filter ); |
| 55 | |
| 56 | // ...and then insert all the wildcards betwean search terms |
| 57 | if ( !$likeArray ) { |
| 58 | $likeArray = [ $dbr->anyString() ]; |
| 59 | } else { |
| 60 | $anyStringToken = $dbr->anyString(); |
| 61 | $tempArray = [ $anyStringToken ]; |
| 62 | foreach ( $likeArray as $likePart ) { |
| 63 | $tempArray[] = $likePart; |
| 64 | $tempArray[] = $anyStringToken; |
| 65 | } |
| 66 | $likeArray = $tempArray; |
| 67 | } |
| 68 | |
| 69 | return [ |
| 70 | 'tables' => [ 'templates' => 'cn_templates' ], |
| 71 | 'fields' => [ 'templates.tmp_name', 'templates.tmp_id' ], |
| 72 | 'conds' => [ $dbr->expr( 'templates.tmp_name', IExpression::LIKE, new LikeValue( ...$likeArray ) ) ], |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sort the banner list by tmp_id (generally equals reverse chronological) |
| 78 | * |
| 79 | * @return string |
| 80 | */ |
| 81 | public function getIndexField() { |
| 82 | return 'templates.tmp_id'; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Generate the content of each table row (1 row = 1 banner) |
| 87 | * |
| 88 | * @param stdClass $row database row |
| 89 | * |
| 90 | * @return string HTML |
| 91 | */ |
| 92 | public function formatRow( $row ) { |
| 93 | // Begin banner row |
| 94 | $htmlOut = Html::openElement( 'tr' ); |
| 95 | |
| 96 | if ( $this->editable ) { |
| 97 | // Remove box |
| 98 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top' ], |
| 99 | Html::check( 'removeTemplates[]', false, |
| 100 | [ |
| 101 | 'value' => $row->tmp_name, |
| 102 | 'onchange' => $this->onRemoveChange |
| 103 | ] |
| 104 | ) |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | // Render banner row. |
| 109 | $htmlOut .= Html::rawElement( 'td', [ 'valign' => 'top' ], |
| 110 | BannerRenderer::linkToBanner( $row->tmp_name ) |
| 111 | ); |
| 112 | |
| 113 | // End banner row |
| 114 | $htmlOut .= Html::closeElement( 'tr' ); |
| 115 | |
| 116 | return $htmlOut; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Specify table headers |
| 121 | * |
| 122 | * @return string HTML |
| 123 | */ |
| 124 | public function getStartBody() { |
| 125 | $htmlOut = ''; |
| 126 | $htmlOut .= Html::openElement( 'table', [ 'cellpadding' => 9 ] ); |
| 127 | $htmlOut .= Html::openElement( 'tr' ); |
| 128 | if ( $this->editable ) { |
| 129 | $htmlOut .= Html::element( 'th', [ 'align' => 'left', 'width' => '5%' ], |
| 130 | $this->msg( 'centralnotice-remove' )->text() |
| 131 | ); |
| 132 | } |
| 133 | $htmlOut .= Html::element( 'th', [ 'align' => 'left' ], |
| 134 | $this->msg( 'centralnotice-templates' )->text() |
| 135 | ); |
| 136 | $htmlOut .= Html::closeElement( 'tr' ); |
| 137 | return $htmlOut; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Close table and add Submit button |
| 142 | * |
| 143 | * @return string HTML |
| 144 | */ |
| 145 | public function getEndBody() { |
| 146 | $htmlOut = ''; |
| 147 | $htmlOut .= Html::closeElement( 'table' ); |
| 148 | if ( $this->editable ) { |
| 149 | $htmlOut .= Html::hidden( 'authtoken', $this->getUser()->getEditToken() ); |
| 150 | $htmlOut .= Html::rawElement( 'div', |
| 151 | [ 'class' => 'cn-buttons' ], |
| 152 | Html::submitButton( $this->msg( 'centralnotice-modify' )->text() ) |
| 153 | ); |
| 154 | } |
| 155 | return $htmlOut; |
| 156 | } |
| 157 | } |