Add class name to protected pages, to allow for specific CSS styling of edit area

Also get rid of checking for NS_MEDIAWIKI explictly and use
MWNamespace::getRestrictionLevels instead

Bug: 50783
Change-Id: I5986ddb9b6f17e4a2aca12dbb551cce4a6cfd663
This commit is contained in:
Krenair 2014-04-30 20:28:29 +01:00 committed by Roan Kattouw
parent 43c0341ad3
commit f8d609a8c7
2 changed files with 13 additions and 2 deletions

View file

@ -330,13 +330,19 @@ class ApiVisualEditor extends ApiBase {
}
}
if ( $page->getNamespace() != NS_MEDIAWIKI ) {
// Look at protection status to set up notices + surface class(es)
$protectedClasses = array();
if ( MWNamespace::getRestrictionLevels( $page->getNamespace() ) !== array( '' ) ) {
// Page protected from editing
if ( $page->isProtected( 'edit' ) ) {
# Is the title semi-protected?
if ( $page->isSemiProtected() ) {
$protectedClasses[] = 'mw-textarea-sprotected';
$noticeMsg = 'semiprotectedpagewarning';
} else {
$protectedClasses[] = 'mw-textarea-protected';
# Then it must be protected based on static groups (regular)
$noticeMsg = 'protectedpagewarning';
}
@ -347,6 +353,8 @@ class ApiVisualEditor extends ApiBase {
// Deal with cascading edit protection
list( $sources, $restrictions ) = $page->getCascadeProtectionSources();
if ( isset( $restrictions['edit'] ) ) {
$protectedClasses[] = ' mw-textarea-cprotected';
$notice = $this->msg( 'cascadeprotectedwarning' )->parseAsBlock() . '<ul>';
// Unfortunately there's no nice way to get only the pages which cause
// editing to be restricted
@ -439,6 +447,7 @@ class ApiVisualEditor extends ApiBase {
'notices' => $notices,
'checkboxes' => $checkboxes,
'links' => $links,
'protectedClasses' => implode( ' ', $protectedClasses )
),
$parsed['result']
);

View file

@ -394,6 +394,7 @@ ve.init.mw.Target.onLoad = function ( response ) {
this.constructor.static.fixBase( this.doc, document );
this.remoteNotices = ve.getObjectValues( data.notices );
this.protectedClasses = data.protectedClasses;
this.$checkboxes = $( ve.getObjectValues( data.checkboxes ).join( '' ) );
// Populate checkboxes with default values for minor and watch
this.$checkboxes
@ -1311,7 +1312,8 @@ ve.init.mw.Target.prototype.setUpSurface = function ( doc, callback ) {
setTimeout( function () {
// Create ui.Surface (also creates ce.Surface and dm.Surface and builds CE tree)
target.surface = target.createSurface( dmDoc );
target.surface.$element.addClass( 've-init-mw-viewPageTarget-surface' );
target.surface.$element.addClass( 've-init-mw-viewPageTarget-surface' )
.addClass( target.protectedClasses );
setTimeout( function () {
// Initialize surface
target.surface.getContext().hide();