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' );
157 * Use TablePager for prettified output. We have to pretend that we're
158 * getting data from a table when in fact not all of it comes from the database.
160 class AllmessagesTablePager
extends TablePager
{
162 public $mLimitsShown;
179 function __construct( $page, $conds, $langObj = null ) {
180 parent
::__construct();
181 $this->mIndexField
= 'am_title';
182 $this->mPage
= $page;
183 $this->mConds
= $conds;
184 $this->mDefaultDirection
= true; // always sort ascending
185 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
187 global $wgLang, $wgContLang, $wgRequest;
189 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
191 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
192 $this->langcode
= $this->lang
->getCode();
193 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
195 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
196 $this->custom
= null; // So won't match in either case
198 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
201 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
202 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
203 if( $prefix !== null ){
204 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
206 $this->prefix
= false;
210 // The suffix that may be needed for message names if we're in a
211 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
212 if( $this->foreign
) {
213 $this->suffix
= '/' . $this->langcode
;
219 function getAllMessages( $descending ) {
220 wfProfileIn( __METHOD__
);
221 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
223 rsort( $messageNames );
225 asort( $messageNames );
228 // Normalise message names so they look like page titles
229 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
231 wfProfileOut( __METHOD__
);
232 return $messageNames;
236 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
237 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
238 * an entry for each existing page, with the key being the message name and
241 * @param array $messageNames
242 * @param string $langcode What language code
243 * @param bool $foreign Whether the $langcode is not the content language
245 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
246 wfProfileIn( __METHOD__
. '-db' );
248 $dbr = wfGetDB( DB_SLAVE
);
249 $res = $dbr->select( 'page',
250 array( 'page_namespace', 'page_title' ),
251 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
253 array( 'USE INDEX' => 'name_title' )
255 $xNames = array_flip( $messageNames );
257 $pageFlags = $talkFlags = array();
259 foreach ( $res as $s ) {
260 if( $s->page_namespace
== NS_MEDIAWIKI
) {
262 $title = explode( '/', $s->page_title
);
263 if( count( $title ) === 2 && $langcode == $title[1]
264 && isset( $xNames[$title[0]] ) ) {
265 $pageFlags["{$title[0]}"] = true;
267 } elseif( isset( $xNames[$s->page_title
] ) ) {
268 $pageFlags[$s->page_title
] = true;
270 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
271 $talkFlags[$s->page_title
] = true;
275 wfProfileOut( __METHOD__
. '-db' );
277 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
281 * This function normally does a database query to get the results; we need
282 * to make a pretend result using a FakeResultWrapper.
284 function reallyDoQuery( $offset, $limit, $descending ) {
285 $result = new FakeResultWrapper( array() );
287 $messageNames = $this->getAllMessages( $descending );
288 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
291 foreach( $messageNames as $key ) {
292 $customised = isset( $statuses['pages'][$key] );
293 if( $customised !== $this->custom
&&
294 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
295 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
297 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
298 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
299 $result->result
[] = array(
301 'am_actual' => $actual,
302 'am_default' => $default,
303 'am_customised' => $customised,
304 'am_talk_exists' => isset( $statuses['talks'][$key] )
308 if( $count == $limit ) {
315 function getStartBody() {
316 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
318 <th rowspan=\"2\">" .
319 wfMsg( 'allmessagesname' ) . "
322 wfMsg( 'allmessagesdefault' ) .
327 wfMsg( 'allmessagescurrent' ) .
329 </tr></thead><tbody>\n";
332 function formatValue( $field, $value ){
338 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
339 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
341 if( $this->mCurrentRow
->am_customised
){
342 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
344 $title = $this->mSkin
->link(
346 $wgLang->lcfirst( $value ),
352 if ( $this->mCurrentRow
->am_talk_exists
) {
353 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
355 $talk = $this->mSkin
->link(
363 return $title . ' (' . $talk . ')';
367 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
372 function formatRow( $row ){
373 // Do all the normal stuff
374 $s = parent
::formatRow( $row );
376 // But if there's a customised message, add that too.
377 if( $row->am_customised
){
378 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
379 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
380 if ( $formatted == '' ) {
381 $formatted = ' ';
383 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
389 function getRowAttrs( $row, $isSecond = false ){
392 if( $row->am_customised
){
393 $arr['class'] = 'allmessages-customised';
396 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
401 function getCellAttrs( $field, $value ){
402 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
403 return array( 'rowspan' => '2', 'class' => $field );
405 return array( 'class' => $field );
409 // This is not actually used, as getStartBody is overridden above
410 function getFieldNames() {
412 'am_title' => wfMsg( 'allmessagesname' ),
413 'am_default' => wfMsg( 'allmessagesdefault' )
417 function getTitle() {
418 return SpecialPage
::getTitleFor( 'Allmessages', false );
421 function isFieldSortable( $x ){
425 function getDefaultSort(){
429 function getQueryInfo(){