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;
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->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
137 $this->prefix
= false;
141 // The suffix that may be needed for message names if we're in a
142 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
143 if( $this->foreign
) {
144 $this->suffix
= '/' . $this->langcode
;
150 function buildForm() {
153 $languages = Language
::getLanguageNames( false );
156 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
157 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
158 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
159 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
161 <td class="mw-label">' .
162 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
164 <td class=\"mw-input\">" .
165 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
169 <td class='mw-label'>" .
170 wfMsg( 'allmessages-filter' ) .
172 <td class='mw-input'>" .
173 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
176 'mw-allmessages-form-filter-unmodified',
177 ( $this->filter
== 'unmodified' )
179 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
182 'mw-allmessages-form-filter-all',
183 ( $this->filter
== 'all' )
185 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
188 'mw-allmessages-form-filter-modified',
189 ( $this->filter
== 'modified' )
194 <td class=\"mw-label\">" .
195 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
197 <td class=\"mw-input\">" .
198 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
200 foreach( $languages as $lang => $name ) {
201 $selected = $lang == $this->langcode
;
202 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
204 $out .= Xml
::closeElement( 'select' ) .
209 <td class="mw-label">' .
210 Xml
::label( wfMsg( 'table_pager_limit_label'), 'mw-table_pager_limit_label' ) .
212 <td class="mw-input">' .
213 $this->getLimitSelect() .
218 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
222 Xml
::closeElement( 'table' ) .
223 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) .
224 Xml
::closeElement( 'fieldset' ) .
225 Xml
::closeElement( 'form' );
229 function getAllMessages( $descending ) {
230 wfProfileIn( __METHOD__
);
231 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
233 rsort( $messageNames );
235 asort( $messageNames );
238 // Normalise message names so they look like page titles
239 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
241 wfProfileOut( __METHOD__
);
242 return $messageNames;
246 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
247 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
248 * an entry for each existing page, with the key being the message name and
251 * @param array $messageNames
252 * @param string $langcode What language code
253 * @param bool $foreign Whether the $langcode is not the content language
255 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
256 wfProfileIn( __METHOD__
. '-db' );
258 $dbr = wfGetDB( DB_SLAVE
);
259 $res = $dbr->select( 'page',
260 array( 'page_namespace', 'page_title' ),
261 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
263 array( 'USE INDEX' => 'name_title' )
265 $xNames = array_flip( $messageNames );
267 $pageFlags = $talkFlags = array();
269 foreach ( $res as $s ) {
270 if( $s->page_namespace
== NS_MEDIAWIKI
) {
272 $title = explode( '/', $s->page_title
);
273 if( count( $title ) === 2 && $langcode == $title[1]
274 && isset( $xNames[$title[0]] ) ) {
275 $pageFlags["{$title[0]}"] = true;
277 } elseif( isset( $xNames[$s->page_title
] ) ) {
278 $pageFlags[$s->page_title
] = true;
280 } elseif( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
281 $talkFlags[$s->page_title
] = true;
285 wfProfileOut( __METHOD__
. '-db' );
287 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
291 * This function normally does a database query to get the results; we need
292 * to make a pretend result using a FakeResultWrapper.
294 function reallyDoQuery( $offset, $limit, $descending ) {
295 $result = new FakeResultWrapper( array() );
297 $messageNames = $this->getAllMessages( $descending );
298 $statuses = self
::getCustomisedStatuses( $messageNames, $this->langcode
, $this->foreign
);
301 foreach( $messageNames as $key ) {
302 $customised = isset( $statuses['pages'][$key] );
303 if( $customised !== $this->custom
&&
304 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
305 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
307 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
308 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
309 $result->result
[] = array(
311 'am_actual' => $actual,
312 'am_default' => $default,
313 'am_customised' => $customised,
314 'am_talk_exists' => isset( $statuses['talks'][$key] )
318 if( $count == $limit ) {
325 function getStartBody() {
326 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
328 <th rowspan=\"2\">" .
329 wfMsg( 'allmessagesname' ) . "
332 wfMsg( 'allmessagesdefault' ) .
337 wfMsg( 'allmessagescurrent' ) .
339 </tr></thead><tbody>\n";
342 function formatValue( $field, $value ){
348 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
349 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
351 if( $this->mCurrentRow
->am_customised
){
352 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
354 $title = $this->mSkin
->link(
356 $wgLang->lcfirst( $value ),
362 if ( $this->mCurrentRow
->am_talk_exists
) {
363 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
365 $talk = $this->mSkin
->link(
373 return $title . ' (' . $talk . ')';
377 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
382 function formatRow( $row ){
383 // Do all the normal stuff
384 $s = parent
::formatRow( $row );
386 // But if there's a customised message, add that too.
387 if( $row->am_customised
){
388 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
389 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
390 if ( $formatted == '' ) {
391 $formatted = ' ';
393 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
399 function getRowAttrs( $row, $isSecond = false ){
402 if( $row->am_customised
){
403 $arr['class'] = 'allmessages-customised';
406 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
411 function getCellAttrs( $field, $value ){
412 global $wgBetterDirectionality;
413 if( $field != 'am_title' && $wgBetterDirectionality ) {
414 return array( 'lang' => $this->langcode
, 'dir' => $this->lang
->getDir() );
415 } elseif( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ) {
416 return array( 'rowspan' => '2', 'class' => $field );
418 return array( 'class' => $field );
422 // This is not actually used, as getStartBody is overridden above
423 function getFieldNames() {
425 'am_title' => wfMsg( 'allmessagesname' ),
426 'am_default' => wfMsg( 'allmessagesdefault' )
430 function getTitle() {
431 return SpecialPage
::getTitleFor( 'Allmessages', false );
434 function isFieldSortable( $x ){
438 function getDefaultSort(){
442 function getQueryInfo(){