MediaWiki REL1_41
ProtectedTitlesPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
31
36
40 public $mConds;
41
43 private $level;
44
46 private $namespace;
47
48 private LinkBatchFactory $linkBatchFactory;
49
62 public function __construct(
63 IContextSource $context,
64 LinkRenderer $linkRenderer,
65 LinkBatchFactory $linkBatchFactory,
66 IConnectionProvider $dbProvider,
67 $conds,
68 $type,
69 $level,
70 $namespace,
71 $sizetype,
72 $size
73 ) {
74 // Set database before parent constructor to avoid setting it there with wfGetDB
75 $this->mDb = $dbProvider->getReplicaDatabase();
76 $this->mConds = $conds;
77 $this->level = $level;
78 $this->namespace = $namespace;
79 parent::__construct( $context, $linkRenderer );
80 $this->linkBatchFactory = $linkBatchFactory;
81 }
82
83 protected function doBatchLookups() {
84 $this->mResult->seek( 0 );
85 $lb = $this->linkBatchFactory->newLinkBatch();
86
87 foreach ( $this->mResult as $row ) {
88 $lb->add( $row->pt_namespace, $row->pt_title );
89 }
90
91 $lb->execute();
92 }
93
94 public function formatRow( $row ) {
95 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
96 if ( !$title ) {
97 return Html::rawElement(
98 'li',
99 [],
100 Html::element(
101 'span',
102 [ 'class' => 'mw-invalidtitle' ],
103 Linker::getInvalidTitleDescription(
104 $this->getContext(),
105 $row->pt_namespace,
106 $row->pt_title
107 )
108 )
109 ) . "\n";
110 }
111
112 $link = $this->getLinkRenderer()->makeLink( $title );
113 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
114 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
115 $lang = $this->getLanguage();
116 $expiry = strlen( $row->pt_expiry ) ?
117 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
118 'infinity';
119
120 if ( $expiry !== 'infinity' ) {
121 $user = $this->getUser();
122 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
123 'protect-expiring-local',
124 $lang->userTimeAndDate( $expiry, $user ),
125 $lang->userDate( $expiry, $user ),
126 $lang->userTime( $expiry, $user )
127 )->escaped();
128 }
129
130 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
131 }
132
136 public function getQueryInfo() {
137 $dbr = $this->getDatabase();
138 $conds = $this->mConds;
139 $conds[] = 'pt_expiry > ' . $dbr->addQuotes( $this->mDb->timestamp() ) .
140 ' OR pt_expiry IS NULL';
141 if ( $this->level ) {
142 $conds['pt_create_perm'] = $this->level;
143 }
144
145 if ( $this->namespace !== null ) {
146 $conds[] = 'pt_namespace=' . $dbr->addQuotes( $this->namespace );
147 }
148
149 return [
150 'tables' => 'protected_titles',
151 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
152 'pt_expiry', 'pt_timestamp' ],
153 'conds' => $conds
154 ];
155 }
156
157 public function getIndexField() {
158 return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ];
159 }
160}
161
166class_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:57
Class that generates HTML for internal links.
Some internal bits split of from Skin.php.
Definition Linker.php:65
IndexPager with an alphabetic list and a formatted navigation bar.
getDatabase()
Get the Database object in use.
__construct(IContextSource $context, LinkRenderer $linkRenderer, LinkBatchFactory $linkBatchFactory, IConnectionProvider $dbProvider, $conds, $type, $level, $namespace, $sizetype, $size)
doBatchLookups()
Called from getBody(), before getStartBody() is called and after doQuery() was called.
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:76
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.