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->filter
= $request->getVal( 'filter', 'all' );
66 $this->prefix
= $request->getVal( 'prefix', '' );
68 $this->table
= new AllmessagesTablePager(
71 wfGetLangObj( $request->getVal( 'lang', $par ) )
74 $this->langcode
= $this->table
->lang
->getCode();
76 $out->addHTML( $this->table
->buildForm() .
77 $this->table
->getNavigationBar() .
78 $this->table
->getBody() .
79 $this->table
->getNavigationBar() );
86 * Use TablePager for prettified output. We have to pretend that we're
87 * getting data from a table when in fact not all of it comes from the database.
89 class AllmessagesTablePager
extends TablePager
{
91 protected $filter, $prefix, $langcode, $displayPrefix;
105 function __construct( $page, $conds, $langObj = null ) {
106 parent
::__construct( $page->getContext() );
107 $this->mIndexField
= 'am_title';
108 $this->mPage
= $page;
109 $this->mConds
= $conds;
110 $this->mDefaultDirection
= true; // always sort ascending
111 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
115 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
117 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
118 $this->langcode
= $this->lang
->getCode();
119 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
121 $request = $this->getRequest();
123 if( $request->getVal( 'filter', 'all' ) === 'all' ){
124 $this->custom
= null; // So won't match in either case
126 $this->custom
= ($request->getVal( 'filter' ) == 'unmodified');
129 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
130 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'prefix', null ) ) : 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() {
151 $languages = Language
::getLanguageNames( false );
154 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
155 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
156 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
157 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
159 <td class="mw-label">' .
160 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
162 <td class=\"mw-input\">" .
163 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
167 <td class='mw-label'>" .
168 $this->msg( 'allmessages-filter' )->escaped() .
170 <td class='mw-input'>" .
171 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
174 'mw-allmessages-form-filter-unmodified',
175 ( $this->filter
== 'unmodified' )
177 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
180 'mw-allmessages-form-filter-all',
181 ( $this->filter
== 'all' )
183 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
186 'mw-allmessages-form-filter-modified',
187 ( $this->filter
== 'modified' )
192 <td class=\"mw-label\">" .
193 Xml
::label( $this->msg( 'allmessages-language' )->text(), 'mw-allmessages-form-lang' ) .
195 <td class=\"mw-input\">" .
196 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
198 foreach( $languages as $lang => $name ) {
199 $selected = $lang == $this->langcode
;
200 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
202 $out .= Xml
::closeElement( 'select' ) .
207 <td class="mw-label">' .
208 Xml
::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
210 <td class="mw-input">' .
211 $this->getLimitSelect() .
216 Xml
::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
220 Xml
::closeElement( 'table' ) .
221 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
222 Xml
::closeElement( 'fieldset' ) .
223 Xml
::closeElement( 'form' );
227 function getAllMessages( $descending ) {
228 wfProfileIn( __METHOD__
);
229 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
231 rsort( $messageNames );
233 asort( $messageNames );
236 // Normalise message names so they look like page titles
237 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
239 wfProfileOut( __METHOD__
);
240 return $messageNames;
244 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
245 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
246 * an entry for each existing page, with the key being the message name and
249 * @param array $messageNames
250 * @param string $langcode What language code
251 * @param bool $foreign Whether the $langcode is not the content language
252 * @return array: a 'pages' and 'talks' array with the keys of existing pages
254 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
255 // FIXME: This function should be moved to Language:: or something.
256 wfProfileIn( __METHOD__
. '-db' );
258 $dbr = wfGetDB( DB_SLAVE
);
259 $res = $dbr->select( 'page',
260 array( 'page_namespace', 'page_title' ),
261 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
263 array( 'USE INDEX' => 'name_title' )
265 $xNames = array_flip( $messageNames );
267 $pageFlags = $talkFlags = array();
269 foreach ( $res as $s ) {
272 $title = explode( '/', $s->page_title
);
273 if( count( $title ) === 2 && $langcode == $title[1]
274 && isset( $xNames[$title[0]] ) ) {
277 } elseif( isset( $xNames[$s->page_title
] ) ) {
278 $exists = $s->page_title
;
280 if( $exists && $s->page_namespace
== NS_MEDIAWIKI
) {
281 $pageFlags[$exists] = true;
282 } elseif( $exists && $s->page_namespace
== NS_MEDIAWIKI_TALK
) {
283 $talkFlags[$exists] = true;
287 wfProfileOut( __METHOD__
. '-db' );
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.
296 function reallyDoQuery( $offset, $limit, $descending ) {
297 $result = new FakeResultWrapper( array() );
299 $messageNames = $this->getAllMessages( $descending );
300 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
303 foreach( $messageNames as $key ) {
304 $customised = isset( $statuses['pages'][$key] );
305 if( $customised !== $this->custom
&&
306 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
307 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
309 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
310 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
311 $result->result
[] = array(
313 'am_actual' => $actual,
314 'am_default' => $default,
315 'am_customised' => $customised,
316 'am_talk_exists' => isset( $statuses['talks'][$key] )
320 if( $count == $limit ) {
327 function getStartBody() {
328 return Xml
::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
330 <th rowspan=\"2\">" .
331 $this->msg( 'allmessagesname' )->escaped() . "
334 $this->msg( 'allmessagesdefault' )->escaped() .
339 $this->msg( 'allmessagescurrent' )->escaped() .
341 </tr></thead><tbody>\n";
344 function formatValue( $field, $value ){
349 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
350 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
352 if( $this->mCurrentRow
->am_customised
){
353 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
355 $title = Linker
::link(
357 $this->getLanguage()->lcfirst( $value ),
363 if ( $this->mCurrentRow
->am_talk_exists
) {
364 $talk = Linker
::linkKnown( $talk , $this->talk
);
366 $talk = Linker
::link(
374 return $title . ' (' . $talk . ')';
378 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
383 function formatRow( $row ){
384 // Do all the normal stuff
385 $s = parent
::formatRow( $row );
387 // But if there's a customised message, add that too.
388 if( $row->am_customised
){
389 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
390 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
391 if ( $formatted == '' ) {
392 $formatted = ' ';
394 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
400 function getRowAttrs( $row, $isSecond = false ){
402 if( $row->am_customised
){
403 $arr['class'] = 'allmessages-customised';
406 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
411 function getCellAttrs( $field, $value ){
412 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
413 return array( 'rowspan' => '2', 'class' => $field );
414 } else if( $field == 'am_title' ) {
415 return array( 'class' => $field );
417 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
421 // This is not actually used, as getStartBody is overridden above
422 function getFieldNames() {
424 'am_title' => $this->msg( 'allmessagesname' )->text(),
425 'am_default' => $this->msg( 'allmessagesdefault' )->text()
429 function getTitle() {
430 return SpecialPage
::getTitleFor( 'Allmessages', false );
433 function isFieldSortable( $x ){
437 function getDefaultSort(){
441 function getQueryInfo(){