Improved parsing in reason suggests
Bug: T155086 Change-Id: I3a3167b7bfd9b5921df1cf3e4a3cf3e1da4ca001
This commit is contained in:
parent
a2551692e7
commit
8c7095be85
5 changed files with 43 additions and 13 deletions
|
|
@ -184,9 +184,12 @@ class ProtectionForm {
|
|||
|
||||
$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
|
||||
] );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -563,6 +563,36 @@ class Xml {
|
|||
. 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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1674,9 +1674,12 @@ class Article implements Page {
|
|||
$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' );
|
||||
|
|
@ -1693,7 +1696,6 @@ class Article implements Page {
|
|||
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(),
|
||||
|
|
@ -1703,7 +1705,6 @@ class Article implements Page {
|
|||
$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' ] ) .
|
||||
|
|
|
|||
|
|
@ -128,9 +128,12 @@ class SpecialBlock extends FormSpecialPage {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -3,14 +3,7 @@
|
|||
*/
|
||||
( 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( {
|
||||
|
|
|
|||
Loading…
Reference in a new issue