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