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' );
63 $this->table
= new AllmessagesTablePager(
66 wfGetLangObj( $request->getVal( 'lang', $par ) )
69 $this->langcode
= $this->table
->lang
->getCode();
71 $out->addHTML( $this->table
->buildForm() );
72 $out->addParserOutputContent( $this->table
->getFullOutput() );
75 protected function getGroupName() {
81 * Use TablePager for prettified output. We have to pretend that we're
82 * getting data from a table when in fact not all of it comes from the database.
84 class AllMessagesTablePager
extends TablePager
{
85 protected $filter, $prefix, $langcode, $displayPrefix;
99 function __construct( $page, $conds, $langObj = null ) {
100 parent
::__construct( $page->getContext() );
101 $this->mIndexField
= 'am_title';
102 $this->mPage
= $page;
103 $this->mConds
= $conds;
104 // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
105 $this->mDefaultDirection
= IndexPager
::DIR_DESCENDING
;
106 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
110 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
112 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
113 $this->langcode
= $this->lang
->getCode();
114 $this->foreign
= $this->langcode
!== $wgContLang->getCode();
116 $request = $this->getRequest();
118 $this->filter
= $request->getVal( 'filter', 'all' );
119 if ( $this->filter
=== 'all' ) {
120 $this->custom
= null; // So won't match in either case
122 $this->custom
= ( $this->filter
=== 'unmodified' );
125 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
126 $prefix = $prefix !== '' ?
127 Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'prefix', null ) ) :
130 if ( $prefix !== null ) {
131 $this->displayPrefix
= $prefix->getDBkey();
132 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
134 $this->displayPrefix
= false;
135 $this->prefix
= false;
138 // The suffix that may be needed for message names if we're in a
139 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
140 if ( $this->foreign
) {
141 $this->suffix
= '/' . $this->langcode
;
147 function buildForm() {
148 $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' );
149 $msg = wfMessage( 'allmessages-language' );
150 $langSelect = Xml
::languageSelector( $this->langcode
, false, null, $attrs, $msg );
152 $out = Xml
::openElement( 'form', array(
154 'action' => $this->getConfig()->get( 'Script' ),
155 'id' => 'mw-allmessages-form'
157 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
158 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
159 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
161 <td class="mw-label">' .
162 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
164 <td class=\"mw-input\">" .
168 str_replace( '_', ' ', $this->displayPrefix
),
169 array( 'id' => 'mw-allmessages-form-prefix' )
174 <td class='mw-label'>" .
175 $this->msg( 'allmessages-filter' )->escaped() .
177 <td class='mw-input'>" .
178 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
181 'mw-allmessages-form-filter-unmodified',
182 ( $this->filter
=== 'unmodified' )
184 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
187 'mw-allmessages-form-filter-all',
188 ( $this->filter
=== 'all' )
190 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
193 'mw-allmessages-form-filter-modified',
194 ( $this->filter
=== 'modified' )
199 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
200 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
204 <td class="mw-label">' .
205 Xml
::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
207 <td class="mw-input">' .
208 $this->getLimitSelect() .
213 Xml
::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
217 Xml
::closeElement( 'table' ) .
218 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
219 Xml
::closeElement( 'fieldset' ) .
220 Xml
::closeElement( 'form' );
225 function getAllMessages( $descending ) {
226 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
228 rsort( $messageNames );
230 asort( $messageNames );
233 // Normalise message names so they look like page titles
234 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
237 return $messageNames;
241 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
242 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
243 * an entry for each existing page, with the key being the message name and
246 * @param array $messageNames
247 * @param string $langcode What language code
248 * @param bool $foreign Whether the $langcode is not the content language
249 * @return array A 'pages' and 'talks' array with the keys of existing pages
251 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
252 // FIXME: This function should be moved to Language:: or something.
253 wfProfileIn( __METHOD__
. '-db' );
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 wfProfileOut( __METHOD__
. '-db' );
291 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
295 * This function normally does a database query to get the results; we need
296 * to make a pretend result using a FakeResultWrapper.
297 * @param string $offset
299 * @param bool $descending
300 * @return FakeResultWrapper
302 function reallyDoQuery( $offset, $limit, $descending ) {
303 $result = new FakeResultWrapper( array() );
305 $messageNames = $this->getAllMessages( $descending );
306 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
309 foreach ( $messageNames as $key ) {
310 $customised = isset( $statuses['pages'][$key] );
311 if ( $customised !== $this->custom
&&
312 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
313 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
315 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
316 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
317 $result->result
[] = array(
319 'am_actual' => $actual,
320 'am_default' => $default,
321 'am_customised' => $customised,
322 'am_talk_exists' => isset( $statuses['talks'][$key] )
327 if ( $count === $limit ) {
335 function getStartBody() {
336 $tableClass = $this->getTableClass();
337 return Xml
::openElement( 'table', array(
338 'class' => "mw-datatable $tableClass",
339 'id' => 'mw-allmessagestable'
343 <th rowspan=\"2\">" .
344 $this->msg( 'allmessagesname' )->escaped() . "
347 $this->msg( 'allmessagesdefault' )->escaped() .
352 $this->msg( 'allmessagescurrent' )->escaped() .
354 </tr></thead><tbody>\n";
357 function formatValue( $field, $value ) {
360 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
361 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
362 $translation = Linker
::makeExternalLink(
363 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( array(
364 'title' => 'Special:SearchTranslations',
365 'group' => 'mediawiki',
366 'grouppath' => 'mediawiki',
367 'query' => 'language:' . $this->getLanguage()->getCode() . '^25 ' .
368 'messageid:"MediaWiki:' . $value . '"^10 "' .
369 $this->msg( $value )->inLanguage( 'en' )->plain() . '"'
371 $this->msg( 'allmessages-filter-translate' )->text()
374 if ( $this->mCurrentRow
->am_customised
) {
375 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
377 $title = Linker
::link(
379 $this->getLanguage()->lcfirst( $value ),
385 if ( $this->mCurrentRow
->am_talk_exists
) {
386 $talk = Linker
::linkKnown( $talk, $this->talk
);
388 $talk = Linker
::link(
398 . $this->msg( 'parentheses' )->rawParams( $talk )->escaped()
400 . $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
404 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
410 function formatRow( $row ) {
411 // Do all the normal stuff
412 $s = parent
::formatRow( $row );
414 // But if there's a customised message, add that too.
415 if ( $row->am_customised
) {
416 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
417 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
419 if ( $formatted === '' ) {
420 $formatted = ' ';
423 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
430 function getRowAttrs( $row, $isSecond = false ) {
433 if ( $row->am_customised
) {
434 $arr['class'] = 'allmessages-customised';
438 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
444 function getCellAttrs( $field, $value ) {
445 if ( $this->mCurrentRow
->am_customised
&& $field === 'am_title' ) {
446 return array( 'rowspan' => '2', 'class' => $field );
447 } elseif ( $field === 'am_title' ) {
448 return array( 'class' => $field );
450 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
454 // This is not actually used, as getStartBody is overridden above
455 function getFieldNames() {
457 'am_title' => $this->msg( 'allmessagesname' )->text(),
458 'am_default' => $this->msg( 'allmessagesdefault' )->text()
462 function getTitle() {
463 return SpecialPage
::getTitleFor( 'Allmessages', false );
466 function isFieldSortable( $x ) {
470 function getDefaultSort() {
474 function getQueryInfo() {