MediaWiki REL1_32
AllMessagesTablePager.php
Go to the documentation of this file.
1<?php
24
32
34
36
40 public $lang;
41
45 public $custom;
46
47 function __construct( $page, $conds, Language $langObj = null ) {
48 parent::__construct( $page->getContext() );
49 $this->mIndexField = 'am_title';
50 $this->mPage = $page;
51 $this->mConds = $conds;
52 // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
53 $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
54 $this->mLimitsShown = [ 20, 50, 100, 250, 500, 5000 ];
55
56 $this->talk = $this->msg( 'talkpagelinktext' )->escaped();
57
58 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
59 $this->lang = $langObj ?? $contLang;
60 $this->langcode = $this->lang->getCode();
61 $this->foreign = !$this->lang->equals( $contLang );
62
63 $request = $this->getRequest();
64
65 $this->filter = $request->getVal( 'filter', 'all' );
66 if ( $this->filter === 'all' ) {
67 $this->custom = null; // So won't match in either case
68 } else {
69 $this->custom = ( $this->filter === 'unmodified' );
70 }
71
72 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
73 $prefix = $prefix !== '' ?
74 Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) :
75 null;
76
77 if ( $prefix !== null ) {
78 $this->displayPrefix = $prefix->getDBkey();
79 $this->prefix = '/^' . preg_quote( $this->displayPrefix, '/' ) . '/i';
80 } else {
81 $this->displayPrefix = false;
82 $this->prefix = false;
83 }
84
85 // The suffix that may be needed for message names if we're in a
86 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
87 if ( $this->foreign ) {
88 $this->suffix = '/' . $this->langcode;
89 } else {
90 $this->suffix = '';
91 }
92 }
93
94 function buildForm() {
95 $attrs = [ 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ];
96 $msg = wfMessage( 'allmessages-language' );
97 $langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg );
98
99 $out = Xml::openElement( 'form', [
100 'method' => 'get',
101 'action' => $this->getConfig()->get( 'Script' ),
102 'id' => 'mw-allmessages-form'
103 ] ) .
104 Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
105 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
106 Xml::openElement( 'table', [ 'class' => 'mw-allmessages-table' ] ) . "\n" .
107 '<tr>
108 <td class="mw-label">' .
109 Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
110 "</td>\n
111 <td class=\"mw-input\">" .
112 Xml::input(
113 'prefix',
114 20,
115 str_replace( '_', ' ', $this->displayPrefix ),
116 [ 'id' => 'mw-allmessages-form-prefix' ]
117 ) .
118 "</td>\n
119 </tr>
120 <tr>\n
121 <td class='mw-label'>" .
122 $this->msg( 'allmessages-filter' )->escaped() .
123 "</td>\n
124 <td class='mw-input'>" .
125 Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
126 'filter',
127 'unmodified',
128 'mw-allmessages-form-filter-unmodified',
129 ( $this->filter === 'unmodified' )
130 ) .
131 Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
132 'filter',
133 'all',
134 'mw-allmessages-form-filter-all',
135 ( $this->filter === 'all' )
136 ) .
137 Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
138 'filter',
139 'modified',
140 'mw-allmessages-form-filter-modified',
141 ( $this->filter === 'modified' )
142 ) .
143 "</td>\n
144 </tr>
145 <tr>\n
146 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
147 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
148 </tr>" .
149
150 '<tr>
151 <td class="mw-label">' .
152 Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
153 '</td>
154 <td class="mw-input">' .
155 $this->getLimitSelect( [ 'id' => 'mw-table_pager_limit_label' ] ) .
156 '</td>
157 <tr>
158 <td></td>
159 <td>' .
160 Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
161 "</td>\n
162 </tr>" .
163
164 Xml::closeElement( 'table' ) .
165 $this->getHiddenFields( [ 'title', 'prefix', 'filter', 'lang', 'limit' ] ) .
166 Xml::closeElement( 'fieldset' ) .
167 Xml::closeElement( 'form' );
168
169 return $out;
170 }
171
172 function getAllMessages( $descending ) {
173 $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
174
175 // Normalise message names so they look like page titles and sort correctly - T86139
176 $messageNames = array_map( [ $this->lang, 'ucfirst' ], $messageNames );
177
178 if ( $descending ) {
179 rsort( $messageNames );
180 } else {
181 asort( $messageNames );
182 }
183
184 return $messageNames;
185 }
186
198 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
199 // FIXME: This function should be moved to Language:: or something.
200
202 $res = $dbr->select( 'page',
203 [ 'page_namespace', 'page_title' ],
204 [ 'page_namespace' => [ NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ] ],
205 __METHOD__,
206 [ 'USE INDEX' => 'name_title' ]
207 );
208 $xNames = array_flip( $messageNames );
209
210 $pageFlags = $talkFlags = [];
211
212 foreach ( $res as $s ) {
213 $exists = false;
214
215 if ( $foreign ) {
216 $titleParts = explode( '/', $s->page_title );
217 if ( count( $titleParts ) === 2 &&
218 $langcode === $titleParts[1] &&
219 isset( $xNames[$titleParts[0]] )
220 ) {
221 $exists = $titleParts[0];
222 }
223 } elseif ( isset( $xNames[$s->page_title] ) ) {
224 $exists = $s->page_title;
225 }
226
227 $title = Title::newFromRow( $s );
228 if ( $exists && $title->inNamespace( NS_MEDIAWIKI ) ) {
229 $pageFlags[$exists] = true;
230 } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK ) ) {
231 $talkFlags[$exists] = true;
232 }
233 }
234
235 return [ 'pages' => $pageFlags, 'talks' => $talkFlags ];
236 }
237
246 function reallyDoQuery( $offset, $limit, $descending ) {
247 $result = new FakeResultWrapper( [] );
248
249 $messageNames = $this->getAllMessages( $descending );
250 $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign );
251
252 $count = 0;
253 foreach ( $messageNames as $key ) {
254 $customised = isset( $statuses['pages'][$key] );
255 if ( $customised !== $this->custom &&
256 ( $descending && ( $key < $offset || !$offset ) || !$descending && $key > $offset ) &&
257 ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
258 ) {
259 $actual = wfMessage( $key )->inLanguage( $this->langcode )->plain();
260 $default = wfMessage( $key )->inLanguage( $this->langcode )->useDatabase( false )->plain();
261 $result->result[] = [
262 'am_title' => $key,
263 'am_actual' => $actual,
264 'am_default' => $default,
265 'am_customised' => $customised,
266 'am_talk_exists' => isset( $statuses['talks'][$key] )
267 ];
268 $count++;
269 }
270
271 if ( $count === $limit ) {
272 break;
273 }
274 }
275
276 return $result;
277 }
278
279 function getStartBody() {
280 $tableClass = $this->getTableClass();
281 return Xml::openElement( 'table', [
282 'class' => "mw-datatable $tableClass",
283 'id' => 'mw-allmessagestable'
284 ] ) .
285 "\n" .
286 "<thead><tr>
287 <th rowspan=\"2\">" .
288 $this->msg( 'allmessagesname' )->escaped() . "
289 </th>
290 <th>" .
291 $this->msg( 'allmessagesdefault' )->escaped() .
292 "</th>
293 </tr>\n
294 <tr>
295 <th>" .
296 $this->msg( 'allmessagescurrent' )->escaped() .
297 "</th>
298 </tr></thead><tbody>\n";
299 }
300
301 function formatValue( $field, $value ) {
302 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
303 switch ( $field ) {
304 case 'am_title' :
305 $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
306 $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
307 $translation = Linker::makeExternalLink(
308 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( [
309 'title' => 'Special:SearchTranslations',
310 'group' => 'mediawiki',
311 'grouppath' => 'mediawiki',
312 'language' => $this->getLanguage()->getCode(),
313 'query' => $value . ' ' . $this->msg( $value )->plain()
314 ] ),
315 $this->msg( 'allmessages-filter-translate' )->text()
316 );
317
318 if ( $this->mCurrentRow->am_customised ) {
319 $title = $linkRenderer->makeKnownLink( $title, $this->getLanguage()->lcfirst( $value ) );
320 } else {
321 $title = $linkRenderer->makeBrokenLink(
322 $title,
323 $this->getLanguage()->lcfirst( $value )
324 );
325 }
326 if ( $this->mCurrentRow->am_talk_exists ) {
327 $talk = $linkRenderer->makeKnownLink( $talk, $this->talk );
328 } else {
329 $talk = $linkRenderer->makeBrokenLink(
330 $talk,
331 $this->talk
332 );
333 }
334
335 return $title . ' ' .
336 $this->msg( 'parentheses' )->rawParams( $talk )->escaped() .
337 ' ' .
338 $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
339
340 case 'am_default' :
341 case 'am_actual' :
342 return Sanitizer::escapeHtmlAllowEntities( $value );
343 }
344
345 return '';
346 }
347
348 function formatRow( $row ) {
349 // Do all the normal stuff
350 $s = parent::formatRow( $row );
351
352 // But if there's a customised message, add that too.
353 if ( $row->am_customised ) {
354 $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) );
355 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
356
357 if ( $formatted === '' ) {
358 $formatted = "\u{00A0}";
359 }
360
361 $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
362 . "</tr>\n";
363 }
364
365 return $s;
366 }
367
368 function getRowAttrs( $row, $isSecond = false ) {
369 $arr = [];
370
371 if ( $row->am_customised ) {
372 $arr['class'] = 'allmessages-customised';
373 }
374
375 if ( !$isSecond ) {
376 $arr['id'] = Sanitizer::escapeIdForAttribute(
377 'msg_' . $this->getLanguage()->lcfirst( $row->am_title )
378 );
379 }
380
381 return $arr;
382 }
383
384 function getCellAttrs( $field, $value ) {
385 if ( $this->mCurrentRow->am_customised && $field === 'am_title' ) {
386 return [ 'rowspan' => '2', 'class' => $field ];
387 } elseif ( $field === 'am_title' ) {
388 return [ 'class' => $field ];
389 } else {
390 return [
391 'lang' => $this->lang->getHtmlCode(),
392 'dir' => $this->lang->getDir(),
393 'class' => $field
394 ];
395 }
396 }
397
398 // This is not actually used, as getStartBody is overridden above
399 function getFieldNames() {
400 return [
401 'am_title' => $this->msg( 'allmessagesname' )->text(),
402 'am_default' => $this->msg( 'allmessagesdefault' )->text()
403 ];
404 }
405
406 function getTitle() {
407 return SpecialPage::getTitleFor( 'Allmessages', false );
408 }
409
410 function isFieldSortable( $x ) {
411 return false;
412 }
413
414 function getDefaultSort() {
415 return '';
416 }
417
418 function getQueryInfo() {
419 return '';
420 }
421
422}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
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.
getDefaultSort()
The database field name used as a default sort order.
getCellAttrs( $field, $value)
Get any extra attributes to be applied to the given cell.
isFieldSortable( $x)
Return true if the named field should be sortable by the UI, false otherwise.
getRowAttrs( $row, $isSecond=false)
formatValue( $field, $value)
Format a table cell.
__construct( $page, $conds, Language $langObj=null)
getFieldNames()
An array mapping database field names to a textual description of the field name, for use in the tabl...
reallyDoQuery( $offset, $limit, $descending)
This function normally does a database query to get the results; we need to make a pretend result usi...
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
const DIR_DESCENDING
Internationalisation code.
Definition Language.php:35
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Definition Linker.php:826
MediaWikiServices is the service locator for the application scope of MediaWiki.
Table-based display with a user-selectable sort order.
getHiddenFields( $blacklist=[])
Get <input type="hidden"> elements for use in a method="get" form.
getLimitSelect( $attribs=[])
Get a "<select>" element which has options for each of the allowed limits.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
$res
Definition database.txt:21
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_MEDIAWIKI_TALK
Definition Defines.php:73
const NS_MEDIAWIKI
Definition Defines.php:72
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2880
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:2042
either a plain
Definition hooks.txt:2105
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:894
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:2105
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
const DB_REPLICA
Definition defines.php:25