From 410a47aa743956c0be9ad66e70838202d1b09dce Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Fri, 28 Oct 2016 15:02:38 +0200 Subject: [PATCH] Extract methods while creating the textbox This is also mainly done so they can be better utilized when extending the EditPage class. Bug: T143823 Change-Id: Id592c9ffa60dc6a904da7ce514e19954125c8ee5 --- includes/EditPage.php | 98 +++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 85c14fc496..9d8b5e5751 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -3217,44 +3217,9 @@ HTML global $wgOut, $wgUser; $wikitext = $this->safeUnicodeOutput( $text ); - if ( strval( $wikitext ) !== '' ) { - // Ensure there's a newline at the end, otherwise adding lines - // is awkward. - // But don't add a newline if the ext is empty, or Firefox in XHTML - // mode will show an extra newline. A bit annoying. - $wikitext .= "\n"; - } - - $attribs = $customAttribs + [ - 'accesskey' => ',', - 'id' => $name, - 'cols' => $wgUser->getIntOption( 'cols' ), - 'rows' => $wgUser->getIntOption( 'rows' ), - // Avoid PHP notices when appending preferences - // (appending allows customAttribs['style'] to still work). - 'style' => '' - ]; + $wikitext = $this->addNewLineAtEnd( $wikitext ); - // The following classes can be used here: - // * mw-editfont-default - // * mw-editfont-monospace - // * mw-editfont-sans-serif - // * mw-editfont-serif - $class = 'mw-editfont-' . $wgUser->getOption( 'editfont' ); - - if ( isset( $attribs['class'] ) ) { - if ( is_string( $attribs['class'] ) ) { - $attribs['class'] .= ' ' . $class; - } elseif ( is_array( $attribs['class'] ) ) { - $attribs['class'][] = $class; - } - } else { - $attribs['class'] = $class; - } - - $pageLang = $this->mTitle->getPageLanguage(); - $attribs['lang'] = $pageLang->getHtmlCode(); - $attribs['dir'] = $pageLang->getDir(); + $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser ); $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); } @@ -4442,4 +4407,63 @@ HTML protected function addExplainConflictHeader( OutputPage &$out ) { $out->wrapWikiMsg( "
\n$1\n
", 'explainconflict' ); } + + /** + * @param string $name + * @param mixed[] $customAttribs + * @param User $wgUser + * @return mixed[] + * @since 1.29 + */ + protected function buildTextboxAttribs( $name, array $customAttribs, User $wgUser ) { + $attribs = $customAttribs + [ + 'accesskey' => ',', + 'id' => $name, + 'cols' => $wgUser->getIntOption( 'cols' ), + 'rows' => $wgUser->getIntOption( 'rows' ), + // Avoid PHP notices when appending preferences + // (appending allows customAttribs['style'] to still work). + 'style' => '' + ]; + + // The following classes can be used here: + // * mw-editfont-default + // * mw-editfont-monospace + // * mw-editfont-sans-serif + // * mw-editfont-serif + $class = 'mw-editfont-' . $wgUser->getOption( 'editfont' ); + + if ( isset( $attribs['class'] ) ) { + if ( is_string( $attribs['class'] ) ) { + $attribs['class'] .= ' ' . $class; + } elseif ( is_array( $attribs['class'] ) ) { + $attribs['class'][] = $class; + } + } else { + $attribs['class'] = $class; + } + + $pageLang = $this->mTitle->getPageLanguage(); + $attribs['lang'] = $pageLang->getHtmlCode(); + $attribs['dir'] = $pageLang->getDir(); + + return $attribs; + } + + /** + * @param string $wikitext + * @return string + * @since 1.29 + */ + protected function addNewLineAtEnd( $wikitext ) { + if ( strval( $wikitext ) !== '' ) { + // Ensure there's a newline at the end, otherwise adding lines + // is awkward. + // But don't add a newline if the text is empty, or Firefox in XHTML + // mode will show an extra newline. A bit annoying. + $wikitext .= "\n"; + return $wikitext; + } + return $wikitext; + } } -- 2.20.1