2015-05-16 19 views

回答

-1

我不知道我完全理解你的問題。只需選擇一些文本,點擊鏈圖標,然後點擊External Link選項卡並粘貼鏈接即可。


Screenshot

+1

我想問的是如何添加一個鏈接到VE工具欄,而不是可編輯的內容:) – Florian

3

我的答案是基於以下資源:

另外,我很確定,據我所知,沒有在VE工具欄中添加工具的文檔化方法。雖然可以將一個工具添加到已添加的組中,但主要用於「插入」工具組,如Syntaxhighlight_GeSHi)。有可能是這樣做更容易或更好的方式:)首先,可視化編輯器提供了一種方式來加載額外的模塊(稱爲插件),當VE的主要部分加載(大多數時候,當你點擊「編輯」按鈕)。這些模塊需要通過全局變量$wgVisualEditorPluginModules(或extension.json中的等效項,如果您使用新的擴展註冊)進行註冊。在您的擴展註冊文件中,您應該初始化一個模塊(使用您所需的腳本文件來添加該工具)並將其添加爲VE插件。

例PHP(經由PHP文件舊擴展註冊):

// other setup... 
$wgResourceModules['ext.extName.visualeditor'] = array(
    'localBasePath' => __DIR__, 
    'remoteExtPath' => 'extName' 
    'dependencies' => array(
     'ext.visualEditor.mwcore', 
    ), 
    'scripts' => array(
     'javascripts/ve.ui.ExtNameTool.js', 
    ), 
    'messages' => array(
     'extname-ve-toolname', 
    ), 
); 
$wgVisualEditorPluginModules[] = 'ext.extName.visualeditor'; 
// other setup... 

extension.json(新基於JSON的擴展註冊):

// other setup... 
"ResourceModules": { 
    "ext.geshi.visualEditor": { 
     "scripts": [ 
      "javascripts/ve.ui.ExtNameTool.js" 
     ], 
     "dependencies": [ 
      "ext.visualEditor.mwcore" 
     ], 
     "messages": [ 
      "extname-ve-toolname" 
     ] 
    } 
}, 
"VisualEditorPluginModules": [ 
    "ext.extName.visualeditor" 
], 
// other setup... 

現在,如果VE啓動,它會加載您的模塊,在本示例中名爲ext.extName.visualeditor,腳本爲ve.ui.ExtNameTool.js。在這個腳本中,你現在可以做,你想要什麼。作爲一個例子,這是一個新的模塊添加到工具欄在toolgroup列表的末尾的方式:

ve.ui.ExtNameTool.js的實施例:

(function() { 
    // create a new class, which will inherit ve.ui.Tool, 
    // which represents one tool 
    ve.ui.extNameTool = function extNameTool(toolGroup, config) { 
     // parent constructor 
     ve.ui.extNameTool.super.apply(this, arguments); 
     // the tool should be enabled by default, enable it 
     this.setDisabled(false); 
    } 
    // inherit ve.ui.Tool 
    OO.inheritClass(ve.ui.extNameTool, ve.ui.Tool); 
    // every tool needs at least a name, or an icon 
    // (with the static property icon) 
    ve.ui.extNameTool.static.name = 'extname'; 
    // don't add the tool to a named group automatically 
    ve.ui.extNameTool.static.autoAddToGroup = false; 
    // prevent this tool to be added to a catch-all group (*), 
    although this tool isn't added to a group 
    ve.ui.extNameTool.static.autoAddToCatchall = false; 
    // the title of the group (it's a message key, 
    // which should be added to the extensions i18n 
    // en.json file to be translateable) 
    // can be a string, too 
    ve.ui.extNameTool.static.title = 
     OO.ui.deferMsg('extname-ve-toolname'); 
    // onSelect is the handler for a click on the tool 
    ve.ui.extNameTool.prototype.onSelect = function() { 
     // show an alert box only, but you can do anything 
     alert('Hello'); 
     this.setActive(false); 
    } 
    // needs to be overwritten, but does nothing so far 
    ve.ui.extNameTool.prototype.onUpdateState = function() { 
    ve.ui.extNameTool.super.prototype.onUpdateState.apply(this, arguments); 
    } 
    // the tool needs to be registered to the toolFactory 
    // of the toolbar to be reachable with the given name 
    ve.ui.toolFactory.register(ve.ui.extNameTool); 
    // add this tool to the toolbar 
    ve.init.mw.Target.static.toolbarGroups.push({ 
     // this will create a new toolgroup with the tools 
     // named in this include directive. The naem is the name given 
     // in the static property of the tool 
     include: [ 'extname' ] 
    }); 
})(); 

在安裝後延伸您的LocalSettings.php並啓動VE,您應該在工具欄中看到具有給定名稱的新工具。點擊它會顯示一個警告框,內容爲「你好」。如同在線評論中所寫:在點擊處理程序(onSelect)中,您可以做任何你想做的事情,例如在新標籤中打開鏈接,例如到特殊頁面。要獲得到特殊頁面的鏈接,我建議使用mw.Title來獲得本地化的名稱空間。例如:

var relativeUrl = mw.Title.newFromText('RecentChanges', -1).getUrl(); 

mw.Title.newFromText()的第一個參數是頁面的名稱,第二個參數是命名空間的ID(-1是特殊頁面的默認,並應永久有效)。

我希望有幫助!