| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\EditPage; |
| 22 |
|
| 23 |
use MediaWiki\MediaWikiServices; |
| 24 |
use MediaWiki\Page\PageIdentity; |
| 25 |
use MediaWiki\Parser\Sanitizer; |
| 26 |
use MediaWiki\Title\Title; |
| 27 |
use MediaWiki\User\UserIdentity; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class TextboxBuilder { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function addNewLineAtEnd( $wikitext ) { |
| 43 |
if ( strval( $wikitext ) !== '' ) { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
return $wikitext . "\n"; |
| 49 |
} |
| 50 |
return $wikitext; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function mergeClassesIntoAttributes( array $classes, array $attribs ) { |
| 59 |
if ( $classes === [] ) { |
| 60 |
return $attribs; |
| 61 |
} |
| 62 |
|
| 63 |
return Sanitizer::mergeAttributes( |
| 64 |
$attribs, |
| 65 |
[ 'class' => implode( ' ', $classes ) ] |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public function getTextboxProtectionCSSClasses( PageIdentity $page ) { |
| 74 |
$classes = []; |
| 75 |
$services = MediaWikiServices::getInstance(); |
| 76 |
if ( $services->getRestrictionStore()->isProtected( $page, 'edit' ) && |
| 77 |
$services->getPermissionManager() |
| 78 |
->getNamespaceRestrictionLevels( $page->getNamespace() ) !== [ '' ] |
| 79 |
) { |
| 80 |
|
| 81 |
if ( $services->getRestrictionStore()->isSemiProtected( $page ) ) { |
| 82 |
$classes[] = 'mw-textarea-sprotected'; |
| 83 |
} else { |
| 84 |
|
| 85 |
$classes[] = 'mw-textarea-protected'; |
| 86 |
} |
| 87 |
|
| 88 |
if ( $services->getRestrictionStore()->isCascadeProtected( $page ) ) { |
| 89 |
$classes[] = 'mw-textarea-cprotected'; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
return $classes; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function buildTextboxAttribs( |
| 104 |
$name, array $customAttribs, UserIdentity $user, PageIdentity $page |
| 105 |
) { |
| 106 |
$attribs = $customAttribs + [ |
| 107 |
'accesskey' => ',', |
| 108 |
'id' => $name, |
| 109 |
'cols' => 80, |
| 110 |
'rows' => 25, |
| 111 |
|
| 112 |
|
| 113 |
'style' => '' |
| 114 |
]; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup(); |
| 121 |
$class = 'mw-editfont-' . $userOptionsLookup->getOption( $user, 'editfont' ); |
| 122 |
|
| 123 |
if ( isset( $attribs['class'] ) ) { |
| 124 |
if ( is_string( $attribs['class'] ) ) { |
| 125 |
$attribs['class'] .= ' ' . $class; |
| 126 |
} elseif ( is_array( $attribs['class'] ) ) { |
| 127 |
$attribs['class'][] = $class; |
| 128 |
} |
| 129 |
} else { |
| 130 |
$attribs['class'] = $class; |
| 131 |
} |
| 132 |
|
| 133 |
$title = Title::newFromPageIdentity( $page ); |
| 134 |
$pageLang = $title->getPageLanguage(); |
| 135 |
$attribs['lang'] = $pageLang->getHtmlCode(); |
| 136 |
$attribs['dir'] = $pageLang->getDir(); |
| 137 |
|
| 138 |
return $attribs; |
| 139 |
} |
| 140 |
|
| 141 |
} |