MediaWiki REL1_35
TextboxBuilder.php
Go to the documentation of this file.
1<?php
25namespace MediaWiki\EditPage;
26
28use Sanitizer;
29use Title;
30use User;
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, User $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 $class = 'mw-editfont-' . $user->getOption( 'editfont' );
120
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;
126 }
127 } else {
128 $attribs['class'] = $class;
129 }
130
131 $pageLang = $title->getPageLanguage();
132 $attribs['lang'] = $pageLang->getHtmlCode();
133 $attribs['dir'] = $pageLang->getDir();
134
135 return $attribs;
136 }
137
138}
Helps EditPage build textboxes.
mergeClassesIntoAttributes(array $classes, array $attribs)
buildTextboxAttribs( $name, array $customAttribs, User $user, Title $title)
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:33
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition User.php:2665