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() {
50 $url = $this->getTitle()->escapeLocalURL();
51 $languages = Language
::getLanguageNames( false );
54 $out = "<form method=\"get\" action=\"$url\"><fieldset>\n" .
55 Xml
::element( 'legend', null, wfMsg( 'allmessages' ) ) . "<table><tr>\n" .
56 "<td class=\"mw-label\">" .
57 Xml
::label( wfMsg('allmessages-prefix'), 'am-form-prefix' ) .
58 "</td>\n<td class=\"mw-input\">" .
59 Xml
::input( 'prefix', 20, str_replace('_',' ',$this->prefix
), array( 'id' => 'am-form-prefix' ) ) .
61 "</td>\n</tr><tr>\n<td class='mw-label'>" .
62 Xml
::label( wfMsg('allmessages-filter'), 'am-form-filter' ) .
63 "</td>\n<td class='mw-input'>" .
64 Xml
::radioLabel( wfMsg('allmessages-filter-unmodified'),
67 'am-form-filter-unmodified',
68 ( $this->filter
== 'unmodified' ?
true : false )
70 Xml
::radioLabel( wfMsg('allmessages-filter-all'),
74 ( $this->filter
== 'all' ?
true : false )
76 Xml
::radioLabel( wfMsg('allmessages-filter-modified'),
79 'am-form-filter-modified',
80 ( $this->filter
== 'modified' ?
true : false )
82 "</td>\n</tr><tr>\n<td class=\"mw-label\">" .
83 Xml
::label( wfMsg('yourlanguage'), 'am-form-lang' ) .
84 "</td>\n<td class=\"mw-input\">" .
85 Xml
::openElement( 'select', array( 'id' => 'am-form-lang', 'name' => 'lang' ) );
86 foreach( $languages as $lang => $name ) {
87 $selected = $lang == $this->langCode ?
'selected="selected"' : '';
88 $out .= "<option value=\"$lang\" $selected>$name</option>\n";
90 $out .= "</td>\n</tr><tr>\n<td></td><td>" . Xml
::submitButton( wfMsg('allpagessubmit') ) .
92 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
98 /* use TablePager for prettified output. We have to pretend that we're
99 * getting data from a table when in fact not all of it comes from the database.
101 class AllmessagesTablePager
extends TablePager
{
103 var $messages = NULL;
104 var $talkPages = NULL;
106 function __construct( $page, $conds, $langObj = NULL ) {
107 parent
::__construct();
108 $this->mIndexField
= 'am_title';
109 $this->mPage
= $page;
110 $this->mConds
= $conds;
111 $this->mDefaultDirection
= true; //always sort ascending
113 global $wgLang, $wgContLang, $wgRequest;
115 $this->talk
= $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) );
117 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
118 $this->langcode
= $this->lang
->getCode();
119 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
121 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
122 $this->custom
= NULL; //So won't match in either case
124 $this->custom
= $wgRequest->getVal( 'filter' ) == 'unmodified' ?
1 : 0;
127 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
128 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', NULL ) ) : NULL;
129 if( $prefix !== NULL ){
130 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
132 $this->prefix
= false;
136 //The suffix that may be needed for message names if we're in a
137 //different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
138 if( $this->foreign
) {
139 $this->suffix
= '/' . $this->langcode
;
145 function getAllMessages( $desc ){
147 wfProfileIn( __METHOD__
. '-cache' );
149 # Make sure all extension messages are available
150 global $wgMessageCache;
151 $wgMessageCache->loadAllMessages( 'en' );
152 $sortedArray = Language
::getMessagesFor( 'en' );
154 krsort( $sortedArray );
156 ksort( $sortedArray );
159 $this->messages
= array();
160 foreach( $sortedArray as $key => $value ) {
161 // All messages start with lowercase, but wikis might have both
162 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
163 $ukey = $this->lang
->ucfirst( $key );
165 // The value without any overrides from the MediaWiki: namespace
166 $this->messages
[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false );
168 // The message that's actually used by the site
169 $this->messages
[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false );
171 $this->messages
[$ukey]['customised'] = 0; //for now
173 $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this
176 wfProfileOut( __METHOD__
. '-cache' );
181 # We only need a list of which messages have *been* customised;
182 # their content is already in the message cache.
183 function markCustomisedMessages(){
184 $this->talkPages
= array();
186 wfProfileIn( __METHOD__
. "-db" );
188 $dbr = wfGetDB( DB_SLAVE
);
189 $res = $dbr->select( 'page',
190 array( 'page_namespace', 'page_title' ),
191 array( 'page_namespace' => array(NS_MEDIAWIKI
,NS_MEDIAWIKI_TALK
) ),
193 array( 'USE INDEX' => 'name_title' )
196 while( $s = $dbr->fetchObject( $res ) ) {
197 if( $s->page_namespace
== NS_MEDIAWIKI
){
198 if( $this->foreign
){
199 $title = explode( '/', $s->page_title
);
200 if( $this->langcode
== $title[1] && array_key_exists( $title[0], $this->messages
) ){
201 $this->messages
["{$title[0]}"]['customised'] = 1;
203 } else if( array_key_exists( $s->page_title
, $this->messages
) ){
204 $this->messages
[$s->page_title
]['customised'] = 1;
206 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
207 $this->talkPages
[$s->page_title
] = 1;
210 $dbr->freeResult( $res );
212 wfProfileOut( __METHOD__
. "-db" );
217 /* This function normally does a database query to get the results; we need
218 * to make a pretend result using a FakeResultWrapper.
220 function reallyDoQuery( $offset , $limit , $descending ){
221 $mResult = new FakeResultWrapper( array() );
223 if( !$this->messages
) $this->getAllMessages( $descending );
224 if( $this->talkPages
=== NULL ) $this->markCustomisedMessages();
227 foreach( $this->messages
as $key => $value ){
228 if( $value['customised'] !== $this->custom
&&
229 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
230 (( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
232 $mResult->result
[] = array( 'am_title' => $key,
233 'am_actual' => $value['actual'],
234 'am_default' => $value['default'],
235 'am_customised' => $value['customised'],
237 unset( $this->messages
[$key] ); // save a few bytes
240 if( $count == $limit ) break;
242 unset( $this->messages
); //no longer needed, free up some memory
246 function getStartBody() {
247 return "<table border=\"1\" class=\"TablePager\" style=\"width:100%;\" id=\"allmessagestable\"><thead>\n<tr>" .
248 "<th rowspan=\"2\">" . wfMsg('allmessagesname') . "</th><th>" . wfMsg('allmessagesdefault') .
249 "</tr>\n<tr><th>" . wfMsg('allmessagescurrent') . "</th></tr>\n";
252 function formatValue( $field , $value ){
258 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
259 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
261 if( $this->mCurrentRow
->am_customised
){
262 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
264 $title = $this->mSkin
->link( $title,
265 $wgLang->lcfirst( $value ),
270 if( array_key_exists( $talk->getDBkey() , $this->talkPages
) ) {
271 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
273 $talk = $this->mSkin
->link( $talk,
279 return $title . ' (' . $talk . ')';
282 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
284 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
289 function formatRow( $row ){
290 //Do all the normal stuff
291 $s = parent
::formatRow( $row );
293 //But if there's a customised message, add that too.
294 if( $row->am_customised
){
295 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
296 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
297 if ( $formatted == '' ) {
298 $formatted = ' ';
300 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
306 function getRowAttrs( $row, $isSecond=false ){
309 if( $row->am_customised
){
310 $arr['class'] = 'allmessages-customised';
313 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
318 function getCellAttrs( $field, $value ){
319 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
320 return array( 'rowspan' => '2', 'class' => $field );
322 return array( 'class' => $field );
326 // This is not actually used, as getStartBody is overridden above
327 function getFieldNames() {
328 return array( 'am_title' => wfMsg('allmessagesname'),
329 'am_default' => wfMsg('allmessagesdefault') );
331 function getTitle() {
332 return SpecialPage
::getTitleFor( 'Allmessages', false );
334 function isFieldSortable( $x ){
337 function getDefaultSort(){
340 function getQueryInfo(){
344 /* Overloads the relevant methods of the real ResultsWrapper so it
345 * doesn't go anywhere near an actual database.
347 class FakeResultWrapper
extends ResultWrapper
{
349 var $result = array();
350 var $db = NULL; //And it's going to stay that way :D
352 var $currentRow = NULL;
354 function __construct( $array ){
355 $this->result
= $array;
359 return count( $this->result
);
362 function fetchRow() {
363 $this->currentRow
= $this->result
[$this->pos++
];
364 return $this->currentRow
;
367 function seek( $row ) {
373 // Callers want to be able to access fields with $this->fieldName
374 function fetchObject(){
375 $this->currentRow
= $this->result
[$this->pos++
];
376 return (object)$this->currentRow
;
381 $this->currentRow
= NULL;