MediaWiki master
ProtectedTitlesPager.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Pager;
23
31
36
37 private ?string $level;
38 private ?int $namespace;
39
40 private LinkBatchFactory $linkBatchFactory;
41
42 public function __construct(
43 IContextSource $context,
44 LinkRenderer $linkRenderer,
45 LinkBatchFactory $linkBatchFactory,
46 IConnectionProvider $dbProvider,
47 ?string $level,
48 ?int $namespace
49 ) {
50 // Set database before parent constructor to avoid setting it there
51 $this->mDb = $dbProvider->getReplicaDatabase();
52 $this->level = $level;
53 $this->namespace = $namespace;
54 parent::__construct( $context, $linkRenderer );
55 $this->linkBatchFactory = $linkBatchFactory;
56 }
57
58 protected function doBatchLookups() {
59 $this->mResult->seek( 0 );
60
61 $lb = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
62 foreach ( $this->mResult as $row ) {
63 $lb->add( $row->pt_namespace, $row->pt_title );
64 }
65 $lb->execute();
66 }
67
68 public function formatRow( $row ) {
69 $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
70 if ( !$title ) {
71 return Html::rawElement(
72 'li',
73 [],
75 'span',
76 [ 'class' => 'mw-invalidtitle' ],
77 Linker::getInvalidTitleDescription(
78 $this->getContext(),
79 $row->pt_namespace,
80 $row->pt_title
81 )
82 )
83 ) . "\n";
84 }
85
86 $link = $this->getLinkRenderer()->makeLink( $title );
87 // Messages: restriction-level-sysop, restriction-level-autoconfirmed
88 $description = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
89 $lang = $this->getLanguage();
90 $expiry = strlen( $row->pt_expiry ) ?
91 $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
92 'infinity';
93
94 if ( $expiry !== 'infinity' ) {
95 $user = $this->getUser();
96 $description .= $this->msg( 'comma-separator' )->escaped() . $this->msg(
97 'protect-expiring-local',
98 $lang->userTimeAndDate( $expiry, $user ),
99 $lang->userDate( $expiry, $user ),
100 $lang->userTime( $expiry, $user )
101 )->escaped();
102 }
103
104 return '<li>' . $lang->specialList( $link, $description ) . "</li>\n";
105 }
106
110 public function getQueryInfo() {
111 $dbr = $this->getDatabase();
112 $conds = [
113 $dbr->expr( 'pt_expiry', '>', $this->mDb->timestamp() )
114 ->or( 'pt_expiry', '=', null ),
115 ];
116 if ( $this->level ) {
117 $conds['pt_create_perm'] = $this->level;
118 }
119
120 if ( $this->namespace !== null ) {
121 $conds[] = $dbr->expr( 'pt_namespace', '=', $this->namespace );
122 }
123
124 return [
125 'tables' => 'protected_titles',
126 'fields' => [ 'pt_namespace', 'pt_title', 'pt_create_perm',
127 'pt_expiry', 'pt_timestamp' ],
128 'conds' => $conds
129 ];
130 }
131
132 public function getIndexField() {
133 return [ [ 'pt_timestamp', 'pt_namespace', 'pt_title' ] ];
134 }
135}
136
141class_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:61
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, ?string $level, ?int $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)