MediaWiki master
ProtectedTitlesPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
31
36
38 private $level;
39
41 private $namespace;
42
43 private LinkBatchFactory $linkBatchFactory;
44
53 public function __construct(
54 IContextSource $context,
55 LinkRenderer $linkRenderer,
56 LinkBatchFactory $linkBatchFactory,
57 IConnectionProvider $dbProvider,
58 $level,
59 $namespace
60 ) {
61 // Set database before parent constructor to avoid setting it there
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 [],
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 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
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
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
153class_alias( ProtectedTitlesPager::class, '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:56
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:63
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.
__construct(IContextSource $context, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, $level, $namespace)
getIndexField()
Returns the name of the index field.
formatRow( $row)
Returns an HTML string representing the result row $row.
Represents a title within MediaWiki.
Definition Title.php:78
Interface for objects which can provide a MediaWiki context on request.
Provide primary and replica IDatabase connections.
getReplicaDatabase( $domain=false, $group=null)
Get connection to a replica database.
element(SerializerNode $parent, SerializerNode $node, $contents)