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
37 protected $filter, $prefix, $langCode;
42 public function __construct() {
43 parent
::__construct( 'Allmessages' );
47 * Show the special page
49 * @param $par Mixed: parameter passed to the page or null
51 public function execute( $par ) {
52 global $wgOut, $wgRequest;
56 global $wgUseDatabaseMessages;
57 if( !$wgUseDatabaseMessages ) {
58 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
61 $this->outputHeader( 'allmessagestext' );
64 $wgOut->addModuleStyles( 'mediawiki.special' );
66 $this->filter
= $wgRequest->getVal( 'filter', 'all' );
67 $this->prefix
= $wgRequest->getVal( 'prefix', '' );
69 $this->table
= new AllmessagesTablePager(
72 wfGetLangObj( $wgRequest->getVal( 'lang', $par ) )
75 $this->langCode
= $this->table
->lang
->getCode();
77 $wgOut->addHTML( $this->buildForm() .
78 $this->table
->getNavigationBar() .
79 $this->table
->getLimitForm() .
80 $this->table
->getBody() .
81 $this->table
->getNavigationBar() );
85 function buildForm() {
88 $languages = Language
::getLanguageNames( false );
91 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
92 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
93 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
94 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
96 <td class="mw-label">' .
97 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
99 <td class=\"mw-input\">" .
100 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
104 <td class='mw-label'>" .
105 wfMsg( 'allmessages-filter' ) .
107 <td class='mw-input'>" .
108 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
111 'mw-allmessages-form-filter-unmodified',
112 ( $this->filter
== 'unmodified' )
114 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
117 'mw-allmessages-form-filter-all',
118 ( $this->filter
== 'all' )
120 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
123 'mw-allmessages-form-filter-modified',
124 ( $this->filter
== 'modified' )
129 <td class=\"mw-label\">" .
130 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
132 <td class=\"mw-input\">" .
133 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
135 foreach( $languages as $lang => $name ) {
136 $selected = $lang == $this->langCode
;
137 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
139 $out .= Xml
::closeElement( 'select' ) .
145 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
148 Xml
::closeElement( 'table' ) .
149 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
150 Xml
::closeElement( 'fieldset' ) .
151 Xml
::closeElement( 'form' );
156 /* use TablePager for prettified output. We have to pretend that we're
157 * getting data from a table when in fact not all of it comes from the database.
159 class AllmessagesTablePager
extends TablePager
{
161 public $mLimitsShown;
173 function __construct( $page, $conds, $langObj = null ) {
174 parent
::__construct();
175 $this->mIndexField
= 'am_title';
176 $this->mPage
= $page;
177 $this->mConds
= $conds;
178 $this->mDefaultDirection
= true; // always sort ascending
179 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
181 global $wgLang, $wgContLang, $wgRequest;
183 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
185 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
186 $this->langcode
= $this->lang
->getCode();
187 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
189 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
190 $this->custom
= null; // So won't match in either case
192 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
195 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
196 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
197 if( $prefix !== null ){
198 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
200 $this->prefix
= false;
204 // The suffix that may be needed for message names if we're in a
205 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
206 if( $this->foreign
) {
207 $this->suffix
= '/' . $this->langcode
;
213 function getAllMessages( $descending ) {
214 wfProfileIn( __METHOD__
);
215 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
217 rsort( $messageNames );
219 asort( $messageNames );
222 // Normalise message names so they look like page titles
223 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
225 wfProfileOut( __METHOD__
);
226 return $messageNames;
230 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
231 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
232 * an entry for each existing page, with the key being the message name and
235 function getCustomisedStatuses( $messageNames ) {
236 wfProfileIn( __METHOD__
. '-db' );
238 $dbr = wfGetDB( DB_SLAVE
);
239 $res = $dbr->select( 'page',
240 array( 'page_namespace', 'page_title' ),
241 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
243 array( 'USE INDEX' => 'name_title' )
245 $xNames = array_flip( $messageNames );
247 $pageFlags = $talkFlags = array();
249 foreach ( $res as $s ) {
250 if( $s->page_namespace
== NS_MEDIAWIKI
) {
251 if( $this->foreign
) {
252 $title = explode( '/', $s->page_title
);
253 if( count( $title ) === 2 && $this->langcode
== $title[1]
254 && isset( $xNames[$title[0]] ) )
256 $pageFlags["{$title[0]}"] = true;
258 } elseif( isset( $xNames[$s->page_title
] ) ) {
259 $pageFlags[$s->page_title
] = true;
261 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
262 $talkFlags[$s->page_title
] = true;
266 wfProfileOut( __METHOD__
. '-db' );
268 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
271 /* This function normally does a database query to get the results; we need
272 * to make a pretend result using a FakeResultWrapper.
274 function reallyDoQuery( $offset, $limit, $descending ) {
275 $result = new FakeResultWrapper( array() );
277 $messageNames = $this->getAllMessages( $descending );
278 $statuses = $this->getCustomisedStatuses( $messageNames );
281 foreach( $messageNames as $key ) {
282 $customised = isset( $statuses['pages'][$key] );
283 if( $customised !== $this->custom
&&
284 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
285 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
287 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
288 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
289 $result->result
[] = array(
291 'am_actual' => $actual,
292 'am_default' => $default,
293 'am_customised' => $customised,
294 'am_talk_exists' => isset( $statuses['talks'][$key] )
298 if( $count == $limit ) {
305 function getStartBody() {
306 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
308 <th rowspan=\"2\">" .
309 wfMsg( 'allmessagesname' ) . "
312 wfMsg( 'allmessagesdefault' ) .
317 wfMsg( 'allmessagescurrent' ) .
319 </tr></thead><tbody>\n";
322 function formatValue( $field, $value ){
328 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
329 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
331 if( $this->mCurrentRow
->am_customised
){
332 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
334 $title = $this->mSkin
->link(
336 $wgLang->lcfirst( $value ),
342 if ( $this->mCurrentRow
->am_talk_exists
) {
343 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
345 $talk = $this->mSkin
->link(
353 return $title . ' (' . $talk . ')';
357 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
362 function formatRow( $row ){
363 // Do all the normal stuff
364 $s = parent
::formatRow( $row );
366 // But if there's a customised message, add that too.
367 if( $row->am_customised
){
368 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
369 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
370 if ( $formatted == '' ) {
371 $formatted = ' ';
373 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
379 function getRowAttrs( $row, $isSecond = false ){
382 if( $row->am_customised
){
383 $arr['class'] = 'allmessages-customised';
386 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
391 function getCellAttrs( $field, $value ){
392 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
393 return array( 'rowspan' => '2', 'class' => $field );
395 return array( 'class' => $field );
399 // This is not actually used, as getStartBody is overridden above
400 function getFieldNames() {
402 'am_title' => wfMsg( 'allmessagesname' ),
403 'am_default' => wfMsg( 'allmessagesdefault' )
407 function getTitle() {
408 return SpecialPage
::getTitleFor( 'Allmessages', false );
411 function isFieldSortable( $x ){
415 function getDefaultSort(){
419 function getQueryInfo(){