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 global $wgUseDatabaseMessages;
55 if ( !$wgUseDatabaseMessages ) {
56 $out->addWikiMsg( 'allmessagesnotsupportedDB' );
60 $this->outputHeader( 'allmessagestext' );
63 $out->addModuleStyles( 'mediawiki.special' );
65 $this->table
= new AllmessagesTablePager(
68 wfGetLangObj( $request->getVal( 'lang', $par ) )
71 $this->langcode
= $this->table
->lang
->getCode();
73 $out->addHTML( $this->table
->buildForm() .
74 $this->table
->getNavigationBar() .
75 $this->table
->getBody() .
76 $this->table
->getNavigationBar() );
79 protected function getGroupName() {
85 * Use TablePager for prettified output. We have to pretend that we're
86 * getting data from a table when in fact not all of it comes from the database.
88 class AllmessagesTablePager
extends TablePager
{
89 protected $filter, $prefix, $langcode, $displayPrefix;
103 function __construct( $page, $conds, $langObj = null ) {
104 parent
::__construct( $page->getContext() );
105 $this->mIndexField
= 'am_title';
106 $this->mPage
= $page;
107 $this->mConds
= $conds;
108 $this->mDefaultDirection
= true; // always sort ascending
109 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
113 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
115 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
116 $this->langcode
= $this->lang
->getCode();
117 $this->foreign
= $this->langcode
!== $wgContLang->getCode();
119 $request = $this->getRequest();
121 $this->filter
= $request->getVal( 'filter', 'all' );
122 if ( $this->filter
=== 'all' ) {
123 $this->custom
= null; // So won't match in either case
125 $this->custom
= ( $this->filter
=== 'unmodified' );
128 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
129 $prefix = $prefix !== '' ?
130 Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'prefix', null ) ) :
133 if ( $prefix !== null ) {
134 $this->displayPrefix
= $prefix->getDBkey();
135 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
137 $this->displayPrefix
= false;
138 $this->prefix
= false;
141 // The suffix that may be needed for message names if we're in a
142 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
143 if ( $this->foreign
) {
144 $this->suffix
= '/' . $this->langcode
;
150 function buildForm() {
153 $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' );
154 $msg = wfMessage( 'allmessages-language' );
155 $langSelect = Xml
::languageSelector( $this->langcode
, false, null, $attrs, $msg );
157 $out = Xml
::openElement( 'form', array(
159 'action' => $wgScript,
160 'id' => 'mw-allmessages-form'
162 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
163 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
164 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
166 <td class="mw-label">' .
167 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
169 <td class=\"mw-input\">" .
173 str_replace( '_', ' ', $this->displayPrefix
),
174 array( 'id' => 'mw-allmessages-form-prefix' )
179 <td class='mw-label'>" .
180 $this->msg( 'allmessages-filter' )->escaped() .
182 <td class='mw-input'>" .
183 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
186 'mw-allmessages-form-filter-unmodified',
187 ( $this->filter
=== 'unmodified' )
189 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
192 'mw-allmessages-form-filter-all',
193 ( $this->filter
=== 'all' )
195 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
198 'mw-allmessages-form-filter-modified',
199 ( $this->filter
=== 'modified' )
204 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
205 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
209 <td class="mw-label">' .
210 Xml
::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
212 <td class="mw-input">' .
213 $this->getLimitSelect() .
218 Xml
::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
222 Xml
::closeElement( 'table' ) .
223 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
224 Xml
::closeElement( 'fieldset' ) .
225 Xml
::closeElement( 'form' );
230 function getAllMessages( $descending ) {
231 wfProfileIn( __METHOD__
);
232 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
234 rsort( $messageNames );
236 asort( $messageNames );
239 // Normalise message names so they look like page titles
240 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
242 wfProfileOut( __METHOD__
);
244 return $messageNames;
248 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
249 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
250 * an entry for each existing page, with the key being the message name and
253 * @param array $messageNames
254 * @param string $langcode What language code
255 * @param bool $foreign Whether the $langcode is not the content language
256 * @return array A 'pages' and 'talks' array with the keys of existing pages
258 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
259 // FIXME: This function should be moved to Language:: or something.
260 wfProfileIn( __METHOD__
. '-db' );
262 $dbr = wfGetDB( DB_SLAVE
);
263 $res = $dbr->select( 'page',
264 array( 'page_namespace', 'page_title' ),
265 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
267 array( 'USE INDEX' => 'name_title' )
269 $xNames = array_flip( $messageNames );
271 $pageFlags = $talkFlags = array();
273 foreach ( $res as $s ) {
276 $title = explode( '/', $s->page_title
);
277 if ( count( $title ) === 2 && $langcode === $title[1]
278 && isset( $xNames[$title[0]] )
282 } elseif ( isset( $xNames[$s->page_title
] ) ) {
283 $exists = $s->page_title
;
285 if ( $exists && $s->page_namespace
=== NS_MEDIAWIKI
) {
286 $pageFlags[$exists] = true;
287 } elseif ( $exists && $s->page_namespace
=== NS_MEDIAWIKI_TALK
) {
288 $talkFlags[$exists] = true;
292 wfProfileOut( __METHOD__
. '-db' );
294 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
298 * This function normally does a database query to get the results; we need
299 * to make a pretend result using a FakeResultWrapper.
300 * @param string $offset
302 * @param bool $descending
303 * @return FakeResultWrapper
305 function reallyDoQuery( $offset, $limit, $descending ) {
306 $result = new FakeResultWrapper( array() );
308 $messageNames = $this->getAllMessages( $descending );
309 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
312 foreach ( $messageNames as $key ) {
313 $customised = isset( $statuses['pages'][$key] );
314 if ( $customised !== $this->custom
&&
315 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
316 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
318 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
319 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
320 $result->result
[] = array(
322 'am_actual' => $actual,
323 'am_default' => $default,
324 'am_customised' => $customised,
325 'am_talk_exists' => isset( $statuses['talks'][$key] )
330 if ( $count === $limit ) {
338 function getStartBody() {
339 return Xml
::openElement( 'table', array(
340 'class' => 'mw-datatable TablePager',
341 'id' => 'mw-allmessagestable'
345 <th rowspan=\"2\">" .
346 $this->msg( 'allmessagesname' )->escaped() . "
349 $this->msg( 'allmessagesdefault' )->escaped() .
354 $this->msg( 'allmessagescurrent' )->escaped() .
356 </tr></thead><tbody>\n";
359 function formatValue( $field, $value ) {
362 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
363 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
364 $translation = Linker
::makeExternalLink(
365 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( array(
366 'title' => 'Special:SearchTranslations',
367 'group' => 'mediawiki',
368 'grouppath' => 'mediawiki',
369 'query' => 'language:' . $this->getLanguage()->getCode() . '^25 ' .
370 'messageid:"MediaWiki:' . $value . '"^10 "' .
371 $this->msg( $value )->inLanguage( 'en' )->plain() . '"'
373 $this->msg( 'allmessages-filter-translate' )->text()
376 if ( $this->mCurrentRow
->am_customised
) {
377 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
379 $title = Linker
::link(
381 $this->getLanguage()->lcfirst( $value ),
387 if ( $this->mCurrentRow
->am_talk_exists
) {
388 $talk = Linker
::linkKnown( $talk, $this->talk
);
390 $talk = Linker
::link(
400 . $this->msg( 'parentheses' )->rawParams( $talk )->escaped()
402 . $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
406 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
412 function formatRow( $row ) {
413 // Do all the normal stuff
414 $s = parent
::formatRow( $row );
416 // But if there's a customised message, add that too.
417 if ( $row->am_customised
) {
418 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
419 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
421 if ( $formatted === '' ) {
422 $formatted = ' ';
425 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
432 function getRowAttrs( $row, $isSecond = false ) {
435 if ( $row->am_customised
) {
436 $arr['class'] = 'allmessages-customised';
440 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
446 function getCellAttrs( $field, $value ) {
447 if ( $this->mCurrentRow
->am_customised
&& $field === 'am_title' ) {
448 return array( 'rowspan' => '2', 'class' => $field );
449 } elseif ( $field === 'am_title' ) {
450 return array( 'class' => $field );
452 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
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() {