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 // Normalise message names so they look like page titles and sort correctly - T86139
229 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
232 rsort( $messageNames );
234 asort( $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.
254 $dbr = wfGetDB( DB_SLAVE
);
255 $res = $dbr->select( 'page',
256 array( 'page_namespace', 'page_title' ),
257 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
259 array( 'USE INDEX' => 'name_title' )
261 $xNames = array_flip( $messageNames );
263 $pageFlags = $talkFlags = array();
265 foreach ( $res as $s ) {
269 $titleParts = explode( '/', $s->page_title
);
270 if ( count( $titleParts ) === 2 &&
271 $langcode === $titleParts[1] &&
272 isset( $xNames[$titleParts[0]] )
274 $exists = $titleParts[0];
276 } elseif ( isset( $xNames[$s->page_title
] ) ) {
277 $exists = $s->page_title
;
280 $title = Title
::newFromRow( $s );
281 if ( $exists && $title->inNamespace( NS_MEDIAWIKI
) ) {
282 $pageFlags[$exists] = true;
283 } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK
) ) {
284 $talkFlags[$exists] = true;
288 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
292 * This function normally does a database query to get the results; we need
293 * to make a pretend result using a FakeResultWrapper.
294 * @param string $offset
296 * @param bool $descending
297 * @return FakeResultWrapper
299 function reallyDoQuery( $offset, $limit, $descending ) {
300 $result = new FakeResultWrapper( array() );
302 $messageNames = $this->getAllMessages( $descending );
303 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
306 foreach ( $messageNames as $key ) {
307 $customised = isset( $statuses['pages'][$key] );
308 if ( $customised !== $this->custom
&&
309 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
310 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
312 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
313 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
314 $result->result
[] = array(
316 'am_actual' => $actual,
317 'am_default' => $default,
318 'am_customised' => $customised,
319 'am_talk_exists' => isset( $statuses['talks'][$key] )
324 if ( $count === $limit ) {
332 function getStartBody() {
333 $tableClass = $this->getTableClass();
334 return Xml
::openElement( 'table', array(
335 'class' => "mw-datatable $tableClass",
336 'id' => 'mw-allmessagestable'
340 <th rowspan=\"2\">" .
341 $this->msg( 'allmessagesname' )->escaped() . "
344 $this->msg( 'allmessagesdefault' )->escaped() .
349 $this->msg( 'allmessagescurrent' )->escaped() .
351 </tr></thead><tbody>\n";
354 function formatValue( $field, $value ) {
357 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
358 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
359 $translation = Linker
::makeExternalLink(
360 'https://translatewiki.net/w/i.php?' . wfArrayToCgi( array(
361 'title' => 'Special:SearchTranslations',
362 'group' => 'mediawiki',
363 'grouppath' => 'mediawiki',
364 'query' => 'language:' . $this->getLanguage()->getCode() . '^25 ' .
365 'messageid:"MediaWiki:' . $value . '"^10 "' .
366 $this->msg( $value )->inLanguage( 'en' )->plain() . '"'
368 $this->msg( 'allmessages-filter-translate' )->text()
371 if ( $this->mCurrentRow
->am_customised
) {
372 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
374 $title = Linker
::link(
376 $this->getLanguage()->lcfirst( $value ),
382 if ( $this->mCurrentRow
->am_talk_exists
) {
383 $talk = Linker
::linkKnown( $talk, $this->talk
);
385 $talk = Linker
::link(
395 . $this->msg( 'parentheses' )->rawParams( $talk )->escaped()
397 . $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
401 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
407 function formatRow( $row ) {
408 // Do all the normal stuff
409 $s = parent
::formatRow( $row );
411 // But if there's a customised message, add that too.
412 if ( $row->am_customised
) {
413 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
414 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
416 if ( $formatted === '' ) {
417 $formatted = ' ';
420 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
427 function getRowAttrs( $row, $isSecond = false ) {
430 if ( $row->am_customised
) {
431 $arr['class'] = 'allmessages-customised';
435 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
441 function getCellAttrs( $field, $value ) {
442 if ( $this->mCurrentRow
->am_customised
&& $field === 'am_title' ) {
443 return array( 'rowspan' => '2', 'class' => $field );
444 } elseif ( $field === 'am_title' ) {
445 return array( 'class' => $field );
447 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
451 // This is not actually used, as getStartBody is overridden above
452 function getFieldNames() {
454 'am_title' => $this->msg( 'allmessagesname' )->text(),
455 'am_default' => $this->msg( 'allmessagesdefault' )->text()
459 function getTitle() {
460 return SpecialPage
::getTitleFor( 'Allmessages', false );
463 function isFieldSortable( $x ) {
467 function getDefaultSort() {
471 function getQueryInfo() {