diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index ffb2a47894..31b41f1917 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -374,7 +374,7 @@ class VisualEditorHooks { * Adds extra variables to the page config. */ public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) { - global $wgStylePath, $wgSVGMaxSize; + global $wgStylePath, $wgSVGMaxSize, $wgNamespacesWithSubpages; $pageLanguage = $out->getTitle()->getPageLanguage(); @@ -387,6 +387,7 @@ class VisualEditorHooks { 'pageLanguageCode' => $pageLanguage->getHtmlCode(), 'pageLanguageDir' => $pageLanguage->getDir(), 'svgMaxSize' => $wgSVGMaxSize, + 'namespacesWithSubpages' => $wgNamespacesWithSubpages ); return true; diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js index 5c23ccb9cc..93d0895b06 100755 --- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js @@ -18,10 +18,20 @@ * @param {number} [size] Vertical size of thumbnails */ ve.ui.MWMediaSearchWidget = function VeUiMWMediaSearchWidget( config ) { + var pageTitle = mw.config.get( 'wgTitle' ), + namespace = mw.config.get( 'wgNamespaceNumber' ), + namespacesWithSubpages = mw.config.get( 'wgVisualEditor' ).namespacesWithSubpages; + + if ( namespacesWithSubpages[ namespace ] ) { + // If we are in a namespace that allows for subpages, strip the entire + // title except for the part after the last / + pageTitle = pageTitle.substr( pageTitle.lastIndexOf( '/' ) + 1 ); + } + // Configuration intialization config = ve.extendObject( { 'placeholder': ve.msg( 'visualeditor-media-input-placeholder' ), - 'value': mw.config.get( 'wgTitle' ) + 'value': pageTitle }, config ); // Parent constructor