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 Xml
::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 // We want to have an option for people to view *all* the messages,
161 // so they can use Ctrl+F to search them. 5000 is the maximum that
162 // will get through WebRequest::getLimitOffset().
163 $this->mLimitsShown
= array( 20, 50, 100, 250, 500, 5000 );
165 global $wgLang, $wgContLang, $wgRequest;
167 $this->talk
= htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
169 $this->lang
= ( $langObj ?
$langObj : $wgContLang );
170 $this->langcode
= $this->lang
->getCode();
171 $this->foreign
= $this->langcode
!= $wgContLang->getCode();
173 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
174 $this->custom
= null; // So won't match in either case
176 $this->custom
= ($wgRequest->getVal( 'filter' ) == 'unmodified');
179 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
180 $prefix = $prefix != '' ? Title
::makeTitleSafe( NS_MEDIAWIKI
, $wgRequest->getVal( 'prefix', null ) ) : null;
181 if( $prefix !== null ){
182 $this->prefix
= '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
184 $this->prefix
= false;
188 // The suffix that may be needed for message names if we're in a
189 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
190 if( $this->foreign
) {
191 $this->suffix
= '/' . $this->langcode
;
197 function getAllMessages( $descending ) {
198 wfProfileIn( __METHOD__
);
199 $messageNames = Language
::getLocalisationCache()->getSubitemList( 'en', 'messages' );
201 rsort( $messageNames );
203 asort( $messageNames );
206 // Normalise message names so they look like page titles
207 $messageNames = array_map( array( $this->lang
, 'ucfirst' ), $messageNames );
208 wfProfileIn( __METHOD__
);
210 return $messageNames;
214 * Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
215 * Returns array( 'pages' => ..., 'talks' => ... ), where the subarrays have
216 * an entry for each existing page, with the key being the message name and
219 function getCustomisedStatuses( $messageNames ) {
220 wfProfileIn( __METHOD__
. '-db' );
222 $dbr = wfGetDB( DB_SLAVE
);
223 $res = $dbr->select( 'page',
224 array( 'page_namespace', 'page_title' ),
225 array( 'page_namespace' => array( NS_MEDIAWIKI
, NS_MEDIAWIKI_TALK
) ),
227 array( 'USE INDEX' => 'name_title' )
229 $xNames = array_flip( $messageNames );
231 $pageFlags = $talkFlags = array();
233 while( $s = $dbr->fetchObject( $res ) ) {
234 if( $s->page_namespace
== NS_MEDIAWIKI
) {
235 if( $this->foreign
) {
236 $title = explode( '/', $s->page_title
);
237 if( count( $title ) === 2 && $this->langcode
== $title[1]
238 && isset( $xNames[$title[0]] ) )
240 $pageFlags["{$title[0]}"] = true;
242 } elseif( isset( $xNames[$s->page_title
] ) ) {
243 $pageFlags[$s->page_title
] = true;
245 } else if( $s->page_namespace
== NS_MEDIAWIKI_TALK
){
246 $talkFlags[$s->page_title
] = true;
250 wfProfileOut( __METHOD__
. '-db' );
252 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
255 /* This function normally does a database query to get the results; we need
256 * to make a pretend result using a FakeResultWrapper.
258 function reallyDoQuery( $offset, $limit, $descending ) {
259 $result = new FakeResultWrapper( array() );
261 $messageNames = $this->getAllMessages( $descending );
262 $statuses = $this->getCustomisedStatuses( $messageNames );
265 foreach( $messageNames as $key ) {
266 $customised = isset( $statuses['pages'][$key] );
267 if( $customised !== $this->custom
&&
268 ( $descending && ( $key < $offset ||
!$offset ) ||
!$descending && $key > $offset ) &&
269 ( ( $this->prefix
&& preg_match( $this->prefix
, $key ) ) ||
$this->prefix
=== false )
271 $result->result
[] = array(
273 'am_actual' => wfMsgGetKey( $key, /*useDB*/true, $this->langcode
, false ),
274 'am_default' => wfMsgGetKey( $key, /*useDB*/false, $this->langcode
, false ),
275 'am_customised' => $customised,
276 'am_talk_exists' => isset( $statuses['talks'][$key] )
280 if( $count == $limit ) break;
285 function getStartBody() {
286 return Xml
::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
288 <th rowspan=\"2\">" .
289 wfMsg( 'allmessagesname' ) . "
292 wfMsg( 'allmessagesdefault' ) .
297 wfMsg( 'allmessagescurrent' ) .
299 </tr></thead><tbody>\n";
302 function formatValue( $field, $value ){
308 $title = Title
::makeTitle( NS_MEDIAWIKI
, $value . $this->suffix
);
309 $talk = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $value . $this->suffix
);
311 if( $this->mCurrentRow
->am_customised
){
312 $title = $this->mSkin
->linkKnown( $title, $wgLang->lcfirst( $value ) );
314 $title = $this->mSkin
->link(
316 $wgLang->lcfirst( $value ),
322 if ( $this->mCurrentRow
->am_talk_exists
) {
323 $talk = $this->mSkin
->linkKnown( $talk , $this->talk
);
325 $talk = $this->mSkin
->link(
333 return $title . ' (' . $talk . ')';
336 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
338 return Sanitizer
::escapeHtmlAllowEntities( $value, ENT_QUOTES
);
343 function formatRow( $row ){
344 // Do all the normal stuff
345 $s = parent
::formatRow( $row );
347 // But if there's a customised message, add that too.
348 if( $row->am_customised
){
349 $s .= Xml
::openElement( 'tr', $this->getRowAttrs( $row, true ) );
350 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual
) );
351 if ( $formatted == '' ) {
352 $formatted = ' ';
354 $s .= Xml
::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual
), $formatted )
360 function getRowAttrs( $row, $isSecond = false ){
363 if( $row->am_customised
){
364 $arr['class'] = 'allmessages-customised';
367 $arr['id'] = Sanitizer
::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title
) );
372 function getCellAttrs( $field, $value ){
373 if( $this->mCurrentRow
->am_customised
&& $field == 'am_title' ){
374 return array( 'rowspan' => '2', 'class' => $field );
376 return array( 'class' => $field );
380 // This is not actually used, as getStartBody is overridden above
381 function getFieldNames() {
383 'am_title' => wfMsg( 'allmessagesname' ),
384 'am_default' => wfMsg( 'allmessagesdefault' )
387 function getTitle() {
388 return SpecialPage
::getTitleFor( 'Allmessages', false );
390 function isFieldSortable( $x ){
393 function getDefaultSort(){
396 function getQueryInfo(){