MediaWiki  REL1_31
TextboxBuilder.php
Go to the documentation of this file.
1 <?php
26 
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 ( !count( $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  MWNamespace::getRestrictionLevels( $title->getNamespace() ) !== [ '' ]
79  ) {
80  # Is the title semi-protected?
81  if ( $title->isSemiProtected() ) {
82  $classes[] = 'mw-textarea-sprotected';
83  } else {
84  # Then it must be protected based on static groups (regular)
85  $classes[] = 'mw-textarea-protected';
86  }
87  # Is the title cascade-protected?
88  if ( $title->isCascadeProtected() ) {
89  $classes[] = 'mw-textarea-cprotected';
90  }
91  }
92 
93  return $classes;
94  }
95 
105  'accesskey' => ',',
106  'id' => $name,
107  'cols' => 80,
108  'rows' => 25,
109  // Avoid PHP notices when appending preferences
110  // (appending allows customAttribs['style'] to still work).
111  'style' => ''
112  ];
113 
114  // The following classes can be used here:
115  // * mw-editfont-monospace
116  // * mw-editfont-sans-serif
117  // * mw-editfont-serif
118  $class = 'mw-editfont-' . $user->getOption( 'editfont' );
119 
120  if ( isset( $attribs['class'] ) ) {
121  if ( is_string( $attribs['class'] ) ) {
122  $attribs['class'] .= ' ' . $class;
123  } elseif ( is_array( $attribs['class'] ) ) {
124  $attribs['class'][] = $class;
125  }
126  } else {
127  $attribs['class'] = $class;
128  }
129 
130  $pageLang = $title->getPageLanguage();
131  $attribs['lang'] = $pageLang->getHtmlCode();
132  $attribs['dir'] = $pageLang->getDir();
133 
134  return $attribs;
135  }
136 
137 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
MediaWiki\EditPage\TextboxBuilder\mergeClassesIntoAttributes
mergeClassesIntoAttributes(array $classes, array $attribs)
Definition: TextboxBuilder.php:60
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
MediaWiki\EditPage\TextboxBuilder
Helps EditPage build textboxes.
Definition: TextboxBuilder.php:37
Sanitizer\mergeAttributes
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:910
$customAttribs
null means default & $customAttribs
Definition: hooks.txt:1995
MediaWiki\EditPage\TextboxBuilder\buildTextboxAttribs
buildTextboxAttribs( $name, array $customAttribs, User $user, Title $title)
Definition: TextboxBuilder.php:103
User
User
Definition: All_system_messages.txt:425
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWiki\EditPage\TextboxBuilder\getTextboxProtectionCSSClasses
getTextboxProtectionCSSClasses(Title $title)
Definition: TextboxBuilder.php:75
MWNamespace
This is a utility class with only static functions for dealing with namespaces that encodes all the "...
Definition: MWNamespace.php:32
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
MWNamespace\getRestrictionLevels
static getRestrictionLevels( $index, User $user=null)
Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a use...
Definition: MWNamespace.php:489
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:2014
MediaWiki\EditPage\TextboxBuilder\addNewLineAtEnd
addNewLineAtEnd( $wikitext)
Definition: TextboxBuilder.php:43
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
Sanitizer
HTML sanitizer for MediaWiki.
Definition: Sanitizer.php:31
MediaWiki\EditPage
Definition: TextboxBuilder.php:25