| 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\Linker\Linker; |
| 28 |
use MediaWiki\Linker\LinkRenderer; |
| 29 |
use MediaWiki\Title\Title; |
| 30 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class ProtectedTitlesPager extends AlphabeticPager { |
| 36 |
|
| 37 |
|
| 38 |
private $level; |
| 39 |
|
| 40 |
|
| 41 |
private $namespace; |
| 42 |
|
| 43 |
private LinkBatchFactory $linkBatchFactory; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function __construct( |
| 54 |
IContextSource $context, |
| 55 |
LinkRenderer $linkRenderer, |
| 56 |
LinkBatchFactory $linkBatchFactory, |
| 57 |
IConnectionProvider $dbProvider, |
| 58 |
$level, |
| 59 |
$namespace |
| 60 |
) { |
| 61 |
|
| 62 |
$this->mDb = $dbProvider->getReplicaDatabase(); |
| 63 |
$this->level = $level; |
| 64 |
$this->namespace = $namespace; |
| 65 |
parent::__construct( $context, $linkRenderer ); |
| 66 |
$this->linkBatchFactory = $linkBatchFactory; |
| 67 |
} |
| 68 |
|
| 69 |
protected function doBatchLookups() { |
| 70 |
$this->mResult->seek( 0 ); |
| 71 |
$lb = $this->linkBatchFactory->newLinkBatch(); |
| 72 |
|
| 73 |
foreach ( $this->mResult as $row ) { |
| 74 |
$lb->add( $row->pt_namespace, $row->pt_title ); |
| 75 |
} |
| 76 |
|
| 77 |
$lb->execute(); |
| 78 |
} |
| 79 |
|
| 80 |
public function formatRow( $row ) { |
| 81 |
$title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title ); |
| 82 |
if ( !$title ) { |
| 83 |
return Html::rawElement( |
| 84 |
'li', |
| 85 |
[], |
| 86 |
Html::element( |
| 87 |
'span', |
| 88 |
[ 'class' => 'mw-invalidtitle' ], |
| 89 |
Linker::getInvalidTitleDescription( |
| 90 |
$this->getContext(), |
| 91 |
$row->pt_namespace, |
| 92 |
$row->pt_title |
| 93 |
) |
| 94 |
) |
| 95 |
) . "\n"; |
| 96 |
} |
| 97 |
|
| 98 |
$link = $this->getLinkRenderer()->makeLink( $title ); |
| 99 |
|
| 100 |
$description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped(); |
| 101 |
$lang = $this->getLanguage(); |
| 102 |
$expiry = strlen( $row->pt_expiry ) ? |
| 103 |
$lang->formatExpiry( $row->pt_expiry, TS_MW ) : |
| 104 |
'infinity'; |
| 105 |
|
| 106 |
if ( $expiry !== 'infinity' ) { |
| 107 |
$user = $this->getUser(); |
| 108 |
$description .= $this->msg( 'comma-separator' )->escaped() . $this->msg( |
| 109 |
'protect-expiring-local', |
| 110 |
$lang->userTimeAndDate( $expiry, $user ), |
| 111 |
$lang->userDate( $expiry, $user ), |
| 112 |
$lang->userTime( $expiry, $user ) |
| 113 |
)->escaped(); |
| 114 |
} |
| 115 |
|
| 116 |
return '<li>' . $lang->specialList( $link, $description ) . "</li>\n"; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function getQueryInfo() { |
| 123 |
$dbr = $this->getDatabase(); |
| 124 |
$conds = [ |
| 125 |
$dbr->expr( 'pt_expiry', '>', $this->mDb->timestamp() ) |
| 126 |
->or( 'pt_expiry', '=', null ), |
| 127 |
]; |
| 128 |
if ( $this->level ) { |
| 129 |
$conds['pt_create_perm'] = $this->level; |
| 130 |
} |
| 131 |
|
| 132 |
if ( $this->namespace !== null ) { |
| 133 |
$conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace ); |
| 134 |
} |
| 135 |
|
| 136 |
return [ |
| 137 |
'tables' => 'protected_titles', |
| 138 |
'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm', |
| 139 |
'pt_expiry', 'pt_timestamp' ], |
| 140 |
'conds' => $conds |
| 141 |
]; |
| 142 |
} |
| 143 |
|
| 144 |
public function getIndexField() { |
| 145 |
return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ]; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
class_alias( ProtectedTitlesPager::class, 'ProtectedTitlesPager' ); |