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;
105 function __construct( $page, $conds, $langObj = null ) {
106 parent
::__construct();
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 );
113 global $wgLang, $wgContLang, $wgRequest;
115 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
117 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
118 $this->langcode
= $this->lang
->getCode();
119 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
121 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
122 $this->custom
= null; // So won't match in either case
124 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
127 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
128 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
129 if( $prefix !== null ){
130 $this->displayPrefix
= $prefix->getDBkey();
131 $this->prefix
= '/^' . preg_quote( $this->displayPrefix
) . '/i';
133 $this->displayPrefix
= false;
134 $this->prefix
= false;
137 // The suffix that may be needed for message names if we're in a
138 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
139 if( $this->foreign
) {
140 $this->suffix
= '/' . $this->langcode
;
146 function buildForm() {
149 $languages = Language
::getLanguageNames( false );
152 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
153 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
154 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
155 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
157 <td class="mw-label">' .
158 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
160 <td class=\"mw-input\">" .
161 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
165 <td class='mw-label'>" .
166 wfMsg( 'allmessages-filter' ) .
168 <td class='mw-input'>" .
169 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
172 'mw-allmessages-form-filter-unmodified',
173 ( $this->filter
== 'unmodified' )
175 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
178 'mw-allmessages-form-filter-all',
179 ( $this->filter
== 'all' )
181 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
184 'mw-allmessages-form-filter-modified',
185 ( $this->filter
== 'modified' )
190 <td class=\"mw-label\">" .
191 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
193 <td class=\"mw-input\">" .
194 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
196 foreach( $languages as $lang => $name ) {
197 $selected = $lang == $this->langcode
;
198 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
200 $out .= Xml
::closeElement( 'select' ) .
205 <td class="mw-label">' .
206 Xml
::label( wfMsg( 'table_pager_limit_label'), 'mw-table_pager_limit_label' ) .
208 <td class="mw-input">' .
209 $this->getLimitSelect() .
214 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
218 Xml
::closeElement( 'table' ) .
219 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
220 Xml
::closeElement( 'fieldset' ) .
221 Xml
::closeElement( 'form' );
225 function getAllMessages( $descending ) {
226 wfProfileIn( __METHOD__
);
227 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
229 rsort( $messageNames );
231 asort( $messageNames );
234 // Normalise message names so they look like page titles
235 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
237 wfProfileOut( __METHOD__
);
238 return $messageNames;
242 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
243 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
244 * an entry for each existing page, with the key being the message name and
247 * @param array $messageNames
248 * @param string $langcode What language code
249 * @param bool $foreign Whether the $langcode is not the content language
251 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
252 // FIXME: This function should be moved to Language:: or something.
253 wfProfileIn( __METHOD__
. '-db' );
255 $dbr = wfGetDB( DB_SLAVE
);
256 $res = $dbr->select( 'page',
257 array( 'page_namespace', 'page_title' ),
258 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
260 array( 'USE INDEX' => 'name_title' )
262 $xNames = array_flip( $messageNames );
264 $pageFlags = $talkFlags = array();
266 foreach ( $res as $s ) {
267 if( $s->page_namespace
== NS_MEDIAWIKI
) {
269 $title = explode( '/', $s->page_title
);
270 if( count( $title ) === 2 && $langcode == $title[1]
271 && isset( $xNames[$title[0]] ) ) {
272 $pageFlags["{$title[0]}"] = true;
274 } elseif( isset( $xNames[$s->page_title
] ) ) {
275 $pageFlags[$s->page_title
] = true;
277 } elseif( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
278 $talkFlags[$s->page_title
] = true;
282 wfProfileOut( __METHOD__
. '-db' );
284 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
288 * This function normally does a database query to get the results; we need
289 * to make a pretend result using a FakeResultWrapper.
291 function reallyDoQuery( $offset, $limit, $descending ) {
292 $result = new FakeResultWrapper( array() );
294 $messageNames = $this->getAllMessages( $descending );
295 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
298 foreach( $messageNames as $key ) {
299 $customised = isset( $statuses['pages'][$key] );
300 if( $customised !== $this->custom
&&
301 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
302 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
304 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
305 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
306 $result->result
[] = array(
308 'am_actual' => $actual,
309 'am_default' => $default,
310 'am_customised' => $customised,
311 'am_talk_exists' => isset( $statuses['talks'][$key] )
315 if( $count == $limit ) {
322 function getStartBody() {
323 return Xml
::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
325 <th rowspan=\"2\">" .
326 wfMsg( 'allmessagesname' ) . "
329 wfMsg( 'allmessagesdefault' ) .
334 wfMsg( 'allmessagescurrent' ) .
336 </tr></thead><tbody>\n";
339 function formatValue( $field, $value ){
345 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
346 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
348 if( $this->mCurrentRow
->am_customised
){
349 $title = Linker
::linkKnown( $title, $wgLang->lcfirst( $value ) );
351 $title = Linker
::link(
353 $wgLang->lcfirst( $value ),
359 if ( $this->mCurrentRow
->am_talk_exists
) {
360 $talk = Linker
::linkKnown( $talk , $this->talk
);
362 $talk = Linker
::link(
370 return $title . ' (' . $talk . ')';
374 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
379 function formatRow( $row ){
380 // Do all the normal stuff
381 $s = parent
::formatRow( $row );
383 // But if there's a customised message, add that too.
384 if( $row->am_customised
){
385 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
386 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
387 if ( $formatted == '' ) {
388 $formatted = ' ';
390 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
396 function getRowAttrs( $row, $isSecond = false ){
399 if( $row->am_customised
){
400 $arr['class'] = 'allmessages-customised';
403 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
408 function getCellAttrs( $field, $value ){
409 if( $field != 'am_title' ) {
410 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir() );
411 } elseif( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ) {
412 return array( 'rowspan' => '2', 'class' => $field );
414 return array( 'class' => $field );
418 // This is not actually used, as getStartBody is overridden above
419 function getFieldNames() {
421 'am_title' => wfMsg( 'allmessagesname' ),
422 'am_default' => wfMsg( 'allmessagesdefault' )
426 function getTitle() {
427 return SpecialPage
::getTitleFor( 'Allmessages', false );
430 function isFieldSortable( $x ){
434 function getDefaultSort(){
438 function getQueryInfo(){