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( 'filter', 'all' );
66 $this->prefix
= $request->getVal( 'prefix', '' );
68 $this->table
= new AllmessagesTablePager(
71 wfGetLangObj( $request->getVal( 'lang', $par ) )
74 $this->langcode
= $this->table
->lang
->getCode();
76 $out->addHTML( $this->table
->buildForm() .
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;
110 function __construct( $page, $conds, $langObj = null ) {
111 parent
::__construct();
112 $this->mIndexField
= 'am_title';
113 $this->mPage
= $page;
114 $this->mConds
= $conds;
115 $this->mDefaultDirection
= true; // always sort ascending
116 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
118 global $wgLang, $wgContLang, $wgRequest;
120 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
122 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
123 $this->langcode
= $this->lang
->getCode();
124 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
126 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
127 $this->custom
= null; // So won't match in either case
129 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
132 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
133 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
134 if( $prefix !== null ){
135 $this->displayPrefix
= $prefix->getDBkey();
136 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
138 $this->displayPrefix
= false;
139 $this->prefix
= false;
143 // The suffix that may be needed for message names if we're in a
144 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
145 if( $this->foreign
) {
146 $this->suffix
= '/' . $this->langcode
;
152 function buildForm() {
155 $languages = Language
::getLanguageNames( false );
158 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
159 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
160 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
161 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
163 <td class="mw-label">' .
164 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
166 <td class=\"mw-input\">" .
167 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
171 <td class='mw-label'>" .
172 wfMsg( 'allmessages-filter' ) .
174 <td class='mw-input'>" .
175 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
178 'mw-allmessages-form-filter-unmodified',
179 ( $this->filter
== 'unmodified' )
181 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
184 'mw-allmessages-form-filter-all',
185 ( $this->filter
== 'all' )
187 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
190 'mw-allmessages-form-filter-modified',
191 ( $this->filter
== 'modified' )
196 <td class=\"mw-label\">" .
197 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
199 <td class=\"mw-input\">" .
200 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
202 foreach( $languages as $lang => $name ) {
203 $selected = $lang == $this->langcode
;
204 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
206 $out .= Xml
::closeElement( 'select' ) .
211 <td class="mw-label">' .
212 Xml
::label( wfMsg( 'table_pager_limit_label'), 'mw-table_pager_limit_label' ) .
214 <td class="mw-input">' .
215 $this->getLimitSelect() .
220 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
224 Xml
::closeElement( 'table' ) .
225 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
226 Xml
::closeElement( 'fieldset' ) .
227 Xml
::closeElement( 'form' );
231 function getAllMessages( $descending ) {
232 wfProfileIn( __METHOD__
);
233 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
235 rsort( $messageNames );
237 asort( $messageNames );
240 // Normalise message names so they look like page titles
241 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
243 wfProfileOut( __METHOD__
);
244 return $messageNames;
248 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
249 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
250 * an entry for each existing page, with the key being the message name and
253 * @param array $messageNames
254 * @param string $langcode What language code
255 * @param bool $foreign Whether the $langcode is not the content language
257 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
258 wfProfileIn( __METHOD__
. '-db' );
260 $dbr = wfGetDB( DB_SLAVE
);
261 $res = $dbr->select( 'page',
262 array( 'page_namespace', 'page_title' ),
263 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
265 array( 'USE INDEX' => 'name_title' )
267 $xNames = array_flip( $messageNames );
269 $pageFlags = $talkFlags = array();
271 foreach ( $res as $s ) {
272 if( $s->page_namespace
== NS_MEDIAWIKI
) {
274 $title = explode( '/', $s->page_title
);
275 if( count( $title ) === 2 && $langcode == $title[1]
276 && isset( $xNames[$title[0]] ) ) {
277 $pageFlags["{$title[0]}"] = true;
279 } elseif( isset( $xNames[$s->page_title
] ) ) {
280 $pageFlags[$s->page_title
] = true;
282 } elseif( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
283 $talkFlags[$s->page_title
] = true;
287 wfProfileOut( __METHOD__
. '-db' );
289 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
293 * This function normally does a database query to get the results; we need
294 * to make a pretend result using a FakeResultWrapper.
296 function reallyDoQuery( $offset, $limit, $descending ) {
297 $result = new FakeResultWrapper( array() );
299 $messageNames = $this->getAllMessages( $descending );
300 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
303 foreach( $messageNames as $key ) {
304 $customised = isset( $statuses['pages'][$key] );
305 if( $customised !== $this->custom
&&
306 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
307 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
309 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
310 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
311 $result->result
[] = array(
313 'am_actual' => $actual,
314 'am_default' => $default,
315 'am_customised' => $customised,
316 'am_talk_exists' => isset( $statuses['talks'][$key] )
320 if( $count == $limit ) {
327 function getStartBody() {
328 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
330 <th rowspan=\"2\">" .
331 wfMsg( 'allmessagesname' ) . "
334 wfMsg( 'allmessagesdefault' ) .
339 wfMsg( 'allmessagescurrent' ) .
341 </tr></thead><tbody>\n";
344 function formatValue( $field, $value ){
350 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
351 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
353 if( $this->mCurrentRow
->am_customised
){
354 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
356 $title = $this->mSkin
->link(
358 $wgLang->lcfirst( $value ),
364 if ( $this->mCurrentRow
->am_talk_exists
) {
365 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
367 $talk = $this->mSkin
->link(
375 return $title . ' (' . $talk . ')';
379 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
384 function formatRow( $row ){
385 // Do all the normal stuff
386 $s = parent
::formatRow( $row );
388 // But if there's a customised message, add that too.
389 if( $row->am_customised
){
390 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
391 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
392 if ( $formatted == '' ) {
393 $formatted = ' ';
395 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
401 function getRowAttrs( $row, $isSecond = false ){
404 if( $row->am_customised
){
405 $arr['class'] = 'allmessages-customised';
408 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
413 function getCellAttrs( $field, $value ){
414 if( $field != 'am_title' ) {
415 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir() );
416 } elseif( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ) {
417 return array( 'rowspan' => '2', 'class' => $field );
419 return array( 'class' => $field );
423 // This is not actually used, as getStartBody is overridden above
424 function getFieldNames() {
426 'am_title' => wfMsg( 'allmessagesname' ),
427 'am_default' => wfMsg( 'allmessagesdefault' )
431 function getTitle() {
432 return SpecialPage
::getTitleFor( 'Allmessages', false );
435 function isFieldSortable( $x ){
439 function getDefaultSort(){
443 function getQueryInfo(){