MediaWiki master
TextboxBuilder.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\EditPage;
8
17
25
26 public function __construct(
27 private readonly PermissionManager $permissionManager,
28 private readonly RestrictionStore $restrictionStore,
29 private readonly UserOptionsLookup $userOptionsLookup,
30 ) {
31 }
32
37 public function addNewLineAtEnd( $wikitext ) {
38 if ( strval( $wikitext ) !== '' ) {
39 // Ensure there's a newline at the end, otherwise adding lines
40 // is awkward.
41 // But don't add a newline if the text is empty, or Firefox in XHTML
42 // mode will show an extra newline. A bit annoying.
43 return $wikitext . "\n";
44 }
45 return $wikitext;
46 }
47
54 public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
55 wfDeprecated( __METHOD__, '1.47' );
56 if ( $classes === [] ) {
57 return $attribs;
58 }
59
60 return Sanitizer::mergeAttributes(
61 $attribs,
62 [ 'class' => implode( ' ', $classes ) ]
63 );
64 }
65
71 $classes = []; // Textarea CSS
72 if ( $this->restrictionStore->isProtected( $page, 'edit' ) &&
73 $this->permissionManager->getNamespaceRestrictionLevels( $page->getNamespace() ) !== [ '' ]
74 ) {
75 # Is the title semi-protected?
76 if ( $this->restrictionStore->isSemiProtected( $page ) ) {
77 $classes[] = 'mw-textarea-sprotected';
78 } else {
79 # Then it must be protected based on static groups (regular)
80 $classes[] = 'mw-textarea-protected';
81 }
82 # Is the title cascade-protected?
83 if ( $this->restrictionStore->isCascadeProtected( $page ) ) {
84 $classes[] = 'mw-textarea-cprotected';
85 }
86 }
87
88 return $classes;
89 }
90
98 public function buildTextboxAttribs(
99 $name, array $customAttribs, UserIdentity $user, PageIdentity $page
100 ) {
101 $attribs = $customAttribs + [
102 'accesskey' => ',',
103 'id' => $name,
104 'cols' => 80,
105 'rows' => 25,
106 ];
107
108 // The following classes can be used here:
109 // * mw-editfont-monospace
110 // * mw-editfont-sans-serif
111 // * mw-editfont-serif
112 $class = 'mw-editfont-' . $this->userOptionsLookup->getOption( $user, 'editfont' );
113 Html::addClass( $attribs['class'], $class );
114
115 $title = Title::newFromPageIdentity( $page );
116 $pageLang = $title->getPageLanguage();
117 $attribs['lang'] = $pageLang->getHtmlCode();
118 $attribs['dir'] = $pageLang->getDir();
119
120 return $attribs;
121 }
122
123}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Helps EditPage build textboxes.
buildTextboxAttribs( $name, array $customAttribs, UserIdentity $user, PageIdentity $page)
mergeClassesIntoAttributes(array $classes, array $attribs)
getTextboxProtectionCSSClasses(PageIdentity $page)
__construct(private readonly PermissionManager $permissionManager, private readonly RestrictionStore $restrictionStore, private readonly UserOptionsLookup $userOptionsLookup,)
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:34
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Represents a title within MediaWiki.
Definition Title.php:69
Provides access to user options.
Interface for objects (potentially) representing an editable wiki page.
getNamespace()
Returns the page's namespace number.
Interface for objects representing user identity.