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 public $mLimitsShown;
131 function __construct( $page, $conds, $langObj = null ) {
132 parent
::__construct();
133 $this->mIndexField
= 'am_title';
134 $this->mPage
= $page;
135 $this->mConds
= $conds;
136 $this->mDefaultDirection
= true; // always sort ascending
137 // We want to have an option for people to view *all* the messages,
138 // so they can use Ctrl+F to search them. 5000 is the maximum that
139 // will get through WebRequest::getLimitOffset().
140 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
142 global $wgLang, $wgContLang, $wgRequest;
144 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
146 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
147 $this->langcode
= $this->lang
->getCode();
148 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
150 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
151 $this->custom
= null; // So won't match in either case
153 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
156 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
157 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
158 if( $prefix !== null ){
159 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
161 $this->prefix
= false;
165 // The suffix that may be needed for message names if we're in a
166 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
167 if( $this->foreign
) {
168 $this->suffix
= '/' . $this->langcode
;
174 function getAllMessages( $descending ) {
175 wfProfileIn( __METHOD__
);
176 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
178 rsort( $messageNames );
180 asort( $messageNames );
183 // Normalise message names so they look like page titles
184 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
185 wfProfileIn( __METHOD__
);
187 return $messageNames;
191 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
192 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
193 * an entry for each existing page, with the key being the message name and
196 function getCustomisedStatuses( $messageNames ) {
197 wfProfileIn( __METHOD__
. '-db' );
199 $dbr = wfGetDB( DB_SLAVE
);
200 $res = $dbr->select( 'page',
201 array( 'page_namespace', 'page_title' ),
202 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
204 array( 'USE INDEX' => 'name_title' )
206 $xNames = array_flip( $messageNames );
208 $pageFlags = $talkFlags = array();
210 while( $s = $dbr->fetchObject( $res ) ) {
211 if( $s->page_namespace
== NS_MEDIAWIKI
) {
212 if( $this->foreign
) {
213 $title = explode( '/', $s->page_title
);
214 if( count( $title ) === 2 && $this->langcode
== $title[1]
215 && isset( $xNames[$title[0]] ) )
217 $pageFlags["{$title[0]}"] = true;
219 } elseif( isset( $xNames[$s->page_title
] ) ) {
220 $pageFlags[$s->page_title
] = true;
222 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
223 $talkFlags[$s->page_title
] = true;
226 $dbr->freeResult( $res );
228 wfProfileOut( __METHOD__
. '-db' );
230 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
233 /* This function normally does a database query to get the results; we need
234 * to make a pretend result using a FakeResultWrapper.
236 function reallyDoQuery( $offset, $limit, $descending ) {
237 $result = new FakeResultWrapper( array() );
239 $messageNames = $this->getAllMessages( $descending );
240 $statuses = $this->getCustomisedStatuses( $messageNames );
243 foreach( $messageNames as $key ) {
244 $customised = isset( $statuses['pages'][$key] );
245 if( $customised !== $this->custom
&&
246 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
247 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
249 $result->result
[] = array(
251 'am_actual' => wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false ),
252 'am_default' => wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false ),
253 'am_customised' => $customised,
254 'am_talk_exists' => isset( $statuses['talks'][$key] )
258 if( $count == $limit ) break;
263 function getStartBody() {
264 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
266 <th rowspan=\"2\">" .
267 wfMsg( 'allmessagesname' ) . "
270 wfMsg( 'allmessagesdefault' ) .
275 wfMsg( 'allmessagescurrent' ) .
277 </tr></thead><tbody>\n";
280 function formatValue( $field, $value ){
286 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
287 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
289 if( $this->mCurrentRow
->am_customised
){
290 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
292 $title = $this->mSkin
->link(
294 $wgLang->lcfirst( $value ),
300 if ( $this->mCurrentRow
->am_talk_exists
) {
301 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
303 $talk = $this->mSkin
->link(
311 return $title . ' (' . $talk . ')';
314 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
316 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
321 function formatRow( $row ){
322 // Do all the normal stuff
323 $s = parent
::formatRow( $row );
325 // But if there's a customised message, add that too.
326 if( $row->am_customised
){
327 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
328 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
329 if ( $formatted == '' ) {
330 $formatted = ' ';
332 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
338 function getRowAttrs( $row, $isSecond = false ){
341 if( $row->am_customised
){
342 $arr['class'] = 'allmessages-customised';
345 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
350 function getCellAttrs( $field, $value ){
351 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
352 return array( 'rowspan' => '2', 'class' => $field );
354 return array( 'class' => $field );
358 // This is not actually used, as getStartBody is overridden above
359 function getFieldNames() {
361 'am_title' => wfMsg( 'allmessagesname' ),
362 'am_default' => wfMsg( 'allmessagesdefault' )
365 function getTitle() {
366 return SpecialPage
::getTitleFor( 'Allmessages', false );
368 function isFieldSortable( $x ){
371 function getDefaultSort(){
374 function getQueryInfo(){
378 /* Overloads the relevant methods of the real ResultsWrapper so it
379 * doesn't go anywhere near an actual database.
381 class FakeResultWrapper
extends ResultWrapper
{
383 var $result = array();
384 var $db = null; // And it's going to stay that way :D
386 var $currentRow = null;
388 function __construct( $array ){
389 $this->result
= $array;
393 return count( $this->result
);
396 function fetchRow() {
397 $this->currentRow
= $this->result
[$this->pos++
];
398 return $this->currentRow
;
401 function seek( $row ) {
407 // Callers want to be able to access fields with $this->fieldName
408 function fetchObject(){
409 $this->currentRow
= $this->result
[$this->pos++
];
410 return (object)$this->currentRow
;
415 $this->currentRow
= null;