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' );
19 function execute( $par ) {
20 global $wgOut, $wgRequest;
24 global $wgUseDatabaseMessages;
25 if( !$wgUseDatabaseMessages ) {
26 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
29 $this->outputHeader( 'allmessagestext' );
32 $this->filter
= $wgRequest->getVal( 'filter', 'all' );
33 $this->prefix
= $wgRequest->getVal( 'prefix', '' );
35 $this->table
= new AllmessagesTablePager( $this,
37 wfGetLangObj( $wgRequest->getVal( 'lang', false ) ) );
39 $this->langCode
= $this->table
->lang
->getCode();
41 $wgOut->addHTML( $this->buildForm() .
42 $this->table
->getNavigationBar() .
43 $this->table
->getLimitForm() .
44 $this->table
->getBody() .
45 $this->table
->getNavigationBar() );
49 function buildForm() {
52 $languages = Language
::getLanguageNames( false );
55 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
56 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
57 Xml
::hidden( 'title', $this->getTitle() ) .
58 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
60 <td class="mw-label">' .
61 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
63 <td class=\"mw-input\">" .
64 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
68 <td class='mw-label'>" .
69 Xml
::label( wfMsg( 'allmessages-filter' ), 'mw-allmessages-form-filter' ) .
71 <td class='mw-input'>" .
72 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
75 'mw-allmessages-form-filter-unmodified',
76 ( $this->filter
== 'unmodified' ?
true : false )
78 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
81 'mw-allmessages-form-filter-all',
82 ( $this->filter
== 'all' ?
true : false )
84 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
87 'mw-allmessages-form-filter-modified',
88 ( $this->filter
== 'modified' ?
true : false )
93 <td class=\"mw-label\">" .
94 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
96 <td class=\"mw-input\">" .
97 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
99 foreach( $languages as $lang => $name ) {
100 $selected = $lang == $this->langCode ?
true : false;
101 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
103 $out .= Xml
::closeElement( 'select' ) .
109 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
112 Xml
::closeElement( 'table' ) .
113 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
114 Xml
::closeElement( 'fieldset' ) .
115 Xml
::closeElement( 'form' );
120 /* use TablePager for prettified output. We have to pretend that we're
121 * getting data from a table when in fact not all of it comes from the database.
123 class AllmessagesTablePager
extends TablePager
{
125 var $messages = NULL;
126 var $talkPages = NULL;
128 function __construct( $page, $conds, $langObj = NULL ) {
129 parent
::__construct();
130 $this->mIndexField
= 'am_title';
131 $this->mPage
= $page;
132 $this->mConds
= $conds;
133 $this->mDefaultDirection
= true; //always sort ascending
135 global $wgLang, $wgContLang, $wgRequest;
137 $this->talk
= $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) );
139 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
140 $this->langcode
= $this->lang
->getCode();
141 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
143 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
144 $this->custom
= NULL; //So won't match in either case
146 $this->custom
= $wgRequest->getVal( 'filter' ) == 'unmodified' ?
1 : 0;
149 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
150 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', NULL ) ) : NULL;
151 if( $prefix !== NULL ){
152 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
154 $this->prefix
= false;
158 //The suffix that may be needed for message names if we're in a
159 //different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
160 if( $this->foreign
) {
161 $this->suffix
= '/' . $this->langcode
;
167 function getAllMessages( $desc ){
169 wfProfileIn( __METHOD__
. '-cache' );
171 # Make sure all extension messages are available
172 global $wgMessageCache;
173 $wgMessageCache->loadAllMessages( 'en' );
174 $sortedArray = Language
::getMessagesFor( 'en' );
176 krsort( $sortedArray );
178 ksort( $sortedArray );
181 $this->messages
= array();
182 foreach( $sortedArray as $key => $value ) {
183 // All messages start with lowercase, but wikis might have both
184 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
185 $ukey = $this->lang
->ucfirst( $key );
187 // The value without any overrides from the MediaWiki: namespace
188 $this->messages
[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false );
190 // The message that's actually used by the site
191 $this->messages
[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false );
193 $this->messages
[$ukey]['customised'] = 0; //for now
195 $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this
198 wfProfileOut( __METHOD__
. '-cache' );
203 # We only need a list of which messages have *been* customised;
204 # their content is already in the message cache.
205 function markCustomisedMessages(){
206 $this->talkPages
= array();
208 wfProfileIn( __METHOD__
. "-db" );
210 $dbr = wfGetDB( DB_SLAVE
);
211 $res = $dbr->select( 'page',
212 array( 'page_namespace', 'page_title' ),
213 array( 'page_namespace' => array(NS_MEDIAWIKI
,NS_MEDIAWIKI_TALK
) ),
215 array( 'USE INDEX' => 'name_title' )
218 while( $s = $dbr->fetchObject( $res ) ) {
219 if( $s->page_namespace
== NS_MEDIAWIKI
){
220 if( $this->foreign
){
221 $title = explode( '/', $s->page_title
);
222 if( count($title) === 2 && $this->langcode
== $title[1] && array_key_exists( $title[0], $this->messages
) ){
223 $this->messages
["{$title[0]}"]['customised'] = 1;
225 } else if( array_key_exists( $s->page_title
, $this->messages
) ){
226 $this->messages
[$s->page_title
]['customised'] = 1;
228 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
229 $this->talkPages
[$s->page_title
] = 1;
232 $dbr->freeResult( $res );
234 wfProfileOut( __METHOD__
. "-db" );
239 /* This function normally does a database query to get the results; we need
240 * to make a pretend result using a FakeResultWrapper.
242 function reallyDoQuery( $offset , $limit , $descending ){
243 $mResult = new FakeResultWrapper( array() );
245 if( !$this->messages
) $this->getAllMessages( $descending );
246 if( $this->talkPages
=== NULL ) $this->markCustomisedMessages();
249 foreach( $this->messages
as $key => $value ){
250 if( $value['customised'] !== $this->custom
&&
251 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
252 (( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
254 $mResult->result
[] = array(
256 'am_actual' => $value['actual'],
257 'am_default' => $value['default'],
258 'am_customised' => $value['customised'],
260 unset( $this->messages
[$key] ); // save a few bytes
263 if( $count == $limit ) break;
265 unset( $this->messages
); //no longer needed, free up some memory
269 function getStartBody() {
270 return "<table border=\"1\" class=\"TablePager\" style=\"width:100%;\" id=\"allmessagestable\"><thead>\n<tr>" .
271 "<th rowspan=\"2\">" . wfMsg('allmessagesname') . "</th><th>" . wfMsg('allmessagesdefault') .
272 "</tr>\n<tr><th>" . wfMsg('allmessagescurrent') . "</th></tr>\n";
275 function formatValue( $field , $value ){
281 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
282 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
284 if( $this->mCurrentRow
->am_customised
){
285 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
287 $title = $this->mSkin
->link( $title,
288 $wgLang->lcfirst( $value ),
293 if( array_key_exists( $talk->getDBkey() , $this->talkPages
) ) {
294 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
296 $talk = $this->mSkin
->link( $talk,
302 return $title . ' (' . $talk . ')';
305 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
307 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
312 function formatRow( $row ){
313 //Do all the normal stuff
314 $s = parent
::formatRow( $row );
316 //But if there's a customised message, add that too.
317 if( $row->am_customised
){
318 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
319 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
320 if ( $formatted == '' ) {
321 $formatted = ' ';
323 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
329 function getRowAttrs( $row, $isSecond=false ){
332 if( $row->am_customised
){
333 $arr['class'] = 'allmessages-customised';
336 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
341 function getCellAttrs( $field, $value ){
342 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
343 return array( 'rowspan' => '2', 'class' => $field );
345 return array( 'class' => $field );
349 // This is not actually used, as getStartBody is overridden above
350 function getFieldNames() {
351 return array( 'am_title' => wfMsg('allmessagesname'),
352 'am_default' => wfMsg('allmessagesdefault') );
354 function getTitle() {
355 return SpecialPage
::getTitleFor( 'Allmessages', false );
357 function isFieldSortable( $x ){
360 function getDefaultSort(){
363 function getQueryInfo(){
367 /* Overloads the relevant methods of the real ResultsWrapper so it
368 * doesn't go anywhere near an actual database.
370 class FakeResultWrapper
extends ResultWrapper
{
372 var $result = array();
373 var $db = NULL; //And it's going to stay that way :D
375 var $currentRow = NULL;
377 function __construct( $array ){
378 $this->result
= $array;
382 return count( $this->result
);
385 function fetchRow() {
386 $this->currentRow
= $this->result
[$this->pos++
];
387 return $this->currentRow
;
390 function seek( $row ) {
396 // Callers want to be able to access fields with $this->fieldName
397 function fetchObject(){
398 $this->currentRow
= $this->result
[$this->pos++
];
399 return (object)$this->currentRow
;
404 $this->currentRow
= NULL;