MediaWiki  1.34.0
TextboxBuilder.php
Go to the documentation of this file.
1 <?php
26 
28 use Sanitizer;
29 use Title;
30 use 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 }
MediaWiki\EditPage\TextboxBuilder\mergeClassesIntoAttributes
mergeClassesIntoAttributes(array $classes, array $attribs)
Definition: TextboxBuilder.php:60
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
MediaWiki\EditPage\TextboxBuilder
Helps EditPage build textboxes.
Definition: TextboxBuilder.php:37
MediaWiki\EditPage\TextboxBuilder\buildTextboxAttribs
buildTextboxAttribs( $name, array $customAttribs, User $user, Title $title)
Definition: TextboxBuilder.php:104
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
MediaWiki\EditPage\TextboxBuilder\getTextboxProtectionCSSClasses
getTextboxProtectionCSSClasses(Title $title)
Definition: TextboxBuilder.php:75
$title
$title
Definition: testCompression.php:34
User\getOption
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition: User.php:2918
MediaWiki\EditPage\TextboxBuilder\addNewLineAtEnd
addNewLineAtEnd( $wikitext)
Definition: TextboxBuilder.php:43
Title
Represents a title within MediaWiki.
Definition: Title.php:42
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\EditPage
Definition: TextboxBuilder.php:25