Merge "Add semantic tags to license info text"
[lhc/web/wiklou.git] / includes / editpage / TextboxBuilder.php
index a6ae9bc..d0a2f8f 100644 (file)
@@ -24,6 +24,7 @@
 
 namespace MediaWiki\EditPage;
 
+use MWNamespace;
 use Title;
 use User;
 
@@ -50,6 +51,49 @@ class TextboxBuilder {
                return $wikitext;
        }
 
+       /**
+        * @param string[] $classes
+        * @param mixed[] $attribs
+        * @return mixed[]
+        */
+       public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
+               if ( !count( $classes ) ) {
+                       return $attribs;
+               }
+
+               if ( isset( $attribs['class'] ) ) {
+                       $classes[] = $attribs['class'];
+               }
+               $attribs['class'] = implode( ' ', $classes );
+
+               return $attribs;
+       }
+
+       /**
+        * @param Title $title
+        * @return string[]
+        */
+       public function getTextboxProtectionCSSClasses( Title $title ) {
+               $classes = []; // Textarea CSS
+               if ( $title->isProtected( 'edit' ) &&
+                       MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ]
+               ) {
+                       # Is the title semi-protected?
+                       if ( $title->isSemiProtected() ) {
+                               $classes[] = 'mw-textarea-sprotected';
+                       } else {
+                               # Then it must be protected based on static groups (regular)
+                               $classes[] = 'mw-textarea-protected';
+                       }
+                       # Is the title cascade-protected?
+                       if ( $title->isCascadeProtected() ) {
+                               $classes[] = 'mw-textarea-cprotected';
+                       }
+               }
+
+               return $classes;
+       }
+
        /**
         * @param string $name
         * @param mixed[] $customAttribs