MediaWiki master
TextboxBuilder.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\EditPage;
22
29
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 return $wikitext . "\n";
50 }
51 return $wikitext;
52 }
53
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
78 if ( $services->getRestrictionStore()->isProtected( $page, 'edit' ) &&
79 $services->getPermissionManager()
80 ->getNamespaceRestrictionLevels( $page->getNamespace() ) !== [ '' ]
81 ) {
82 # Is the title semi-protected?
83 if ( $services->getRestrictionStore()->isSemiProtected( $page ) ) {
84 $classes[] = 'mw-textarea-sprotected';
85 } else {
86 # Then it must be protected based on static groups (regular)
87 $classes[] = 'mw-textarea-protected';
88 }
89 # Is the title cascade-protected?
90 if ( $services->getRestrictionStore()->isCascadeProtected( $page ) ) {
91 $classes[] = 'mw-textarea-cprotected';
92 }
93 }
94
95 return $classes;
96 }
97
105 public function buildTextboxAttribs(
106 $name, array $customAttribs, UserIdentity $user, PageIdentity $page
107 ) {
108 $attribs = $customAttribs + [
109 'accesskey' => ',',
110 'id' => $name,
111 'cols' => 80,
112 'rows' => 25,
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 Html::addClass( $attribs['class'], $class );
122
123 $title = Title::newFromPageIdentity( $page );
124 $pageLang = $title->getPageLanguage();
125 $attribs['lang'] = $pageLang->getHtmlCode();
126 $attribs['dir'] = $pageLang->getDir();
127
128 return $attribs;
129 }
130
131}
Helps EditPage build textboxes.
buildTextboxAttribs( $name, array $customAttribs, UserIdentity $user, PageIdentity $page)
mergeClassesIntoAttributes(array $classes, array $attribs)
getTextboxProtectionCSSClasses(PageIdentity $page)
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
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:46
Represents a title within MediaWiki.
Definition Title.php:78
getOption(UserIdentity $user, string $oname, $defaultOverride=null, bool $ignoreHidden=false, int $queryFlags=IDBAccessObject::READ_NORMAL)
Get the user's current setting for a given option.
Interface for objects (potentially) representing an editable wiki page.
getNamespace()
Returns the page's namespace number.
Interface for objects representing user identity.