MediaWiki REL1_37
TextboxBuilder.php
Go to the documentation of this file.
1<?php
25namespace MediaWiki\EditPage;
26
29use Sanitizer;
30use Title;
31
38
43 public function addNewLineAtEnd( $wikitext ) {
44 if ( strval( $wikitext ) !== '' ) {
45 // Ensure there's a newline at the end, otherwise adding lines
46 // is awkward.
47 // But don't add a newline if the text is empty, or Firefox in XHTML
48 // mode will show an extra newline. A bit annoying.
49 $wikitext .= "\n";
50 return $wikitext;
51 }
52 return $wikitext;
53 }
54
60 public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
61 if ( $classes === [] ) {
62 return $attribs;
63 }
64
65 return Sanitizer::mergeAttributes(
66 $attribs,
67 [ 'class' => implode( ' ', $classes ) ]
68 );
69 }
70
76 $classes = []; // Textarea CSS
77 if ( $title->isProtected( 'edit' ) &&
78 MediaWikiServices::getInstance()->getPermissionManager()
79 ->getNamespaceRestrictionLevels( $title->getNamespace() ) !== [ '' ]
80 ) {
81 # Is the title semi-protected?
82 if ( $title->isSemiProtected() ) {
83 $classes[] = 'mw-textarea-sprotected';
84 } else {
85 # Then it must be protected based on static groups (regular)
86 $classes[] = 'mw-textarea-protected';
87 }
88 # Is the title cascade-protected?
89 if ( $title->isCascadeProtected() ) {
90 $classes[] = 'mw-textarea-cprotected';
91 }
92 }
93
94 return $classes;
95 }
96
104 public function buildTextboxAttribs( $name, array $customAttribs, UserIdentity $user, Title $title ) {
105 $attribs = $customAttribs + [
106 'accesskey' => ',',
107 'id' => $name,
108 'cols' => 80,
109 'rows' => 25,
110 // Avoid PHP notices when appending preferences
111 // (appending allows customAttribs['style'] to still work).
112 'style' => ''
113 ];
114
115 // The following classes can be used here:
116 // * mw-editfont-monospace
117 // * mw-editfont-sans-serif
118 // * mw-editfont-serif
119 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
120 $class = 'mw-editfont-' . $userOptionsLookup->getOption( $user, 'editfont' );
121
122 if ( isset( $attribs['class'] ) ) {
123 if ( is_string( $attribs['class'] ) ) {
124 $attribs['class'] .= ' ' . $class;
125 } elseif ( is_array( $attribs['class'] ) ) {
126 $attribs['class'][] = $class;
127 }
128 } else {
129 $attribs['class'] = $class;
130 }
131
132 $pageLang = $title->getPageLanguage();
133 $attribs['lang'] = $pageLang->getHtmlCode();
134 $attribs['dir'] = $pageLang->getDir();
135
136 return $attribs;
137 }
138
139}
UserOptionsLookup $userOptionsLookup
Helps EditPage build textboxes.
buildTextboxAttribs( $name, array $customAttribs, UserIdentity $user, Title $title)
mergeClassesIntoAttributes(array $classes, array $attribs)
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:35
Represents a title within MediaWiki.
Definition Title.php:48
Interface for objects representing user identity.