3 * Implements Special:Allmessages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Use this special page to get a list of the MediaWiki system messages.
28 * @ingroup SpecialPage
30 class SpecialAllMessages
extends SpecialPage
{
32 * @var AllMessagesTablePager
39 public function __construct() {
40 parent
::__construct( 'Allmessages' );
44 * Show the special page
46 * @param string $par Parameter passed to the page or null
48 public function execute( $par ) {
49 $request = $this->getRequest();
50 $out = $this->getOutput();
54 if ( !$this->getConfig()->get( 'UseDatabaseMessages' ) ) {
55 $out->addWikiMsg( 'allmessagesnotsupportedDB' );
60 $this->outputHeader( 'allmessagestext' );
61 $out->addModuleStyles( 'mediawiki.special' );
62 $this->addHelpLink( 'Help:System message' );
64 $this->table
= new AllMessagesTablePager(
67 wfGetLangObj( $request->getVal( 'lang', $par ) )
70 $this->langcode
= $this->table
->lang
->getCode();
72 $out->addHTML( $this->table
->buildForm() );
73 $out->addParserOutputContent( $this->table
->getFullOutput() );
76 protected function getGroupName() {
82 * Use TablePager for prettified output. We have to pretend that we're
83 * getting data from a table when in fact not all of it comes from the database.
85 class AllMessagesTablePager
extends TablePager
{
86 protected $filter, $prefix, $langcode, $displayPrefix;
100 function __construct( $page, $conds, $langObj = null ) {
101 parent
::__construct( $page->getContext() );
102 $this->mIndexField
= 'am_title';
103 $this->mPage
= $page;
104 $this->mConds
= $conds;
105 // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
106 $this->mDefaultDirection
= IndexPager
::DIR_DESCENDING
;
107 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
111 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
113 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
114 $this->langcode
= $this->lang
->getCode();
115 $this->foreign
= $this->langcode
!== $wgContLang->getCode();
117 $request = $this->getRequest();
119 $this->filter
= $request->getVal( 'filter', 'all' );
120 if ( $this->filter
=== 'all' ) {
121 $this->custom
= null; // So won't match in either case
123 $this->custom
= ( $this->filter
=== 'unmodified' );
126 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
127 $prefix = $prefix !== '' ?
128 Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'prefix', null ) ) :
131 if ( $prefix !== null ) {
132 $this->displayPrefix
= $prefix->getDBkey();
133 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
, '/' ) . '/i';
135 $this->displayPrefix
= false;
136 $this->prefix
= false;
139 // The suffix that may be needed for message names if we're in a
140 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
141 if ( $this->foreign
) {
142 $this->suffix
= '/' . $this->langcode
;
148 function buildForm() {
149 $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' );
150 $msg = wfMessage( 'allmessages-language' );
151 $langSelect = Xml
::languageSelector( $this->langcode
, false, null, $attrs, $msg );
153 $out = Xml
::openElement( 'form', array(
155 'action' => $this->getConfig()->get( 'Script' ),
156 'id' => 'mw-allmessages-form'
158 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
159 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
160 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
162 <td class="mw-label">' .
163 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
165 <td class=\"mw-input\">" .
169 str_replace( '_', ' ', $this->displayPrefix
),
170 array( 'id' => 'mw-allmessages-form-prefix' )
175 <td class='mw-label'>" .
176 $this->msg( 'allmessages-filter' )->escaped() .
178 <td class='mw-input'>" .
179 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
182 'mw-allmessages-form-filter-unmodified',
183 ( $this->filter
=== 'unmodified' )
185 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
188 'mw-allmessages-form-filter-all',
189 ( $this->filter
=== 'all' )
191 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
194 'mw-allmessages-form-filter-modified',
195 ( $this->filter
=== 'modified' )
200 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
201 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
205 <td class="mw-label">' .
206 Xml
::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
208 <td class="mw-input">' .
209 $this->getLimitSelect( array( 'id' => 'mw-table_pager_limit_label' ) ) .
214 Xml
::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
218 Xml
::closeElement( 'table' ) .
219 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
220 Xml
::closeElement( 'fieldset' ) .
221 Xml
::closeElement( 'form' );
226 function getAllMessages( $descending ) {
227 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
229 // Normalise message names so they look like page titles and sort correctly - T86139
230 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
233 rsort( $messageNames );
235 asort( $messageNames );
238 return $messageNames;
242 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
243 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
244 * an entry for each existing page, with the key being the message name and
247 * @param array $messageNames
248 * @param string $langcode What language code
249 * @param bool $foreign Whether the $langcode is not the content language
250 * @return array A 'pages' and 'talks' array with the keys of existing pages
252 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
253 // FIXME: This function should be moved to Language:: or something.
255 $dbr = wfGetDB( DB_SLAVE
);
256 $res = $dbr->select( 'page',
257 array( 'page_namespace', 'page_title' ),
258 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
260 array( 'USE INDEX' => 'name_title' )
262 $xNames = array_flip( $messageNames );
264 $pageFlags = $talkFlags = array();
266 foreach ( $res as $s ) {
270 $titleParts = explode( '/', $s->page_title
);
271 if ( count( $titleParts ) === 2 &&
272 $langcode === $titleParts[1] &&
273 isset( $xNames[$titleParts[0]] )
275 $exists = $titleParts[0];
277 } elseif ( isset( $xNames[$s->page_title
] ) ) {
278 $exists = $s->page_title
;
281 $title = Title
::newFromRow( $s );
282 if ( $exists && $title->inNamespace( NS_MEDIAWIKI
) ) {
283 $pageFlags[$exists] = true;
284 } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK
) ) {
285 $talkFlags[$exists] = true;
289 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
293 * This function normally does a database query to get the results; we need
294 * to make a pretend result using a FakeResultWrapper.
295 * @param string $offset
297 * @param bool $descending
298 * @return FakeResultWrapper
300 function reallyDoQuery( $offset, $limit, $descending ) {
301 $result = new FakeResultWrapper( array() );
303 $messageNames = $this->getAllMessages( $descending );
304 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
307 foreach ( $messageNames as $key ) {
308 $customised = isset( $statuses['pages'][$key] );
309 if ( $customised !== $this->custom
&&
310 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
311 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
313 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
314 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
315 $result->result
[] = array(
317 'am_actual' => $actual,
318 'am_default' => $default,
319 'am_customised' => $customised,
320 'am_talk_exists' => isset( $statuses['talks'][$key] )
325 if ( $count === $limit ) {
333 function getStartBody() {
334 $tableClass = $this->getTableClass();
335 return Xml
::openElement( 'table', array(
336 'class' => "mw-datatable $tableClass",
337 'id' => 'mw-allmessagestable'
341 <th rowspan=\"2\">" .
342 $this->msg( 'allmessagesname' )->escaped() . "
345 $this->msg( 'allmessagesdefault' )->escaped() .
350 $this->msg( 'allmessagescurrent' )->escaped() .
352 </tr></thead><tbody>\n";
355 function formatValue( $field, $value ) {
358 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
359 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
360 $translation = Linker
::makeExternalLink(
361 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( array(
362 'title' => 'Special:SearchTranslations',
363 'group' => 'mediawiki',
364 'grouppath' => 'mediawiki',
365 'query' => 'language:' . $this->getLanguage()->getCode() . '^25 ' .
366 'messageid:"MediaWiki:' . $value . '"^10 "' .
367 $this->msg( $value )->inLanguage( 'en' )->plain() . '"'
369 $this->msg( 'allmessages-filter-translate' )->text()
372 if ( $this->mCurrentRow
->am_customised
) {
373 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
375 $title = Linker
::link(
377 $this->getLanguage()->lcfirst( $value ),
383 if ( $this->mCurrentRow
->am_talk_exists
) {
384 $talk = Linker
::linkKnown( $talk, $this->talk
);
386 $talk = Linker
::link(
395 return $title . ' ' .
396 $this->msg( 'parentheses' )->rawParams( $talk )->escaped() .
398 $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
402 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
408 function formatRow( $row ) {
409 // Do all the normal stuff
410 $s = parent
::formatRow( $row );
412 // But if there's a customised message, add that too.
413 if ( $row->am_customised
) {
414 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
415 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
417 if ( $formatted === '' ) {
418 $formatted = ' ';
421 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
428 function getRowAttrs( $row, $isSecond = false ) {
431 if ( $row->am_customised
) {
432 $arr['class'] = 'allmessages-customised';
436 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
442 function getCellAttrs( $field, $value ) {
443 if ( $this->mCurrentRow
->am_customised
&& $field === 'am_title' ) {
444 return array( 'rowspan' => '2', 'class' => $field );
445 } elseif ( $field === 'am_title' ) {
446 return array( 'class' => $field );
449 'lang' => $this->lang
->getHtmlCode(),
450 'dir' => $this->lang
->getDir(),
456 // This is not actually used, as getStartBody is overridden above
457 function getFieldNames() {
459 'am_title' => $this->msg( 'allmessagesname' )->text(),
460 'am_default' => $this->msg( 'allmessagesdefault' )->text()
464 function getTitle() {
465 return SpecialPage
::getTitleFor( 'Allmessages', false );
468 function isFieldSortable( $x ) {
472 function getDefaultSort() {
476 function getQueryInfo() {