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 $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' );
150 $msg = wfMessage( 'allmessages-language' );
151 $langSelect = Xml
::languageSelector( $this->langcode
, false, null, $attrs, $msg );
153 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
154 Xml
::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
155 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
156 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
158 <td class="mw-label">' .
159 Xml
::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
161 <td class=\"mw-input\">" .
162 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
166 <td class='mw-label'>" .
167 $this->msg( 'allmessages-filter' )->escaped() .
169 <td class='mw-input'>" .
170 Xml
::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
173 'mw-allmessages-form-filter-unmodified',
174 ( $this->filter
== 'unmodified' )
176 Xml
::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
179 'mw-allmessages-form-filter-all',
180 ( $this->filter
== 'all' )
182 Xml
::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
185 'mw-allmessages-form-filter-modified',
186 ( $this->filter
== 'modified' )
191 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
192 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
196 <td class="mw-label">' .
197 Xml
::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
199 <td class="mw-input">' .
200 $this->getLimitSelect() .
205 Xml
::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
209 Xml
::closeElement( 'table' ) .
210 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
211 Xml
::closeElement( 'fieldset' ) .
212 Xml
::closeElement( 'form' );
216 function getAllMessages( $descending ) {
217 wfProfileIn( __METHOD__
);
218 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
220 rsort( $messageNames );
222 asort( $messageNames );
225 // Normalise message names so they look like page titles
226 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
228 wfProfileOut( __METHOD__
);
229 return $messageNames;
233 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
234 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
235 * an entry for each existing page, with the key being the message name and
238 * @param array $messageNames
239 * @param string $langcode What language code
240 * @param bool $foreign Whether the $langcode is not the content language
241 * @return array: a 'pages' and 'talks' array with the keys of existing pages
243 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
244 // FIXME: This function should be moved to Language:: or something.
245 wfProfileIn( __METHOD__
. '-db' );
247 $dbr = wfGetDB( DB_SLAVE
);
248 $res = $dbr->select( 'page',
249 array( 'page_namespace', 'page_title' ),
250 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
252 array( 'USE INDEX' => 'name_title' )
254 $xNames = array_flip( $messageNames );
256 $pageFlags = $talkFlags = array();
258 foreach ( $res as $s ) {
261 $title = explode( '/', $s->page_title
);
262 if( count( $title ) === 2 && $langcode == $title[1]
263 && isset( $xNames[$title[0]] ) ) {
266 } elseif( isset( $xNames[$s->page_title
] ) ) {
267 $exists = $s->page_title
;
269 if( $exists && $s->page_namespace
== NS_MEDIAWIKI
) {
270 $pageFlags[$exists] = true;
271 } elseif( $exists && $s->page_namespace
== NS_MEDIAWIKI_TALK
) {
272 $talkFlags[$exists] = true;
276 wfProfileOut( __METHOD__
. '-db' );
278 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
282 * This function normally does a database query to get the results; we need
283 * to make a pretend result using a FakeResultWrapper.
284 * @return FakeResultWrapper
286 function reallyDoQuery( $offset, $limit, $descending ) {
287 $result = new FakeResultWrapper( array() );
289 $messageNames = $this->getAllMessages( $descending );
290 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
293 foreach( $messageNames as $key ) {
294 $customised = isset( $statuses['pages'][$key] );
295 if( $customised !== $this->custom
&&
296 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
297 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
299 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
300 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
301 $result->result
[] = array(
303 'am_actual' => $actual,
304 'am_default' => $default,
305 'am_customised' => $customised,
306 'am_talk_exists' => isset( $statuses['talks'][$key] )
310 if( $count == $limit ) {
317 function getStartBody() {
318 return Xml
::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
320 <th rowspan=\"2\">" .
321 $this->msg( 'allmessagesname' )->escaped() . "
324 $this->msg( 'allmessagesdefault' )->escaped() .
329 $this->msg( 'allmessagescurrent' )->escaped() .
331 </tr></thead><tbody>\n";
334 function formatValue( $field, $value ){
339 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
340 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
342 if( $this->mCurrentRow
->am_customised
){
343 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
345 $title = Linker
::link(
347 $this->getLanguage()->lcfirst( $value ),
353 if ( $this->mCurrentRow
->am_talk_exists
) {
354 $talk = Linker
::linkKnown( $talk , $this->talk
);
356 $talk = Linker
::link(
364 return $title . ' ' . $this->msg( 'parentheses' )->rawParams( $talk )->escaped();
368 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
373 function formatRow( $row ){
374 // Do all the normal stuff
375 $s = parent
::formatRow( $row );
377 // But if there's a customised message, add that too.
378 if( $row->am_customised
){
379 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
380 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
381 if ( $formatted == '' ) {
382 $formatted = ' ';
384 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
390 function getRowAttrs( $row, $isSecond = false ){
392 if( $row->am_customised
){
393 $arr['class'] = 'allmessages-customised';
396 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
401 function getCellAttrs( $field, $value ){
402 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
403 return array( 'rowspan' => '2', 'class' => $field );
404 } elseif( $field == 'am_title' ) {
405 return array( 'class' => $field );
407 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
411 // This is not actually used, as getStartBody is overridden above
412 function getFieldNames() {
414 'am_title' => $this->msg( 'allmessagesname' )->text(),
415 'am_default' => $this->msg( 'allmessagesdefault' )->text()
419 function getTitle() {
420 return SpecialPage
::getTitleFor( 'Allmessages', false );
423 function isFieldSortable( $x ){
427 function getDefaultSort(){
431 function getQueryInfo(){