3 * Helps EditPage build textboxes
5 * (C) Copyright 2017 Kunal Mehta <legoktm@member.fsf.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
25 namespace MediaWiki\EditPage
;
32 * Helps EditPage build textboxes
36 class TextboxBuilder
{
39 * @param string $wikitext
42 public function addNewLineAtEnd( $wikitext ) {
43 if ( strval( $wikitext ) !== '' ) {
44 // Ensure there's a newline at the end, otherwise adding lines
46 // But don't add a newline if the text is empty, or Firefox in XHTML
47 // mode will show an extra newline. A bit annoying.
55 * @param string[] $classes
56 * @param mixed[] $attribs
59 public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
60 if ( !count( $classes ) ) {
64 if ( isset( $attribs['class'] ) ) {
65 $classes[] = $attribs['class'];
67 $attribs['class'] = implode( ' ', $classes );
76 public function getTextboxProtectionCSSClasses( Title
$title ) {
77 $classes = []; // Textarea CSS
78 if ( $title->isProtected( 'edit' ) &&
79 MWNamespace
::getRestrictionLevels( $title->getNamespace() ) !== [ '' ]
81 # Is the title semi-protected?
82 if ( $title->isSemiProtected() ) {
83 $classes[] = 'mw-textarea-sprotected';
85 # Then it must be protected based on static groups (regular)
86 $classes[] = 'mw-textarea-protected';
88 # Is the title cascade-protected?
89 if ( $title->isCascadeProtected() ) {
90 $classes[] = 'mw-textarea-cprotected';
99 * @param mixed[] $customAttribs
101 * @param Title $title
104 public function buildTextboxAttribs( $name, array $customAttribs, User
$user, Title
$title ) {
105 $attribs = $customAttribs +
[
110 // Avoid PHP notices when appending preferences
111 // (appending allows customAttribs['style'] to still work).
115 // The following classes can be used here:
116 // * mw-editfont-monospace
117 // * mw-editfont-sans-serif
118 // * mw-editfont-serif
119 $class = 'mw-editfont-' . $user->getOption( 'editfont' );
121 if ( isset( $attribs['class'] ) ) {
122 if ( is_string( $attribs['class'] ) ) {
123 $attribs['class'] .= ' ' . $class;
124 } elseif ( is_array( $attribs['class'] ) ) {
125 $attribs['class'][] = $class;
128 $attribs['class'] = $class;
131 $pageLang = $title->getPageLanguage();
132 $attribs['lang'] = $pageLang->getHtmlCode();
133 $attribs['dir'] = $pageLang->getDir();