3 * Implements Special:Allmessages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Use this special page to get a list of the MediaWiki system messages.
28 * @ingroup SpecialPage
30 class SpecialAllmessages
extends SpecialPage
{
33 * @var AllmessagesTablePager
40 public function __construct() {
41 parent
::__construct( 'Allmessages' );
45 * Show the special page
47 * @param $par Mixed: parameter passed to the page or null
49 public function execute( $par ) {
50 $request = $this->getRequest();
51 $out = $this->getOutput();
55 global $wgUseDatabaseMessages;
56 if( !$wgUseDatabaseMessages ) {
57 $out->addWikiMsg( 'allmessagesnotsupportedDB' );
60 $this->outputHeader( 'allmessagestext' );
63 $out->addModuleStyles( 'mediawiki.special' );
65 $this->filter
= $request->getVal( 'wpFilter', 'all' );
66 $this->prefix
= $request->getVal( 'wpPrefix', '' );
68 $this->table
= new AllmessagesTablePager(
71 wfGetLangObj( $request->getVal( 'wpLanguage', $par ) )
74 $this->langcode
= $this->table
->lang
->getCode();
76 $out->addHTML( $this->table
->buildHTMLForm() .
77 $this->table
->getNavigationBar() .
78 $this->table
->getBody() .
79 $this->table
->getNavigationBar() );
86 * Use TablePager for prettified output. We have to pretend that we're
87 * getting data from a table when in fact not all of it comes from the database.
89 class AllmessagesTablePager
extends TablePager
{
91 protected $filter, $prefix, $langcode, $displayPrefix;
105 function __construct( $page, $conds, $langObj = null ) {
106 parent
::__construct( $page->getContext() );
107 $this->mIndexField
= 'am_title';
108 $this->mPage
= $page;
109 $this->mConds
= $conds;
110 $this->mDefaultDirection
= true; // always sort ascending
111 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
115 $this->talk
= $this->msg( 'talkpagelinktext' )->escaped();
117 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
118 $this->langcode
= $this->lang
->getCode();
119 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
121 $request = $this->getRequest();
123 if( $request->getVal( 'wpFilter', 'all' ) === 'all' ){
124 $this->custom
= null; // So won't match in either case
126 $this->custom
= ($request->getVal( 'wpFilter' ) == 'unmodified');
129 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'wpPrefix', '' ) );
130 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $request->getVal( 'wpPrefix', null ) ) : null;
131 if( $prefix !== null ){
132 $this->displayPrefix
= $prefix->getDBkey();
133 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
135 $this->displayPrefix
= false;
136 $this->prefix
= false;
139 // The suffix that may be needed for message names if we're in a
140 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
141 if( $this->foreign
) {
142 $this->suffix
= '/' . $this->langcode
;
148 protected function getHTMLFormFields() {
152 'label-message' => 'allmessages-prefix',
157 'label-message' => 'allmessages-filter',
159 $this->msg( 'allmessages-filter-unmodified' )->text() => 'unmodified',
160 $this->msg( 'allmessages-filter-all' )->text() => 'all',
161 $this->msg( 'allmessages-filter-modified' )->text() => 'modified',
167 'label-message' => 'allmessages-language',
168 'options' => array(), // This is filled in below
169 'default' => $this->langcode
,
171 'Limit' => $this->getHTMLFormLimitSelect(),
174 $languages = Language
::getLanguageNames( false );
177 foreach( $languages as $code => $name ) {
178 $f['Language']['options'][ "$code - $name" ] = $code;
184 protected function getHTMLFormLegend() {
185 return 'allmessages-filter-legend';
188 protected function getHTMLFormSubmit() {
189 return 'allmessages-filter-submit';
192 function getAllMessages( $descending ) {
193 wfProfileIn( __METHOD__
);
194 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
196 rsort( $messageNames );
198 asort( $messageNames );
201 // Normalise message names so they look like page titles
202 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
204 wfProfileOut( __METHOD__
);
205 return $messageNames;
209 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
210 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
211 * an entry for each existing page, with the key being the message name and
214 * @param array $messageNames
215 * @param string $langcode What language code
216 * @param bool $foreign Whether the $langcode is not the content language
217 * @return array: a 'pages' and 'talks' array with the keys of existing pages
219 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
220 // FIXME: This function should be moved to Language:: or something.
221 wfProfileIn( __METHOD__
. '-db' );
223 $dbr = wfGetDB( DB_SLAVE
);
224 $res = $dbr->select( 'page',
225 array( 'page_namespace', 'page_title' ),
226 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
228 array( 'USE INDEX' => 'name_title' )
230 $xNames = array_flip( $messageNames );
232 $pageFlags = $talkFlags = array();
234 foreach ( $res as $s ) {
237 $title = explode( '/', $s->page_title
);
238 if( count( $title ) === 2 && $langcode == $title[1]
239 && isset( $xNames[$title[0]] ) ) {
242 } elseif( isset( $xNames[$s->page_title
] ) ) {
243 $exists = $s->page_title
;
245 if( $exists && $s->page_namespace
== NS_MEDIAWIKI
) {
246 $pageFlags[$exists] = true;
247 } elseif( $exists && $s->page_namespace
== NS_MEDIAWIKI_TALK
) {
248 $talkFlags[$exists] = true;
252 wfProfileOut( __METHOD__
. '-db' );
254 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
258 * This function normally does a database query to get the results; we need
259 * to make a pretend result using a FakeResultWrapper.
261 function reallyDoQuery( $offset, $limit, $descending ) {
262 $result = new FakeResultWrapper( array() );
264 $messageNames = $this->getAllMessages( $descending );
265 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
268 foreach( $messageNames as $key ) {
269 $customised = isset( $statuses['pages'][$key] );
270 if( $customised !== $this->custom
&&
271 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
272 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
274 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
275 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
276 $result->result
[] = array(
278 'am_actual' => $actual,
279 'am_default' => $default,
280 'am_customised' => $customised,
281 'am_talk_exists' => isset( $statuses['talks'][$key] )
285 if( $count == $limit ) {
292 function getStartBody() {
293 return Xml
::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
295 <th rowspan=\"2\">" .
296 $this->msg( 'allmessagesname' )->escaped() . "
299 $this->msg( 'allmessagesdefault' )->escaped() .
304 $this->msg( 'allmessagescurrent' )->escaped() .
306 </tr></thead><tbody>\n";
309 function formatValue( $field, $value ){
314 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
315 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
317 if( $this->mCurrentRow
->am_customised
){
318 $title = Linker
::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
320 $title = Linker
::link(
322 $this->getLanguage()->lcfirst( $value ),
328 if ( $this->mCurrentRow
->am_talk_exists
) {
329 $talk = Linker
::linkKnown( $talk , $this->talk
);
331 $talk = Linker
::link(
339 return $title . ' (' . $talk . ')';
343 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
348 function formatRow( $row ){
349 // Do all the normal stuff
350 $s = parent
::formatRow( $row );
352 // But if there's a customised message, add that too.
353 if( $row->am_customised
){
354 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
355 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
356 if ( $formatted == '' ) {
357 $formatted = ' ';
359 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
365 function getRowAttrs( $row, $isSecond = false ){
367 if( $row->am_customised
){
368 $arr['class'] = 'allmessages-customised';
371 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title
) );
376 function getCellAttrs( $field, $value ){
377 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
378 return array( 'rowspan' => '2', 'class' => $field );
379 } elseif( $field == 'am_title' ) {
380 return array( 'class' => $field );
382 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir(), 'class' => $field );
386 // This is not actually used, as getStartBody is overridden above
387 function getFieldNames() {
389 'am_title' => $this->msg( 'allmessagesname' )->text(),
390 'am_default' => $this->msg( 'allmessagesdefault' )->text()
394 function getTitle() {
395 return SpecialPage
::getTitleFor( 'Allmessages', false );
398 function isFieldSortable( $x ){
402 function getDefaultSort(){
406 function getQueryInfo(){