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
{
33 * @var AllmessagesTablePager
40 public function __construct() {
41 parent
::__construct( 'Allmessages' );
45 * Show the special page
47 * @param $par Mixed: parameter passed to the page or null
49 public function execute( $par ) {
50 $request = $this->getRequest();
51 $out = $this->getOutput();
55 global $wgUseDatabaseMessages;
56 if( !$wgUseDatabaseMessages ) {
57 $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() );
83 * Use TablePager for prettified output. We have to pretend that we're
84 * getting data from a table when in fact not all of it comes from the database.
86 class AllmessagesTablePager
extends TablePager
{
88 protected $filter, $prefix, $langcode, $displayPrefix;
102 function __construct( $page, $conds, $langObj = null ) {
103 parent
::__construct( $page->getContext() );
104 $this->mIndexField
= 'am_title';
105 $this->mPage
= $page;
106 $this->mConds
= $conds;
107 $this->mDefaultDirection
= true; // always sort ascending
108 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
112 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
114 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
115 $this->langcode
= $this->lang
->getCode();
116 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
118 $request = $this->getRequest();
120 $this->filter
= $request->getVal( 'filter', 'all' );
121 if( $this->filter
=== 'all' ){
122 $this->custom
= null; // So won't match in either case
124 $this->custom
= ($this->filter
== 'unmodified');
127 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
128 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'prefix', null ) ) : null;
129 if( $prefix !== null ){
130 $this->displayPrefix
= $prefix->getDBkey();
131 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
133 $this->displayPrefix
= false;
134 $this->prefix
= false;
137 // The suffix that may be needed for message names if we're in a
138 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
139 if( $this->foreign
) {
140 $this->suffix
= '/' . $this->langcode
;
146 function buildForm() {
149 $languages = Language
::fetchLanguageNames( null, 'mw' );
152 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
153 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
154 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
155 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
157 <td class="mw-label">' .
158 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
160 <td class=\"mw-input\">" .
161 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
165 <td class='mw-label'>" .
166 $this->msg( 'allmessages-filter' )->escaped() .
168 <td class='mw-input'>" .
169 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
172 'mw-allmessages-form-filter-unmodified',
173 ( $this->filter
== 'unmodified' )
175 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
178 'mw-allmessages-form-filter-all',
179 ( $this->filter
== 'all' )
181 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
184 'mw-allmessages-form-filter-modified',
185 ( $this->filter
== 'modified' )
190 <td class=\"mw-label\">" .
191 Xml
::label( $this->msg( 'allmessages-language' )->text(), 'mw-allmessages-form-lang' ) .
193 <td class=\"mw-input\">" .
194 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
196 foreach( $languages as $lang => $name ) {
197 $selected = $lang == $this->langcode
;
198 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
200 $out .= Xml
::closeElement( 'select' ) .
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() .
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' );
225 function getAllMessages( $descending ) {
226 wfProfileIn( __METHOD__
);
227 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
229 rsort( $messageNames );
231 asort( $messageNames );
234 // Normalise message names so they look like page titles
235 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
237 wfProfileOut( __METHOD__
);
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.
254 wfProfileIn( __METHOD__
. '-db' );
256 $dbr = wfGetDB( DB_SLAVE
);
257 $res = $dbr->select( 'page',
258 array( 'page_namespace', 'page_title' ),
259 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
261 array( 'USE INDEX' => 'name_title' )
263 $xNames = array_flip( $messageNames );
265 $pageFlags = $talkFlags = array();
267 foreach ( $res as $s ) {
270 $title = explode( '/', $s->page_title
);
271 if( count( $title ) === 2 && $langcode == $title[1]
272 && isset( $xNames[$title[0]] ) ) {
275 } elseif( isset( $xNames[$s->page_title
] ) ) {
276 $exists = $s->page_title
;
278 if( $exists && $s->page_namespace
== NS_MEDIAWIKI
) {
279 $pageFlags[$exists] = true;
280 } elseif( $exists && $s->page_namespace
== NS_MEDIAWIKI_TALK
) {
281 $talkFlags[$exists] = true;
285 wfProfileOut( __METHOD__
. '-db' );
287 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
291 * This function normally does a database query to get the results; we need
292 * to make a pretend result using a FakeResultWrapper.
293 * @return FakeResultWrapper
295 function reallyDoQuery( $offset, $limit, $descending ) {
296 $result = new FakeResultWrapper( array() );
298 $messageNames = $this->getAllMessages( $descending );
299 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
302 foreach( $messageNames as $key ) {
303 $customised = isset( $statuses['pages'][$key] );
304 if( $customised !== $this->custom
&&
305 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
306 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
308 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
309 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
310 $result->result
[] = array(
312 'am_actual' => $actual,
313 'am_default' => $default,
314 'am_customised' => $customised,
315 'am_talk_exists' => isset( $statuses['talks'][$key] )
319 if( $count == $limit ) {
326 function getStartBody() {
327 return Xml
::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
329 <th rowspan=\"2\">" .
330 $this->msg( 'allmessagesname' )->escaped() . "
333 $this->msg( 'allmessagesdefault' )->escaped() .
338 $this->msg( 'allmessagescurrent' )->escaped() .
340 </tr></thead><tbody>\n";
343 function formatValue( $field, $value ){
348 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
349 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
351 if( $this->mCurrentRow
->am_customised
){
352 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
354 $title = Linker
::link(
356 $this->getLanguage()->lcfirst( $value ),
362 if ( $this->mCurrentRow
->am_talk_exists
) {
363 $talk = Linker
::linkKnown( $talk , $this->talk
);
365 $talk = Linker
::link(
373 return $title . ' ' . $this->msg( 'parentheses' )->rawParams( $talk )->escaped();
377 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
382 function formatRow( $row ){
383 // Do all the normal stuff
384 $s = parent
::formatRow( $row );
386 // But if there's a customised message, add that too.
387 if( $row->am_customised
){
388 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
389 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
390 if ( $formatted == '' ) {
391 $formatted = ' ';
393 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
399 function getRowAttrs( $row, $isSecond = false ){
401 if( $row->am_customised
){
402 $arr['class'] = 'allmessages-customised';
405 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
410 function getCellAttrs( $field, $value ){
411 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
412 return array( 'rowspan' => '2', 'class' => $field );
413 } elseif( $field == 'am_title' ) {
414 return array( 'class' => $field );
416 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
420 // This is not actually used, as getStartBody is overridden above
421 function getFieldNames() {
423 'am_title' => $this->msg( 'allmessagesname' )->text(),
424 'am_default' => $this->msg( 'allmessagesdefault' )->text()
428 function getTitle() {
429 return SpecialPage
::getTitleFor( 'Allmessages', false );
432 function isFieldSortable( $x ){
436 function getDefaultSort(){
440 function getQueryInfo(){