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
{
35 public function __construct() {
36 parent
::__construct( 'Allmessages' );
40 * Show the special page
42 * @param $par Mixed: parameter passed to the page or null
44 public function execute( $par ) {
45 global $wgOut, $wgRequest;
49 global $wgUseDatabaseMessages;
50 if( !$wgUseDatabaseMessages ) {
51 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
54 $this->outputHeader( 'allmessagestext' );
57 $this->filter
= $wgRequest->getVal( 'filter', 'all' );
58 $this->prefix
= $wgRequest->getVal( 'prefix', '' );
60 $this->table
= new AllmessagesTablePager(
63 wfGetLangObj( $wgRequest->getVal( 'lang', $par ) )
66 $this->langCode
= $this->table
->lang
->getCode();
68 $wgOut->addHTML( $this->buildForm() .
69 $this->table
->getNavigationBar() .
70 $this->table
->getLimitForm() .
71 $this->table
->getBody() .
72 $this->table
->getNavigationBar() );
76 function buildForm() {
79 $languages = Language
::getLanguageNames( false );
82 $out = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
83 Xml
::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
84 Html
::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
85 Xml
::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
87 <td class="mw-label">' .
88 Xml
::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
90 <td class=\"mw-input\">" .
91 Xml
::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix
), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
95 <td class='mw-label'>" .
96 wfMsg( 'allmessages-filter' ) .
98 <td class='mw-input'>" .
99 Xml
::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
102 'mw-allmessages-form-filter-unmodified',
103 ( $this->filter
== 'unmodified' )
105 Xml
::radioLabel( wfMsg( 'allmessages-filter-all' ),
108 'mw-allmessages-form-filter-all',
109 ( $this->filter
== 'all' )
111 Xml
::radioLabel( wfMsg( 'allmessages-filter-modified' ),
114 'mw-allmessages-form-filter-modified',
115 ( $this->filter
== 'modified' )
120 <td class=\"mw-label\">" .
121 Xml
::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
123 <td class=\"mw-input\">" .
124 Xml
::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
126 foreach( $languages as $lang => $name ) {
127 $selected = $lang == $this->langCode
;
128 $out .= Xml
::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
130 $out .= Xml
::closeElement( 'select' ) .
136 Xml
::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
139 Xml
::closeElement( 'table' ) .
140 $this->table
->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
141 Xml
::closeElement( 'fieldset' ) .
142 Xml
::closeElement( 'form' );
147 /* use TablePager for prettified output. We have to pretend that we're
148 * getting data from a table when in fact not all of it comes from the database.
150 class AllmessagesTablePager
extends TablePager
{
152 public $mLimitsShown;
154 function __construct( $page, $conds, $langObj = null ) {
155 parent
::__construct();
156 $this->mIndexField
= 'am_title';
157 $this->mPage
= $page;
158 $this->mConds
= $conds;
159 $this->mDefaultDirection
= true; // always sort ascending
160 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
162 global $wgLang, $wgContLang, $wgRequest;
164 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
166 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
167 $this->langcode
= $this->lang
->getCode();
168 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
170 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
171 $this->custom
= null; // So won't match in either case
173 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
176 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
177 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
178 if( $prefix !== null ){
179 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
181 $this->prefix
= false;
185 // The suffix that may be needed for message names if we're in a
186 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
187 if( $this->foreign
) {
188 $this->suffix
= '/' . $this->langcode
;
194 function getAllMessages( $descending ) {
195 wfProfileIn( __METHOD__
);
196 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
198 rsort( $messageNames );
200 asort( $messageNames );
203 // Normalise message names so they look like page titles
204 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
206 wfProfileOut( __METHOD__
);
207 return $messageNames;
211 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
212 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
213 * an entry for each existing page, with the key being the message name and
216 function getCustomisedStatuses( $messageNames ) {
217 wfProfileIn( __METHOD__
. '-db' );
219 $dbr = wfGetDB( DB_SLAVE
);
220 $res = $dbr->select( 'page',
221 array( 'page_namespace', 'page_title' ),
222 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
224 array( 'USE INDEX' => 'name_title' )
226 $xNames = array_flip( $messageNames );
228 $pageFlags = $talkFlags = array();
230 foreach ( $res as $s ) {
231 if( $s->page_namespace
== NS_MEDIAWIKI
) {
232 if( $this->foreign
) {
233 $title = explode( '/', $s->page_title
);
234 if( count( $title ) === 2 && $this->langcode
== $title[1]
235 && isset( $xNames[$title[0]] ) )
237 $pageFlags["{$title[0]}"] = true;
239 } elseif( isset( $xNames[$s->page_title
] ) ) {
240 $pageFlags[$s->page_title
] = true;
242 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
243 $talkFlags[$s->page_title
] = true;
247 wfProfileOut( __METHOD__
. '-db' );
249 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
252 /* This function normally does a database query to get the results; we need
253 * to make a pretend result using a FakeResultWrapper.
255 function reallyDoQuery( $offset, $limit, $descending ) {
256 $result = new FakeResultWrapper( array() );
258 $messageNames = $this->getAllMessages( $descending );
259 $statuses = $this->getCustomisedStatuses( $messageNames );
262 foreach( $messageNames as $key ) {
263 $customised = isset( $statuses['pages'][$key] );
264 if( $customised !== $this->custom
&&
265 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
266 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
268 $actual = wfMessage( $key )->inLanguage( $this->langcode
)->plain();
269 $default = wfMessage( $key )->inLanguage( $this->langcode
)->useDatabase( false )->plain();
270 $result->result
[] = array(
272 'am_actual' => $actual,
273 'am_default' => $default,
274 'am_customised' => $customised,
275 'am_talk_exists' => isset( $statuses['talks'][$key] )
279 if( $count == $limit ) break;
284 function getStartBody() {
285 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
287 <th rowspan=\"2\">" .
288 wfMsg( 'allmessagesname' ) . "
291 wfMsg( 'allmessagesdefault' ) .
296 wfMsg( 'allmessagescurrent' ) .
298 </tr></thead><tbody>\n";
301 function formatValue( $field, $value ){
307 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
308 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
310 if( $this->mCurrentRow
->am_customised
){
311 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
313 $title = $this->mSkin
->link(
315 $wgLang->lcfirst( $value ),
321 if ( $this->mCurrentRow
->am_talk_exists
) {
322 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
324 $talk = $this->mSkin
->link(
332 return $title . ' (' . $talk . ')';
336 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
341 function formatRow( $row ){
342 // Do all the normal stuff
343 $s = parent
::formatRow( $row );
345 // But if there's a customised message, add that too.
346 if( $row->am_customised
){
347 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
348 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
349 if ( $formatted == '' ) {
350 $formatted = ' ';
352 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
358 function getRowAttrs( $row, $isSecond = false ){
361 if( $row->am_customised
){
362 $arr['class'] = 'allmessages-customised';
365 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
370 function getCellAttrs( $field, $value ){
371 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
372 return array( 'rowspan' => '2', 'class' => $field );
374 return array( 'class' => $field );
378 // This is not actually used, as getStartBody is overridden above
379 function getFieldNames() {
381 'am_title' => wfMsg( 'allmessagesname' ),
382 'am_default' => wfMsg( 'allmessagesdefault' )
385 function getTitle() {
386 return SpecialPage
::getTitleFor( 'Allmessages', false );
388 function isFieldSortable( $x ){
391 function getDefaultSort(){
394 function getQueryInfo(){