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;
131 public $mLimitsShown;
133 function __construct( $page, $conds, $langObj = null ) {
134 parent
::__construct();
135 $this->mIndexField
= 'am_title';
136 $this->mPage
= $page;
137 $this->mConds
= $conds;
138 $this->mDefaultDirection
= true; // always sort ascending
139 // We want to have an option for people to view *all* the messages,
140 // so they can use Ctrl+F to search them. 5000 is the maximum that
141 // will get through WebRequest::getLimitOffset().
142 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 => wfMsg('limitall') );
144 global $wgLang, $wgContLang, $wgRequest;
146 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
148 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
149 $this->langcode
= $this->lang
->getCode();
150 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
152 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
153 $this->custom
= null; // So won't match in either case
155 $this->custom
= $wgRequest->getVal( 'filter' ) == 'unmodified' ?
1 : 0;
158 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
159 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
160 if( $prefix !== null ){
161 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
163 $this->prefix
= false;
167 // The suffix that may be needed for message names if we're in a
168 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
169 if( $this->foreign
) {
170 $this->suffix
= '/' . $this->langcode
;
176 function getAllMessages( $desc ){
177 wfProfileIn( __METHOD__
. '-cache' );
179 # Make sure all extension messages are available
180 global $wgMessageCache;
181 $wgMessageCache->loadAllMessages( 'en' );
182 $sortedArray = Language
::getMessagesFor( 'en' );
184 krsort( $sortedArray );
186 ksort( $sortedArray );
189 $this->messages
= array();
190 foreach( $sortedArray as $key => $value ) {
191 // All messages start with lowercase, but wikis might have both
192 // upper and lowercase MediaWiki: pages if $wgCapitalLinks=false.
193 $ukey = $this->lang
->ucfirst( $key );
195 // The value without any overrides from the MediaWiki: namespace
196 $this->messages
[$ukey]['default'] = wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false );
198 // The message that's actually used by the site
199 $this->messages
[$ukey]['actual'] = wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false );
201 $this->messages
[$ukey]['customised'] = 0; //for now
203 $sortedArray[$key] = null; // trade bytes from $sortedArray to this
206 wfProfileOut( __METHOD__
. '-cache' );
211 # We only need a list of which messages have *been* customised;
212 # their content is already in the message cache.
213 function markCustomisedMessages(){
214 $this->talkPages
= array();
216 wfProfileIn( __METHOD__
. '-db' );
218 $dbr = wfGetDB( DB_SLAVE
);
219 $res = $dbr->select( 'page',
220 array( 'page_namespace', 'page_title' ),
221 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
223 array( 'USE INDEX' => 'name_title' )
226 while( $s = $dbr->fetchObject( $res ) ) {
227 if( $s->page_namespace
== NS_MEDIAWIKI
){
228 if( $this->foreign
){
229 $title = explode( '/', $s->page_title
);
230 if( count( $title ) === 2 && $this->langcode
== $title[1] && array_key_exists( $title[0], $this->messages
) ){
231 $this->messages
["{$title[0]}"]['customised'] = 1;
233 } else if( array_key_exists( $s->page_title
, $this->messages
) ){
234 $this->messages
[$s->page_title
]['customised'] = 1;
236 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
237 $this->talkPages
[$s->page_title
] = 1;
240 $dbr->freeResult( $res );
242 wfProfileOut( __METHOD__
. '-db' );
247 /* This function normally does a database query to get the results; we need
248 * to make a pretend result using a FakeResultWrapper.
250 function reallyDoQuery( $offset, $limit, $descending ){
251 $mResult = new FakeResultWrapper( array() );
253 if( !$this->messages
) $this->getAllMessages( $descending );
254 if( $this->talkPages
=== null ) $this->markCustomisedMessages();
257 foreach( $this->messages
as $key => $value ){
258 if( $value['customised'] !== $this->custom
&&
259 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
260 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
262 $mResult->result
[] = array(
264 'am_actual' => $value['actual'],
265 'am_default' => $value['default'],
266 'am_customised' => $value['customised'],
268 unset( $this->messages
[$key] ); // save a few bytes
271 if( $count == $limit ) break;
273 unset( $this->messages
); // no longer needed, free up some memory
277 function getStartBody() {
278 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
280 <th rowspan=\"2\">" .
281 wfMsg( 'allmessagesname' ) . "
284 wfMsg( 'allmessagesdefault' ) .
289 wfMsg( 'allmessagescurrent' ) .
291 </tr></thead><tbody>\n";
294 function formatValue( $field, $value ){
300 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
301 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
303 if( $this->mCurrentRow
->am_customised
){
304 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
306 $title = $this->mSkin
->link(
308 $wgLang->lcfirst( $value ),
314 if( array_key_exists( $talk->getDBkey() , $this->talkPages
) ) {
315 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
317 $talk = $this->mSkin
->link(
325 return $title . ' (' . $talk . ')';
328 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
330 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
335 function formatRow( $row ){
336 // Do all the normal stuff
337 $s = parent
::formatRow( $row );
339 // But if there's a customised message, add that too.
340 if( $row->am_customised
){
341 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
342 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
343 if ( $formatted == '' ) {
344 $formatted = ' ';
346 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
352 function getRowAttrs( $row, $isSecond = false ){
355 if( $row->am_customised
){
356 $arr['class'] = 'allmessages-customised';
359 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
364 function getCellAttrs( $field, $value ){
365 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
366 return array( 'rowspan' => '2', 'class' => $field );
368 return array( 'class' => $field );
372 // This is not actually used, as getStartBody is overridden above
373 function getFieldNames() {
375 'am_title' => wfMsg( 'allmessagesname' ),
376 'am_default' => wfMsg( 'allmessagesdefault' )
379 function getTitle() {
380 return SpecialPage
::getTitleFor( 'Allmessages', false );
382 function isFieldSortable( $x ){
385 function getDefaultSort(){
388 function getQueryInfo(){
392 /* Overloads the relevant methods of the real ResultsWrapper so it
393 * doesn't go anywhere near an actual database.
395 class FakeResultWrapper
extends ResultWrapper
{
397 var $result = array();
398 var $db = null; // And it's going to stay that way :D
400 var $currentRow = null;
402 function __construct( $array ){
403 $this->result
= $array;
407 return count( $this->result
);
410 function fetchRow() {
411 $this->currentRow
= $this->result
[$this->pos++
];
412 return $this->currentRow
;
415 function seek( $row ) {
421 // Callers want to be able to access fields with $this->fieldName
422 function fetchObject(){
423 $this->currentRow
= $this->result
[$this->pos++
];
424 return (object)$this->currentRow
;
429 $this->currentRow
= null;