MediaWiki master
TextboxBuilder.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\EditPage;
8
15
24
29 public function addNewLineAtEnd( $wikitext ) {
30 if ( strval( $wikitext ) !== '' ) {
31 // Ensure there's a newline at the end, otherwise adding lines
32 // is awkward.
33 // But don't add a newline if the text is empty, or Firefox in XHTML
34 // mode will show an extra newline. A bit annoying.
35 return $wikitext . "\n";
36 }
37 return $wikitext;
38 }
39
46 public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
47 if ( $classes === [] ) {
48 return $attribs;
49 }
50
51 return Sanitizer::mergeAttributes(
52 $attribs,
53 [ 'class' => implode( ' ', $classes ) ]
54 );
55 }
56
62 $classes = []; // Textarea CSS
64 if ( $services->getRestrictionStore()->isProtected( $page, 'edit' ) &&
65 $services->getPermissionManager()
66 ->getNamespaceRestrictionLevels( $page->getNamespace() ) !== [ '' ]
67 ) {
68 # Is the title semi-protected?
69 if ( $services->getRestrictionStore()->isSemiProtected( $page ) ) {
70 $classes[] = 'mw-textarea-sprotected';
71 } else {
72 # Then it must be protected based on static groups (regular)
73 $classes[] = 'mw-textarea-protected';
74 }
75 # Is the title cascade-protected?
76 if ( $services->getRestrictionStore()->isCascadeProtected( $page ) ) {
77 $classes[] = 'mw-textarea-cprotected';
78 }
79 }
80
81 return $classes;
82 }
83
91 public function buildTextboxAttribs(
92 $name, array $customAttribs, UserIdentity $user, PageIdentity $page
93 ) {
94 $attribs = $customAttribs + [
95 'accesskey' => ',',
96 'id' => $name,
97 'cols' => 80,
98 'rows' => 25,
99 ];
100
101 // The following classes can be used here:
102 // * mw-editfont-monospace
103 // * mw-editfont-sans-serif
104 // * mw-editfont-serif
105 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
106 $class = 'mw-editfont-' . $userOptionsLookup->getOption( $user, 'editfont' );
107 Html::addClass( $attribs['class'], $class );
108
109 $title = Title::newFromPageIdentity( $page );
110 $pageLang = $title->getPageLanguage();
111 $attribs['lang'] = $pageLang->getHtmlCode();
112 $attribs['dir'] = $pageLang->getDir();
113
114 return $attribs;
115 }
116
117}
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:43
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:32
Represents a title within MediaWiki.
Definition Title.php:69
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.