MediaWiki  master
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 
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)
isSemiProtected( $action='edit')
Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionL...
Definition: Title.php:2586
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user&#39;s current setting for a given option.
Definition: User.php:2915
static getInstance()
Returns the global default instance of the top level service locator.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
buildTextboxAttribs( $name, array $customAttribs, User $user, Title $title)
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:936
isCascadeProtected()
Cascading protection: Return true if cascading restrictions apply to this page, false if not...
Definition: Title.php:2666
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:1040
isProtected( $action='')
Does the title correspond to a protected article?
Definition: Title.php:2614
getPageLanguage()
Get the language in which the content of this page is written in wikitext.
Definition: Title.php:4638