MediaWiki master
ProtectedTitlesPager.php
Go to the documentation of this file.
1<?php
9
18use Wikimedia\Timestamp\TimestampFormat as TS;
19
24
25 public function __construct(
26 IContextSource $context,
27 LinkRenderer $linkRenderer,
28 private readonly LinkBatchFactory $linkBatchFactory,
29 IConnectionProvider $dbProvider,
30 private readonly ?string $level,
31 private readonly ?int $namespace,
32 ) {
33 // Set database before parent constructor to avoid setting it there
34 $this->mDb = $dbProvider->getReplicaDatabase();
35 parent::__construct( $context, $linkRenderer );
36 }
37
39 protected function doBatchLookups() {
40 $this->mResult->seek( 0 );
41
42 $lb = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
43 foreach ( $this->mResult as $row ) {
44 $lb->add( $row->pt_namespace, $row->pt_title );
45 }
46 $lb->execute();
47 }
48
50 public function formatRow( $row ) {
51 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
52 if ( !$title ) {
53 return Html::rawElement(
54 'li',
55 [],
57 'span',
58 [ 'class' => 'mw-invalidtitle' ],
59 Linker::getInvalidTitleDescription(
60 $this->getContext(),
61 $row->pt_namespace,
62 $row->pt_title
63 )
64 )
65 ) . "\n";
66 }
67
68 $link = $this->getLinkRenderer()->makeLink( $title );
69 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
70 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
71 $lang = $this->getLanguage();
72 $expiry = strlen( $row->pt_expiry ) ?
73 $lang->formatExpiry( $row->pt_expiry, TS::MW ) :
74 'infinity';
75
76 if ( $expiry !== 'infinity' ) {
77 $user = $this->getUser();
78 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
79 'protect-expiring-local',
80 $lang->userTimeAndDate( $expiry, $user ),
81 $lang->userDate( $expiry, $user ),
82 $lang->userTime( $expiry, $user )
83 )->escaped();
84 }
85
86 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
87 }
88
92 public function getQueryInfo() {
93 $dbr = $this->getDatabase();
94 $conds = [
95 $dbr->expr( 'pt_expiry', '>', $this->mDb->timestamp() )
96 ->or( 'pt_expiry', '=', null ),
97 ];
98 if ( $this->level ) {
99 $conds['pt_create_perm'] = $this->level;
100 }
101
102 if ( $this->namespace !== null ) {
103 $conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace );
104 }
105
106 return [
107 'tables' => 'protected_titles',
108 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
109 'pt_expiry', 'pt_timestamp' ],
110 'conds' => $conds
111 ];
112 }
113
115 public function getIndexField() {
116 return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ];
117 }
118}
119
124class_alias( ProtectedTitlesPager::class, 'ProtectedTitlesPager' );
125
127class_alias( ProtectedTitlesPager::class, 'MediaWiki\\Pager\\ProtectedTitlesPager' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:47
Factory for LinkBatch objects to batch query page metadata.
IndexPager with an alphabetic list and a formatted navigation bar.
getDatabase()
Get the Database object in use.
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called....
formatRow( $row)
Returns an HTML string representing the result row $row.Rows will be concatenated and returned by get...
__construct(IContextSource $context, LinkRenderer $linkRenderer, private readonly LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, private readonly ?string $level, private readonly ?int $namespace,)
getIndexField()
Returns the name of the index field.If the pager supports multiple orders, it may return an array of ...
Represents a title within MediaWiki.
Definition Title.php:69
Interface for objects which can provide a MediaWiki context on request.
Provide primary and replica IDatabase connections.
getReplicaDatabase(string|false $domain=false, $group=null)
Get connection to a replica database.
element(SerializerNode $parent, SerializerNode $node, $contents)