$out = $this->mContext->getOutput();
if ( !wfMessage( 'protect-dropdown' )->inContentLanguage()->isDisabled() ) {
+ $reasonsList = Xml::getArrayFromWikiTextList(
+ wfMessage( 'protect-dropdown' )->inContentLanguage()->text()
+ );
$out->addModules( 'mediawiki.reasonSuggest' );
$out->addJsConfigVars( [
- 'reasons' => 'protect-dropdown'
+ 'reasons' => $reasonsList
] );
}
. Xml::closeElement( 'select' );
}
+ /**
+ * Converts textual drop-down list to array
+ *
+ * @param string $list Correctly formatted text (newline delimited) to be
+ * used to generate the options.
+ * @return array
+ */
+ public static function getArrayFromWikiTextList( $list = '' ) {
+ $options = [];
+
+ foreach ( explode( "\n", $list ) as $option ) {
+ $value = trim( $option );
+ if ( $value == '' ) {
+ continue;
+ } elseif ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) {
+ // A new group is starting ...
+ $value = trim( substr( $value, 1 ) );
+ $options[] = $value;
+ } elseif ( substr( $value, 0, 2 ) == '**' ) {
+ // groupmember
+ $value = trim( substr( $value, 2 ) );
+ $options[] = $value;
+ } else {
+ // groupless reason list
+ $options[] = $value;
+ }
+ }
+ return $options;
+ }
+
/**
* Shortcut for creating fieldsets.
*
$ctx = $this->getContext();
$outputPage = $ctx->getOutput();
if ( !wfMessage( 'deletereason-dropdown' )->inContentLanguage()->isDisabled() ) {
+ $reasonsList = Xml::getArrayFromWikiTextList(
+ wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text()
+ );
$outputPage->addModules( 'mediawiki.reasonSuggest' );
$outputPage->addJsConfigVars( [
- 'reasons' => 'deletereason-dropdown'
+ 'reasons' => $reasonsList
] );
}
$useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
Hooks::run( 'ArticleConfirmDelete', [ $this, $outputPage, &$reason ] );
$user = $this->getContext()->getUser();
-
if ( $user->isAllowed( 'suppressrevision' ) ) {
$suppress = Html::openElement( 'div', [ 'id' => 'wpDeleteSuppressRow' ] ) .
Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
$suppress = '';
}
$checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $title );
-
$form = Html::openElement( 'form', [ 'method' => 'post',
'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ] ) .
Html::openElement( 'fieldset', [ 'id' => 'mw-delete-table' ] ) .
protected function getFormFields() {
global $wgBlockAllowsUTEdit;
if ( !wfMessage( 'ipbreason-dropdown' )->inContentLanguage()->isDisabled() ) {
+ $reasonsList = Xml::getArrayFromWikiTextList(
+ wfMessage( 'ipbreason-dropdown' )->inContentLanguage()->text()
+ );
$this->getOutput()->addModules( 'mediawiki.reasonSuggest' );
$this->getOutput()->addJsConfigVars( [
- 'reasons' => 'ipbreason-dropdown'
+ 'reasons' => $reasonsList
] );
}
$user = $this->getUser();
*/
( function ( mw, $ ) {
$( function () {
- var api = new mw.Api(), reasons = [];
- // These messages can be really big, so its loaded on-the-go
- api.loadMessagesIfMissing( [ mw.config.get( 'reasons' ) ] )
- .done( function () {
- // Convert from string to array, first index is unneeded
- reasons = mw.msg( mw.config.get( 'reasons' ) ).split( '\n** ' );
- reasons.splice( 0, 1 );
- } );
+ var reasons = mw.config.get( 'reasons' );
// Add relevant suggestion
$( '#mwProtect-reason, #wpReason, #mw-input-wpReason-other' ).suggestions( {