MediaWiki REL1_33
AllMessagesTablePager.php
Go to the documentation of this file.
1<?php
24
32
36 protected $langcode;
37
41 protected $foreign;
42
46 protected $prefix;
47
51 public $lang;
52
56 public $custom;
57
62 public function __construct( IContextSource $context = null, FormOptions $opts ) {
63 parent::__construct( $context );
64
65 $this->mIndexField = 'am_title';
66 // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
67 $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
68
69 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
70 $this->lang = wfGetLangObj( $opts->getValue( 'lang' ) );
71
72 $this->langcode = $this->lang->getCode();
73 $this->foreign = !$this->lang->equals( $contLang );
74
75 $filter = $opts->getValue( 'filter' );
76 if ( $filter === 'all' ) {
77 $this->custom = null; // So won't match in either case
78 } else {
79 $this->custom = ( $filter === 'unmodified' );
80 }
81
82 $prefix = $this->getLanguage()->ucfirst( $opts->getValue( 'prefix' ) );
83 $prefix = $prefix !== '' ?
84 Title::makeTitleSafe( NS_MEDIAWIKI, $opts->getValue( 'prefix' ) ) :
85 null;
86
87 if ( $prefix !== null ) {
88 $displayPrefix = $prefix->getDBkey();
89 $this->prefix = '/^' . preg_quote( $displayPrefix, '/' ) . '/i';
90 } else {
91 $this->prefix = false;
92 }
93
94 // The suffix that may be needed for message names if we're in a
95 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
96 if ( $this->foreign ) {
97 $this->suffix = '/' . $this->langcode;
98 } else {
99 $this->suffix = '';
100 }
101 }
102
103 function getAllMessages( $descending ) {
104 $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
105
106 // Normalise message names so they look like page titles and sort correctly - T86139
107 $messageNames = array_map( [ $this->lang, 'ucfirst' ], $messageNames );
108
109 if ( $descending ) {
110 rsort( $messageNames );
111 } else {
112 asort( $messageNames );
113 }
114
115 return $messageNames;
116 }
117
129 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
130 // FIXME: This function should be moved to Language:: or something.
131
133 $res = $dbr->select( 'page',
134 [ 'page_namespace', 'page_title' ],
135 [ 'page_namespace' => [ NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ] ],
136 __METHOD__,
137 [ 'USE INDEX' => 'name_title' ]
138 );
139 $xNames = array_flip( $messageNames );
140
141 $pageFlags = $talkFlags = [];
142
143 foreach ( $res as $s ) {
144 $exists = false;
145
146 if ( $foreign ) {
147 $titleParts = explode( '/', $s->page_title );
148 if ( count( $titleParts ) === 2 &&
149 $langcode === $titleParts[1] &&
150 isset( $xNames[$titleParts[0]] )
151 ) {
152 $exists = $titleParts[0];
153 }
154 } elseif ( isset( $xNames[$s->page_title] ) ) {
155 $exists = $s->page_title;
156 }
157
158 $title = Title::newFromRow( $s );
159 if ( $exists && $title->inNamespace( NS_MEDIAWIKI ) ) {
160 $pageFlags[$exists] = true;
161 } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK ) ) {
162 $talkFlags[$exists] = true;
163 }
164 }
165
166 return [ 'pages' => $pageFlags, 'talks' => $talkFlags ];
167 }
168
177 function reallyDoQuery( $offset, $limit, $order ) {
178 $asc = ( $order === self::QUERY_ASCENDING );
179 $result = new FakeResultWrapper( [] );
180
181 $messageNames = $this->getAllMessages( $order );
182 $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign );
183
184 $count = 0;
185 foreach ( $messageNames as $key ) {
186 $customised = isset( $statuses['pages'][$key] );
187 if ( $customised !== $this->custom &&
188 ( $asc && ( $key < $offset || !$offset ) || !$asc && $key > $offset ) &&
189 ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
190 ) {
191 $actual = wfMessage( $key )->inLanguage( $this->lang )->plain();
192 $default = wfMessage( $key )->inLanguage( $this->lang )->useDatabase( false )->plain();
193 $result->result[] = [
194 'am_title' => $key,
195 'am_actual' => $actual,
196 'am_default' => $default,
197 'am_customised' => $customised,
198 'am_talk_exists' => isset( $statuses['talks'][$key] )
199 ];
200 $count++;
201 }
202
203 if ( $count === $limit ) {
204 break;
205 }
206 }
207
208 return $result;
209 }
210
211 protected function getStartBody() {
212 $tableClass = $this->getTableClass();
213 return Xml::openElement( 'table', [
214 'class' => "mw-datatable $tableClass",
215 'id' => 'mw-allmessagestable'
216 ] ) .
217 "\n" .
218 "<thead><tr>
219 <th rowspan=\"2\">" .
220 $this->msg( 'allmessagesname' )->escaped() . "
221 </th>
222 <th>" .
223 $this->msg( 'allmessagesdefault' )->escaped() .
224 "</th>
225 </tr>\n
226 <tr>
227 <th>" .
228 $this->msg( 'allmessagescurrent' )->escaped() .
229 "</th>
230 </tr></thead>\n";
231 }
232
233 function getEndBody() {
234 return Html::closeElement( 'table' );
235 }
236
237 function formatValue( $field, $value ) {
238 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
239 switch ( $field ) {
240 case 'am_title' :
241 $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
242 $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
243 $translation = Linker::makeExternalLink(
244 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( [
245 'title' => 'Special:SearchTranslations',
246 'group' => 'mediawiki',
247 'grouppath' => 'mediawiki',
248 'language' => $this->getLanguage()->getCode(),
249 'query' => $value . ' ' . $this->msg( $value )->plain()
250 ] ),
251 $this->msg( 'allmessages-filter-translate' )->text()
252 );
253 $talkLink = $this->msg( 'talkpagelinktext' )->escaped();
254
255 if ( $this->mCurrentRow->am_customised ) {
256 $title = $linkRenderer->makeKnownLink( $title, $this->getLanguage()->lcfirst( $value ) );
257 } else {
258 $title = $linkRenderer->makeBrokenLink(
259 $title,
260 $this->getLanguage()->lcfirst( $value )
261 );
262 }
263 if ( $this->mCurrentRow->am_talk_exists ) {
264 $talk = $linkRenderer->makeKnownLink( $talk, $talkLink );
265 } else {
266 $talk = $linkRenderer->makeBrokenLink(
267 $talk,
268 $talkLink
269 );
270 }
271
272 return $title . ' ' .
273 $this->msg( 'parentheses' )->rawParams( $talk )->escaped() .
274 ' ' .
275 $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
276
277 case 'am_default' :
278 case 'am_actual' :
279 return Sanitizer::escapeHtmlAllowEntities( $value );
280 }
281
282 return '';
283 }
284
289 function formatRow( $row ) {
290 // Do all the normal stuff
291 $s = parent::formatRow( $row );
292
293 // But if there's a customised message, add that too.
294 if ( $row->am_customised ) {
295 $s .= Html::openElement( 'tr', $this->getRowAttrs( $row, true ) );
296 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
297
298 if ( $formatted === '' ) {
299 $formatted = "\u{00A0}";
300 }
301
302 $s .= Html::element( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
303 . Html::closeElement( 'tr' );
304 }
305
306 return Html::rawElement( 'tbody', [], $s );
307 }
308
309 function getRowAttrs( $row ) {
310 return [];
311 }
312
318 function getCellAttrs( $field, $value ) {
319 $attr = [];
320 if ( $field === 'am_title' ) {
321 if ( $this->mCurrentRow->am_customised ) {
322 $attr += [ 'rowspan' => '2' ];
323 }
324 } else {
325 $attr += [
326 'lang' => $this->lang->getHtmlCode(),
327 'dir' => $this->lang->getDir(),
328 ];
329 if ( $this->mCurrentRow->am_customised ) {
330 // CSS class: am_default, am_actual
331 $attr += [ 'class' => $field ];
332 }
333 }
334 return $attr;
335 }
336
337 // This is not actually used, as getStartBody is overridden above
338 function getFieldNames() {
339 return [
340 'am_title' => $this->msg( 'allmessagesname' )->text(),
341 'am_default' => $this->msg( 'allmessagesdefault' )->text()
342 ];
343 }
344
345 function getTitle() {
346 return SpecialPage::getTitleFor( 'Allmessages', false );
347 }
348
349 function isFieldSortable( $x ) {
350 return false;
351 }
352
353 function getDefaultSort() {
354 return '';
355 }
356
357 function getQueryInfo() {
358 return '';
359 }
360
361}
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Use TablePager for prettified output.
static getCustomisedStatuses( $messageNames, $langcode='en', $foreign=false)
Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
getRowAttrs( $row)
Get attributes to be applied to the given row.
getDefaultSort()
The database field name used as a default sort order.
isFieldSortable( $x)
Return true if the named field should be sortable by the UI, false otherwise.
reallyDoQuery( $offset, $limit, $order)
This function normally does a database query to get the results; we need to make a pretend result usi...
formatValue( $field, $value)
Format a table cell.
getFieldNames()
An array mapping database field names to a textual description of the field name, for use in the tabl...
__construct(IContextSource $context=null, FormOptions $opts)
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
IContextSource $context
Helper class to keep track of options when mixing links and form elements.
getValue( $name)
Get the value for the given option name.
const DIR_DESCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
const QUERY_ASCENDING
Backwards-compatible constant for reallyDoQuery() (do not change)
Internationalisation code.
Definition Language.php:36
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Definition Linker.php:842
MediaWikiServices is the service locator for the application scope of MediaWiki.
Table-based display with a user-selectable sort order.
getTableClass()
TablePager relies on mw-datatable for styling, see T214208.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
$res
Definition database.txt:21
namespace being checked & $result
Definition hooks.txt:2340
either a plain
Definition hooks.txt:2054
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2054
const NS_MEDIAWIKI_TALK
Definition Defines.php:82
Interface for objects which can provide a MediaWiki context on request.
$filter
const DB_REPLICA
Definition defines.php:25