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