3 * Use this special page to get a list of the MediaWiki system messages.
7 class SpecialAllmessages
extends SpecialPage
{
12 public function __construct() {
13 parent
::__construct( 'Allmessages' );
17 * Show the special page
19 * @param $par Mixed: parameter passed to the page or null
21 public function execute( $par ) {
22 global $wgOut, $wgRequest;
26 global $wgUseDatabaseMessages;
27 if( !$wgUseDatabaseMessages ) {
28 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
31 $this->outputHeader( 'allmessagestext' );
34 $this->filter
= $wgRequest->getVal( 'filter', 'all' );
35 $this->prefix
= $wgRequest->getVal( 'prefix', '' );
37 $this->table
= new AllmessagesTablePager(
40 wfGetLangObj( $wgRequest->getVal( 'lang', $par ) )
43 $this->langCode
= $this->table
->lang
->getCode();
45 $wgOut->addHTML( $this->buildForm() .
46 $this->table
->getNavigationBar() .
47 $this->table
->getLimitForm() .
48 $this->table
->getBody() .
49 $this->table
->getNavigationBar() );
53 function buildForm() {
56 $languages = Language
::getLanguageNames( false );
59 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
60 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
61 Xml
::hidden( 'title', $this->getTitle() ) .
62 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
64 <td class="mw-label">' .
65 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
67 <td class=\"mw-input\">" .
68 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
72 <td class='mw-label'>" .
73 wfMsg( 'allmessages-filter' ) .
75 <td class='mw-input'>" .
76 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
79 'mw-allmessages-form-filter-unmodified',
80 ( $this->filter
== 'unmodified' ?
true : false )
82 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
85 'mw-allmessages-form-filter-all',
86 ( $this->filter
== 'all' ?
true : false )
88 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
91 'mw-allmessages-form-filter-modified',
92 ( $this->filter
== 'modified' ?
true : false )
97 <td class=\"mw-label\">" .
98 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
100 <td class=\"mw-input\">" .
101 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
103 foreach( $languages as $lang => $name ) {
104 $selected = $lang == $this->langCode ?
true : false;
105 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
107 $out .= Xml
::closeElement( 'select' ) .
113 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
116 Xml
::closeElement( 'table' ) .
117 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
118 Xml
::closeElement( 'fieldset' ) .
119 Xml
::closeElement( 'form' );
124 /* use TablePager for prettified output. We have to pretend that we're
125 * getting data from a table when in fact not all of it comes from the database.
127 class AllmessagesTablePager
extends TablePager
{
129 var $messages = null;
130 var $talkPages = null;
132 function __construct( $page, $conds, $langObj = null ) {
133 parent
::__construct();
134 $this->mIndexField
= 'am_title';
135 $this->mPage
= $page;
136 $this->mConds
= $conds;
137 $this->mDefaultDirection
= true; // always sort ascending
139 global $wgLang, $wgContLang, $wgRequest;
141 $this->talk
= $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) );
143 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
144 $this->langcode
= $this->lang
->getCode();
145 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
147 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
148 $this->custom
= null; // So won't match in either case
150 $this->custom
= $wgRequest->getVal( 'filter' ) == 'unmodified' ?
1 : 0;
153 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
154 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
155 if( $prefix !== null ){
156 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
158 $this->prefix
= false;
162 // The suffix that may be needed for message names if we're in a
163 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
164 if( $this->foreign
) {
165 $this->suffix
= '/' . $this->langcode
;
171 function getAllMessages( $desc ){
172 wfProfileIn( __METHOD__
. '-cache' );
174 # Make sure all extension messages are available
175 global $wgMessageCache;
176 $wgMessageCache->loadAllMessages( 'en' );
177 $sortedArray = Language
::getMessagesFor( 'en' );
179 krsort( $sortedArray );
181 ksort( $sortedArray );
184 $this->messages
= array();
185 foreach( $sortedArray as $key => $value ) {
186 // All messages start with lowercase, but wikis might have both
187 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
188 $ukey = $this->lang
->ucfirst( $key );
190 // The value without any overrides from the MediaWiki: namespace
191 $this->messages
[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false );
193 // The message that's actually used by the site
194 $this->messages
[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false );
196 $this->messages
[$ukey]['customised'] = 0; //for now
198 $sortedArray[$key] = null; // trade bytes from $sortedArray to this
201 wfProfileOut( __METHOD__
. '-cache' );
206 # We only need a list of which messages have *been* customised;
207 # their content is already in the message cache.
208 function markCustomisedMessages(){
209 $this->talkPages
= array();
211 wfProfileIn( __METHOD__
. '-db' );
213 $dbr = wfGetDB( DB_SLAVE
);
214 $res = $dbr->select( 'page',
215 array( 'page_namespace', 'page_title' ),
216 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
218 array( 'USE INDEX' => 'name_title' )
221 while( $s = $dbr->fetchObject( $res ) ) {
222 if( $s->page_namespace
== NS_MEDIAWIKI
){
223 if( $this->foreign
){
224 $title = explode( '/', $s->page_title
);
225 if( count( $title ) === 2 && $this->langcode
== $title[1] && array_key_exists( $title[0], $this->messages
) ){
226 $this->messages
["{$title[0]}"]['customised'] = 1;
228 } else if( array_key_exists( $s->page_title
, $this->messages
) ){
229 $this->messages
[$s->page_title
]['customised'] = 1;
231 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
232 $this->talkPages
[$s->page_title
] = 1;
235 $dbr->freeResult( $res );
237 wfProfileOut( __METHOD__
. '-db' );
242 /* This function normally does a database query to get the results; we need
243 * to make a pretend result using a FakeResultWrapper.
245 function reallyDoQuery( $offset, $limit, $descending ){
246 $mResult = new FakeResultWrapper( array() );
248 if( !$this->messages
) $this->getAllMessages( $descending );
249 if( $this->talkPages
=== null ) $this->markCustomisedMessages();
252 foreach( $this->messages
as $key => $value ){
253 if( $value['customised'] !== $this->custom
&&
254 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
255 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
257 $mResult->result
[] = array(
259 'am_actual' => $value['actual'],
260 'am_default' => $value['default'],
261 'am_customised' => $value['customised'],
263 unset( $this->messages
[$key] ); // save a few bytes
266 if( $count == $limit ) break;
268 unset( $this->messages
); // no longer needed, free up some memory
272 function getStartBody() {
273 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
275 <th rowspan=\"2\">" .
276 wfMsg( 'allmessagesname' ) . "
279 wfMsg( 'allmessagesdefault' ) .
284 wfMsg( 'allmessagescurrent' ) .
286 </tr></thead><tbody>\n";
289 function formatValue( $field, $value ){
295 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
296 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
298 if( $this->mCurrentRow
->am_customised
){
299 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
301 $title = $this->mSkin
->link(
303 $wgLang->lcfirst( $value ),
309 if( array_key_exists( $talk->getDBkey() , $this->talkPages
) ) {
310 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
312 $talk = $this->mSkin
->link(
320 return $title . ' (' . $talk . ')';
323 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
325 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
330 function formatRow( $row ){
331 // Do all the normal stuff
332 $s = parent
::formatRow( $row );
334 // But if there's a customised message, add that too.
335 if( $row->am_customised
){
336 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
337 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
338 if ( $formatted == '' ) {
339 $formatted = ' ';
341 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
347 function getRowAttrs( $row, $isSecond = false ){
350 if( $row->am_customised
){
351 $arr['class'] = 'allmessages-customised';
354 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
359 function getCellAttrs( $field, $value ){
360 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
361 return array( 'rowspan' => '2', 'class' => $field );
363 return array( 'class' => $field );
367 // This is not actually used, as getStartBody is overridden above
368 function getFieldNames() {
370 'am_title' => wfMsg( 'allmessagesname' ),
371 'am_default' => wfMsg( 'allmessagesdefault' )
374 function getTitle() {
375 return SpecialPage
::getTitleFor( 'Allmessages', false );
377 function isFieldSortable( $x ){
380 function getDefaultSort(){
383 function getQueryInfo(){
387 /* Overloads the relevant methods of the real ResultsWrapper so it
388 * doesn't go anywhere near an actual database.
390 class FakeResultWrapper
extends ResultWrapper
{
392 var $result = array();
393 var $db = null; // And it's going to stay that way :D
395 var $currentRow = null;
397 function __construct( $array ){
398 $this->result
= $array;
402 return count( $this->result
);
405 function fetchRow() {
406 $this->currentRow
= $this->result
[$this->pos++
];
407 return $this->currentRow
;
410 function seek( $row ) {
416 // Callers want to be able to access fields with $this->fieldName
417 function fetchObject(){
418 $this->currentRow
= $this->result
[$this->pos++
];
419 return (object)$this->currentRow
;
424 $this->currentRow
= null;