9a09d07de20cadda84f66cbe39de72784d665445
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
::hidden( 'title', $this->getTitle() ) .
56 Xml
::element( 'legend', null, wfMsg( 'allmessages' ) ) . "<table><tr>\n" .
57 "<td class=\"mw-label\">" .
58 Xml
::label( wfMsg('allmessages-prefix'), 'am-form-prefix' ) .
59 "</td>\n<td class=\"mw-input\">" .
60 Xml
::input( 'prefix', 20, str_replace('_',' ',$this->prefix
), array( 'id' => 'am-form-prefix' ) ) .
62 "</td>\n</tr><tr>\n<td class='mw-label'>" .
63 Xml
::label( wfMsg('allmessages-filter'), 'am-form-filter' ) .
64 "</td>\n<td class='mw-input'>" .
65 Xml
::radioLabel( wfMsg('allmessages-filter-unmodified'),
68 'am-form-filter-unmodified',
69 ( $this->filter
== 'unmodified' ?
true : false )
71 Xml
::radioLabel( wfMsg('allmessages-filter-all'),
75 ( $this->filter
== 'all' ?
true : false )
77 Xml
::radioLabel( wfMsg('allmessages-filter-modified'),
80 'am-form-filter-modified',
81 ( $this->filter
== 'modified' ?
true : false )
83 "</td>\n</tr><tr>\n<td class=\"mw-label\">" .
84 Xml
::label( wfMsg('yourlanguage'), 'am-form-lang' ) .
85 "</td>\n<td class=\"mw-input\">" .
86 Xml
::openElement( 'select', array( 'id' => 'am-form-lang', 'name' => 'lang' ) );
87 foreach( $languages as $lang => $name ) {
88 $selected = $lang == $this->langCode ?
'selected="selected"' : '';
89 $out .= "<option value=\"$lang\" $selected>$name</option>\n";
91 $out .= "</td>\n</tr><tr>\n<td></td><td>" . Xml
::submitButton( wfMsg('allpagessubmit') ) .
93 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
99 /* use TablePager for prettified output. We have to pretend that we're
100 * getting data from a table when in fact not all of it comes from the database.
102 class AllmessagesTablePager
extends TablePager
{
104 var $messages = NULL;
105 var $talkPages = NULL;
107 function __construct( $page, $conds, $langObj = NULL ) {
108 parent
::__construct();
109 $this->mIndexField
= 'am_title';
110 $this->mPage
= $page;
111 $this->mConds
= $conds;
112 $this->mDefaultDirection
= true; //always sort ascending
114 global $wgLang, $wgContLang, $wgRequest;
116 $this->talk
= $wgLang->lc( htmlspecialchars( wfMsg( 'talkpagelinktext' ) ) );
118 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
119 $this->langcode
= $this->lang
->getCode();
120 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
122 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
123 $this->custom
= NULL; //So won't match in either case
125 $this->custom
= $wgRequest->getVal( 'filter' ) == 'unmodified' ?
1 : 0;
128 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
129 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', NULL ) ) : NULL;
130 if( $prefix !== NULL ){
131 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
133 $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 getAllMessages( $desc ){
148 wfProfileIn( __METHOD__
. '-cache' );
150 # Make sure all extension messages are available
151 global $wgMessageCache;
152 $wgMessageCache->loadAllMessages( 'en' );
153 $sortedArray = Language
::getMessagesFor( 'en' );
155 krsort( $sortedArray );
157 ksort( $sortedArray );
160 $this->messages
= array();
161 foreach( $sortedArray as $key => $value ) {
162 // All messages start with lowercase, but wikis might have both
163 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
164 $ukey = $this->lang
->ucfirst( $key );
166 // The value without any overrides from the MediaWiki: namespace
167 $this->messages
[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false );
169 // The message that's actually used by the site
170 $this->messages
[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false );
172 $this->messages
[$ukey]['customised'] = 0; //for now
174 $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this
177 wfProfileOut( __METHOD__
. '-cache' );
182 # We only need a list of which messages have *been* customised;
183 # their content is already in the message cache.
184 function markCustomisedMessages(){
185 $this->talkPages
= array();
187 wfProfileIn( __METHOD__
. "-db" );
189 $dbr = wfGetDB( DB_SLAVE
);
190 $res = $dbr->select( 'page',
191 array( 'page_namespace', 'page_title' ),
192 array( 'page_namespace' => array(NS_MEDIAWIKI
,NS_MEDIAWIKI_TALK
) ),
194 array( 'USE INDEX' => 'name_title' )
197 while( $s = $dbr->fetchObject( $res ) ) {
198 if( $s->page_namespace
== NS_MEDIAWIKI
){
199 if( $this->foreign
){
200 $title = explode( '/', $s->page_title
);
201 if( $this->langcode
== $title[1] && array_key_exists( $title[0], $this->messages
) ){
202 $this->messages
["{$title[0]}"]['customised'] = 1;
204 } else if( array_key_exists( $s->page_title
, $this->messages
) ){
205 $this->messages
[$s->page_title
]['customised'] = 1;
207 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
208 $this->talkPages
[$s->page_title
] = 1;
211 $dbr->freeResult( $res );
213 wfProfileOut( __METHOD__
. "-db" );
218 /* This function normally does a database query to get the results; we need
219 * to make a pretend result using a FakeResultWrapper.
221 function reallyDoQuery( $offset , $limit , $descending ){
222 $mResult = new FakeResultWrapper( array() );
224 if( !$this->messages
) $this->getAllMessages( $descending );
225 if( $this->talkPages
=== NULL ) $this->markCustomisedMessages();
228 foreach( $this->messages
as $key => $value ){
229 if( $value['customised'] !== $this->custom
&&
230 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
231 (( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
233 $mResult->result
[] = array( 'am_title' => $key,
234 'am_actual' => $value['actual'],
235 'am_default' => $value['default'],
236 'am_customised' => $value['customised'],
238 unset( $this->messages
[$key] ); // save a few bytes
241 if( $count == $limit ) break;
243 unset( $this->messages
); //no longer needed, free up some memory
247 function getStartBody() {
248 return "<table border=\"1\" class=\"TablePager\" style=\"width:100%;\" id=\"allmessagestable\"><thead>\n<tr>" .
249 "<th rowspan=\"2\">" . wfMsg('allmessagesname') . "</th><th>" . wfMsg('allmessagesdefault') .
250 "</tr>\n<tr><th>" . wfMsg('allmessagescurrent') . "</th></tr>\n";
253 function formatValue( $field , $value ){
259 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
260 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
262 if( $this->mCurrentRow
->am_customised
){
263 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
265 $title = $this->mSkin
->link( $title,
266 $wgLang->lcfirst( $value ),
271 if( array_key_exists( $talk->getDBkey() , $this->talkPages
) ) {
272 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
274 $talk = $this->mSkin
->link( $talk,
280 return $title . ' (' . $talk . ')';
283 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
285 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
290 function formatRow( $row ){
291 //Do all the normal stuff
292 $s = parent
::formatRow( $row );
294 //But if there's a customised message, add that too.
295 if( $row->am_customised
){
296 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
297 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
298 if ( $formatted == '' ) {
299 $formatted = ' ';
301 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
307 function getRowAttrs( $row, $isSecond=false ){
310 if( $row->am_customised
){
311 $arr['class'] = 'allmessages-customised';
314 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
319 function getCellAttrs( $field, $value ){
320 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
321 return array( 'rowspan' => '2', 'class' => $field );
323 return array( 'class' => $field );
327 // This is not actually used, as getStartBody is overridden above
328 function getFieldNames() {
329 return array( 'am_title' => wfMsg('allmessagesname'),
330 'am_default' => wfMsg('allmessagesdefault') );
332 function getTitle() {
333 return SpecialPage
::getTitleFor( 'Allmessages', false );
335 function isFieldSortable( $x ){
338 function getDefaultSort(){
341 function getQueryInfo(){
345 /* Overloads the relevant methods of the real ResultsWrapper so it
346 * doesn't go anywhere near an actual database.
348 class FakeResultWrapper
extends ResultWrapper
{
350 var $result = array();
351 var $db = NULL; //And it's going to stay that way :D
353 var $currentRow = NULL;
355 function __construct( $array ){
356 $this->result
= $array;
360 return count( $this->result
);
363 function fetchRow() {
364 $this->currentRow
= $this->result
[$this->pos++
];
365 return $this->currentRow
;
368 function seek( $row ) {
374 // Callers want to be able to access fields with $this->fieldName
375 function fetchObject(){
376 $this->currentRow
= $this->result
[$this->pos++
];
377 return (object)$this->currentRow
;
382 $this->currentRow
= NULL;