Convert Special:AllMessages to use OOUI
Moved form from pager and added new HTMLSelectLanguageField. Bug: T117749 Bug: T134425 Change-Id: I46dc6cc8f7ddf8552a726202df136cbbff66588c
This commit is contained in:
parent
c81e1506c6
commit
d0c31ac988
5 changed files with 136 additions and 112 deletions
|
|
@ -603,6 +603,7 @@ $wgAutoloadLocalClasses = [
|
|||
'HTMLRestrictionsField' => __DIR__ . '/includes/htmlform/fields/HTMLRestrictionsField.php',
|
||||
'HTMLSelectAndOtherField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectAndOtherField.php',
|
||||
'HTMLSelectField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectField.php',
|
||||
'HTMLSelectLanguageField' => __DIR__ . '/includes/htmlform/HTMLSelectLanguageField.php',
|
||||
'HTMLSelectLimitField' => __DIR__ . '/includes/htmlform/fields/HTMLSelectLimitField.php',
|
||||
'HTMLSelectNamespace' => __DIR__ . '/includes/htmlform/fields/HTMLSelectNamespace.php',
|
||||
'HTMLSelectNamespaceWithButton' => __DIR__ . '/includes/htmlform/fields/HTMLSelectNamespaceWithButton.php',
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ class HTMLForm extends ContextSource {
|
|||
'checkmatrix' => HTMLCheckMatrix::class,
|
||||
'cloner' => HTMLFormFieldCloner::class,
|
||||
'autocompleteselect' => HTMLAutoCompleteSelectField::class,
|
||||
'language' => HTMLSelectLanguageField::class,
|
||||
'date' => HTMLDateTimeField::class,
|
||||
'time' => HTMLDateTimeField::class,
|
||||
'datetime' => HTMLDateTimeField::class,
|
||||
|
|
|
|||
34
includes/htmlform/HTMLSelectLanguageField.php
Normal file
34
includes/htmlform/HTMLSelectLanguageField.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Language select field.
|
||||
*/
|
||||
class HTMLSelectLanguageField extends HTMLSelectField {
|
||||
public function __construct( $params ) {
|
||||
parent::__construct( $params );
|
||||
|
||||
if ( $this->mParent instanceof HTMLForm ) {
|
||||
$config = $this->mParent->getConfig();
|
||||
$languageCode = $config->get( 'LanguageCode' );
|
||||
} else {
|
||||
global $wgLanguageCode;
|
||||
$languageCode = $wgLanguageCode;
|
||||
}
|
||||
|
||||
$languages = Language::fetchLanguageNames( null, 'mw' );
|
||||
|
||||
// Make sure the site language is in the list;
|
||||
// a custom language code might not have a defined name…
|
||||
if ( !array_key_exists( $languageCode, $languages ) ) {
|
||||
$languages[$languageCode] = $languageCode;
|
||||
}
|
||||
|
||||
foreach ( $languages as $code => $name ) {
|
||||
$this->mParams['options'][$code . ' - ' . $name] = $code;
|
||||
}
|
||||
|
||||
if ( !array_key_exists( 'default', $params ) ) {
|
||||
$this->mParams['default'] = $languageCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
* @file
|
||||
* @ingroup SpecialPage
|
||||
*/
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Use this special page to get a list of the MediaWiki system messages.
|
||||
|
|
@ -28,10 +29,6 @@
|
|||
* @ingroup SpecialPage
|
||||
*/
|
||||
class SpecialAllMessages extends SpecialPage {
|
||||
/**
|
||||
* @var AllMessagesTablePager
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( 'Allmessages' );
|
||||
|
|
@ -43,7 +40,6 @@ class SpecialAllMessages extends SpecialPage {
|
|||
* @param string $par Parameter passed to the page or null
|
||||
*/
|
||||
public function execute( $par ) {
|
||||
$request = $this->getRequest();
|
||||
$out = $this->getOutput();
|
||||
|
||||
$this->setHeaders();
|
||||
|
|
@ -54,18 +50,77 @@ class SpecialAllMessages extends SpecialPage {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->outputHeader( 'allmessagestext' );
|
||||
$out->addModuleStyles( 'mediawiki.special' );
|
||||
$this->addHelpLink( 'Help:System message' );
|
||||
|
||||
$this->table = new AllMessagesTablePager(
|
||||
$this,
|
||||
[],
|
||||
wfGetLangObj( $request->getVal( 'lang', $par ) )
|
||||
);
|
||||
$contLang = MediaWikiServices::getInstance()->getContentLanguage()->getCode();
|
||||
$lang = $this->getLanguage();
|
||||
|
||||
$out->addHTML( $this->table->buildForm() );
|
||||
$out->addParserOutputContent( $this->table->getFullOutput() );
|
||||
$opts = new FormOptions();
|
||||
|
||||
$opts->add( 'prefix', '' );
|
||||
$opts->add( 'filter', 'all' );
|
||||
$opts->add( 'lang', $contLang );
|
||||
$opts->add( 'limit', 50 );
|
||||
|
||||
$opts->fetchValuesFromRequest( $this->getRequest() );
|
||||
$opts->validateIntBounds( 'limit', 0, 5000 );
|
||||
|
||||
$pager = new AllMessagesTablePager( $this->getContext(), $opts );
|
||||
|
||||
$formDescriptor = [
|
||||
'prefix' => [
|
||||
'type' => 'text',
|
||||
'name' => 'prefix',
|
||||
'label-message' => 'allmessages-prefix',
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'type' => 'radio',
|
||||
'name' => 'filter',
|
||||
'label-message' => 'allmessages-filter',
|
||||
'options' => [
|
||||
$this->msg( 'allmessages-filter-unmodified' )->text() => 'unmodified',
|
||||
$this->msg( 'allmessages-filter-all' )->text() => 'all',
|
||||
$this->msg( 'allmessages-filter-modified' )->text() => 'modified',
|
||||
],
|
||||
'default' => 'all',
|
||||
'flatlist' => true,
|
||||
],
|
||||
|
||||
'lang' => [
|
||||
'type' => 'language',
|
||||
'name' => 'lang',
|
||||
'label-message' => 'allmessages-language',
|
||||
'default' => $opts->getValue( 'lang' ),
|
||||
],
|
||||
|
||||
'limit' => [
|
||||
'type' => 'limitselect',
|
||||
'name' => 'limit',
|
||||
'label-message' => 'table_pager_limit_label',
|
||||
'options' => [
|
||||
$lang->formatNum( 20 ) => 20,
|
||||
$lang->formatNum( 50 ) => 50,
|
||||
$lang->formatNum( 100 ) => 100,
|
||||
$lang->formatNum( 250 ) => 250,
|
||||
$lang->formatNum( 500 ) => 500,
|
||||
$lang->formatNum( 5000 ) => 5000,
|
||||
],
|
||||
'default' => $opts->getValue( 'limit' ),
|
||||
],
|
||||
];
|
||||
|
||||
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
||||
$htmlForm
|
||||
->setMethod( 'get' )
|
||||
->setIntro( $this->msg( 'allmessagestext' ) )
|
||||
->setWrapperLegendMsg( 'allmessages' )
|
||||
->setSubmitTextMsg( 'allmessages-filter-submit' )
|
||||
->prepareForm()
|
||||
->displayForm( false );
|
||||
|
||||
$out->addParserOutputContent( $pager->getFullOutput() );
|
||||
}
|
||||
|
||||
protected function getGroupName() {
|
||||
|
|
|
|||
|
|
@ -30,9 +30,20 @@ use Wikimedia\Rdbms\FakeResultWrapper;
|
|||
*/
|
||||
class AllMessagesTablePager extends TablePager {
|
||||
|
||||
protected $filter, $prefix, $langcode, $displayPrefix;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
public $mLimitsShown;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $foreign;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* @var Language
|
||||
|
|
@ -44,41 +55,40 @@ class AllMessagesTablePager extends TablePager {
|
|||
*/
|
||||
public $custom;
|
||||
|
||||
public function __construct( $page, $conds, Language $langObj = null ) {
|
||||
parent::__construct( $page->getContext() );
|
||||
/**
|
||||
* @param IContextSource|null $context
|
||||
* @param FormOptions $opts
|
||||
*/
|
||||
public function __construct( IContextSource $context = null, FormOptions $opts ) {
|
||||
parent::__construct( $context );
|
||||
|
||||
$this->mIndexField = 'am_title';
|
||||
$this->mPage = $page;
|
||||
$this->mConds = $conds;
|
||||
// FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
|
||||
$this->mDefaultDirection = IndexPager::DIR_DESCENDING;
|
||||
$this->mLimitsShown = [ 20, 50, 100, 250, 500, 5000 ];
|
||||
|
||||
$this->talk = $this->msg( 'talkpagelinktext' )->escaped();
|
||||
|
||||
$langObj = wfGetLangObj( $opts->getValue( 'lang' ) );
|
||||
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
||||
$this->lang = $langObj ?? $contLang;
|
||||
|
||||
$this->langcode = $this->lang->getCode();
|
||||
$this->foreign = !$this->lang->equals( $contLang );
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$this->filter = $request->getVal( 'filter', 'all' );
|
||||
if ( $this->filter === 'all' ) {
|
||||
$filter = $opts->getValue( 'filter' );
|
||||
if ( $filter === 'all' ) {
|
||||
$this->custom = null; // So won't match in either case
|
||||
} else {
|
||||
$this->custom = ( $this->filter === 'unmodified' );
|
||||
$this->custom = ( $filter === 'unmodified' );
|
||||
}
|
||||
|
||||
$prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
|
||||
$prefix = $this->getLanguage()->ucfirst( $opts->getValue( 'prefix' ) );
|
||||
$prefix = $prefix !== '' ?
|
||||
Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) :
|
||||
Title::makeTitleSafe( NS_MEDIAWIKI, $opts->getValue( 'prefix' ) ) :
|
||||
null;
|
||||
|
||||
if ( $prefix !== null ) {
|
||||
$this->displayPrefix = $prefix->getDBkey();
|
||||
$this->prefix = '/^' . preg_quote( $this->displayPrefix, '/' ) . '/i';
|
||||
$displayPrefix = $prefix->getDBkey();
|
||||
$this->prefix = '/^' . preg_quote( $displayPrefix, '/' ) . '/i';
|
||||
} else {
|
||||
$this->displayPrefix = false;
|
||||
$this->prefix = false;
|
||||
}
|
||||
|
||||
|
|
@ -91,84 +101,6 @@ class AllMessagesTablePager extends TablePager {
|
|||
}
|
||||
}
|
||||
|
||||
function buildForm() {
|
||||
$attrs = [ 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ];
|
||||
$msg = wfMessage( 'allmessages-language' );
|
||||
$langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg );
|
||||
|
||||
$out = Xml::openElement( 'form', [
|
||||
'method' => 'get',
|
||||
'action' => $this->getConfig()->get( 'Script' ),
|
||||
'id' => 'mw-allmessages-form'
|
||||
] ) .
|
||||
Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
|
||||
Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
|
||||
Xml::openElement( 'table', [ 'class' => 'mw-allmessages-table' ] ) . "\n" .
|
||||
'<tr>
|
||||
<td class="mw-label">' .
|
||||
Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
|
||||
"</td>\n
|
||||
<td class=\"mw-input\">" .
|
||||
Xml::input(
|
||||
'prefix',
|
||||
20,
|
||||
str_replace( '_', ' ', $this->displayPrefix ),
|
||||
[ 'id' => 'mw-allmessages-form-prefix' ]
|
||||
) .
|
||||
"</td>\n
|
||||
</tr>
|
||||
<tr>\n
|
||||
<td class='mw-label'>" .
|
||||
$this->msg( 'allmessages-filter' )->escaped() .
|
||||
"</td>\n
|
||||
<td class='mw-input'>" .
|
||||
Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
|
||||
'filter',
|
||||
'unmodified',
|
||||
'mw-allmessages-form-filter-unmodified',
|
||||
( $this->filter === 'unmodified' )
|
||||
) .
|
||||
Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
|
||||
'filter',
|
||||
'all',
|
||||
'mw-allmessages-form-filter-all',
|
||||
( $this->filter === 'all' )
|
||||
) .
|
||||
Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
|
||||
'filter',
|
||||
'modified',
|
||||
'mw-allmessages-form-filter-modified',
|
||||
( $this->filter === 'modified' )
|
||||
) .
|
||||
"</td>\n
|
||||
</tr>
|
||||
<tr>\n
|
||||
<td class=\"mw-label\">" . $langSelect[0] . "</td>\n
|
||||
<td class=\"mw-input\">" . $langSelect[1] . "</td>\n
|
||||
</tr>" .
|
||||
|
||||
'<tr>
|
||||
<td class="mw-label">' .
|
||||
Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
|
||||
'</td>
|
||||
<td class="mw-input">' .
|
||||
$this->getLimitSelect( [ 'id' => 'mw-table_pager_limit_label' ] ) .
|
||||
'</td>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>' .
|
||||
Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
|
||||
"</td>\n
|
||||
</tr>" .
|
||||
|
||||
Xml::closeElement( 'table' ) .
|
||||
$this->getHiddenFields( [ 'title', 'prefix', 'filter', 'lang', 'limit' ] ) .
|
||||
Xml::closeElement( 'fieldset' ) .
|
||||
Xml::closeElement( 'form' );
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
function getAllMessages( $descending ) {
|
||||
$messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
|
||||
|
||||
|
|
@ -318,6 +250,7 @@ class AllMessagesTablePager extends TablePager {
|
|||
] ),
|
||||
$this->msg( 'allmessages-filter-translate' )->text()
|
||||
);
|
||||
$talkLink = $this->msg( 'talkpagelinktext' )->escaped();
|
||||
|
||||
if ( $this->mCurrentRow->am_customised ) {
|
||||
$title = $linkRenderer->makeKnownLink( $title, $this->getLanguage()->lcfirst( $value ) );
|
||||
|
|
@ -328,11 +261,11 @@ class AllMessagesTablePager extends TablePager {
|
|||
);
|
||||
}
|
||||
if ( $this->mCurrentRow->am_talk_exists ) {
|
||||
$talk = $linkRenderer->makeKnownLink( $talk, $this->talk );
|
||||
$talk = $linkRenderer->makeKnownLink( $talk, $talkLink );
|
||||
} else {
|
||||
$talk = $linkRenderer->makeBrokenLink(
|
||||
$talk,
|
||||
$this->talk
|
||||
$talkLink
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue