diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 20e28e5372..7693ac50e1 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -209,17 +209,17 @@ class VisualEditorHooks { /** * Changes the section edit links to add a VE edit link. * - * This is attached to the MediaWiki 'DoEditSectionLink' hook. + * This is attached to the MediaWiki 'SkinEditSectionLinks' hook. * * @param $skin Skin * @param $title Title * @param $section string * @param $tooltip string - * @param $result string HTML + * @param $result array * @param $lang Language * @return bool true */ - public static function onDoEditSectionLink( Skin $skin, Title $title, $section, + public static function onSkinEditSectionLinks( Skin $skin, Title $title, $section, $tooltip, &$result, $lang ) { // Only do this if the user has VE enabled @@ -245,35 +245,24 @@ class VisualEditorHooks { $sourceEditSection = $tabMessages['editsectionsource'] !== null ? $tabMessages['editsectionsource'] : 'editsection'; - // Code mostly duplicated from Skin::doEditSectionLink() :( - $attribs = array(); - if ( !is_null( $tooltip ) ) { - # Bug 25462: undo double-escaping. - $tooltip = Sanitizer::decodeCharReferences( $tooltip ); - $attribs['title'] = $skin->msg( 'editsectionhint' )->rawParams( $tooltip ) - ->inLanguage( $lang )->text(); - } - $veLink = Linker::link( $title, $skin->msg( $veEditSection )->inLanguage( $lang )->text(), - $attribs + array( 'class' => 'mw-editsection-visualeditor' ), - array( 'veaction' => 'edit', 'vesection' => $section ), - array( 'noclasses', 'known' ) - ); - $sourceLink = Linker::link( $title, $skin->msg( $sourceEditSection )->inLanguage( $lang )->text(), - $attribs, - array( 'action' => 'edit', 'section' => $section ), - array( 'noclasses', 'known' ) + $result['editsection']['text'] = $skin->msg( $sourceEditSection )->inLanguage( $lang )->text(); + + $veLink = array( + 'text' => $skin->msg( $veEditSection )->inLanguage( $lang )->text(), + 'targetTitle' => $title, + 'attribs' => $result['editsection']['attribs'] + array( + 'class' => 'mw-editsection-visualeditor' + ), + 'query' => array( 'veaction' => 'edit', 'vesection' => $section ), + 'options' => array( 'noclasses', 'known' ) ); - $veFirst = $config->get( 'VisualEditorTabPosition' ) === 'before'; - $result = '' - . '[' - . ( $veFirst ? $veLink : $sourceLink ) - . '' - . $skin->msg( 'pipe-separator' )->inLanguage( $lang )->text() - . '' - . ( $veFirst ? $sourceLink : $veLink ) - . ']' - . ''; + $result['veeditsection'] = $veLink; + if ( $config->get( 'VisualEditorTabPosition' ) === 'before' ) { + krsort( $result ); + // TODO: This will probably cause weird ordering if any other extensions added something already. + // ... wfArrayInsertBefore? + } return true; } diff --git a/VisualEditor.php b/VisualEditor.php index 707a0bed2a..095758cabc 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -68,7 +68,7 @@ $wgConfigRegistry['visualeditor'] = 'GlobalVarConfig::newInstance'; // Register Hooks $wgHooks['BeforePageDisplay'][] = 'VisualEditorHooks::onBeforePageDisplay'; $wgHooks['ContentHandlerDefaultModelFor'][] = 'VisualEditorHooks::onContentHandlerDefaultModelFor'; -$wgHooks['DoEditSectionLink'][] = 'VisualEditorHooks::onDoEditSectionLink'; +$wgHooks['SkinEditSectionLinks'][] = 'VisualEditorHooks::onSkinEditSectionLinks'; $wgHooks['GetBetaFeaturePreferences'][] = 'VisualEditorHooks::onGetBetaPreferences'; $wgHooks['GetPreferences'][] = 'VisualEditorHooks::onGetPreferences'; $wgHooks['ListDefinedTags'][] = 'VisualEditorHooks::onListDefinedTags'; diff --git a/extension.json b/extension.json index 4364023f75..50b01b5295 100644 --- a/extension.json +++ b/extension.json @@ -115,8 +115,8 @@ "ContentHandlerDefaultModelFor": [ "VisualEditorHooks::onContentHandlerDefaultModelFor" ], - "DoEditSectionLink": [ - "VisualEditorHooks::onDoEditSectionLink" + "SkinEditSectionLinks": [ + "VisualEditorHooks::onSkinEditSectionLinks" ], "GetBetaFeaturePreferences": [ "VisualEditorHooks::onGetBetaPreferences"