Jump to content

Topic on Extension talk:VisualEditor/Flow

Enable VisualEditor for 'create' page

32
MarkJurgens (talkcontribs)

Any suggestions for turning on the visual editor for as the default for creating a page? It still defaults to the old editor.

Still experimenting. Great work everyone.

Jdforrester (WMF) (talkcontribs)

If you have VisualEditor switched on, you should get "Create" and "Create source". The first takes you into VisualEditor, the second to the wikitext editor. Does this not show up for you?

MarkJurgens (talkcontribs)

Almost, the visual editor is available as an option, and works when I click on the tab. However it defaults to the edit source.

Here's my localsettings:

require_once("$IP/extensions/VisualEditor/VisualEditor.php");
 
## Visual Editor Settings:

// Create VisualEditor namespace
define( 'NS_VISUALEDITOR', 2500 );
define( 'NS_VISUALEDITOR_TALK', 2501 );
$wgExtraNamespaces[NS_VISUALEDITOR] = 'VisualEditor';
$wgExtraNamespaces[NS_VISUALEDITOR_TALK] = 'VisualEditor_talk';
 
// Allow using VisualEditor in the main namespace only (default)
$wgVisualEditorNamespaces ['*'];
// $wgVisualEditorNamespaces = array( NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK );
 
// Restrict VisualEditor to the VisualEditor namespace
//$wgVisualEditorNamespaces = array();
//$wgVisualEditorNamespaces[] = NS_VISUALEDITOR;
 
// Enable by default for everybody
$wgDefaultUserOptions['visualeditor-enable'] = 1;
 
// Don't allow users to disable it
$wgHiddenPrefs[] = 'visualeditor-enable';
129.215.139.112 (talkcontribs)

I have the same request. Creating pages through a link or through the search box always loads the markup editor, and you have to change to VE manually with the "create" tab. This behaviour is very confusing for my users. By the way, preloading a template also doesn't work with VE.

139.30.7.108 (talkcontribs)

Hello, I also work on this issue. I developed a special page extension for creating an article. The user has to type the name of article, then after a search (checking if already exists) user select a template and click create. Behind "create" there's this link 'http://yourmedia.wiki/index.php?title=[ARTICLE_NAME]&veaction=edit&redlink=1'. So, the visual editor will start and the user can create content.

But the preloading of templates also doesn't work. With the standard eitor this was easy by using NewArticleTemplate extension. But the used hook 'EditPage::showEditForm:initial' doesn't work with VE. Can anyone help? Otherwise I implement an work-around (some 'Javascript magic').

Stephan Matthiesen (talkcontribs)

If you have a workaround, that would be great. I have the same issue, and it would be enough if an extension just creates and saves a new page by copying the template, and the user then can click on "edit" to actually modify it. This would solve both problems (that VE isn't default, and it doesn't handle templates). Is it possible to copy a page using URL parameters?

139.30.7.108 (talkcontribs)

I implement an extension for this issue. Actually, it's based on MediaWiki WriteAPI which is not a good solution because it makes it easy for automatic editing by bots. But it works. The user chooses a name and a template from a list and click create. In background AJAX is used to get MediaWiki text from choosen template and then creates the page by using the WriteAPI (where you give template text as a parameter). Finaly, the user is automatically forwarded to the new page with opened visual editor.

Stephan Matthiesen (talkcontribs)

Is this extension available somewhere? Sounds useful and I'd like to test it.

Noti1234 (talkcontribs)

I would also like to test this extension...

86.21.250.65 (talkcontribs)

I have implemented the following crude hack into the top of my index.php:

if($_GET['redlink']==1 && $_GET['action']=='edit') {
	header('Location: index.php?title='.$_GET['title'].'&veaction=edit&redlink=1'); 
	die();
}

Hope this helps someone.

118.69.216.234 (talkcontribs)

Thanks for your workaround. It works well!

Noboddy (talkcontribs)

Thanks for that, it's a great workaround!

65.60.117.82 (talkcontribs)

Hi - is this suppose to be placed in the index.php of the wiki folder? I did that and got all kinds of errors.

65.60.117.82 (talkcontribs)

Nevermind I figured out how to do it. You can't simply use that code, you have to modify it to first check if the page even has those tags in the url. this works

if(isset($_GET["redlink"]) && isset($_GET["action"])){ $clicked_edit_link = ($_GET["redlink"]); $action_doing_now = ($_GET["action"]);

if($clicked_edit_link==1 && $action_doing_now=='edit') { header('Location: index.php?title='.$_GET['title'].'&veaction=edit&redlink=1'); die(); }}

Vedmaka (talkcontribs)

All you need is to modify (noarticletext) message at Special:Allmessages - just replace action=edit by veaction=edit

Potrod (talkcontribs)

Thanks! That works great for creating pages based on what you type in the URL (ie: www.example.com/wiki/newpage123). But it does not work if you type "newpage123" in the search box. If you want to be able to create pages from the search box using Visual Editor, you would also have to edit the special message MediaWiki:Searchmenu-new

Here is what I came up with for that:

<strong>[{{fullurl:$1|veaction=edit}} Create the page "$1"] on this wiki!</strong> 
Ianmelchior (talkcontribs)

@Vedmaka & @Potrod's suggestions worked well for me. I recommend this method.

177.69.223.132 (talkcontribs)

for me too!!! S2

Ianmelchior (talkcontribs)

@Vedmaka@Potrod any idea how to also make VisualEditor the default when clicking on a red link to create a new article?

Potrod (talkcontribs)

There was an idea above that seemed to work for some people.

Tinss (talkcontribs)

@Vedmaka's tip and the code above worked for me and seems to cover all bases (page creation via a redlink, search or URL). The code above works fine when placed in the LocalSettings.php (instead of index) but you need to check for the existence of all $_GET parameters with isset($_GET['var']). Here is the final result:

# A hack that redirects users to the visual editor when clicking a redlink rather that to the wikicode editor.
if(isset($_GET['redlink']) && isset($_GET['action']) && isset($_GET['title']) && $_GET['redlink'] == 1 && $_GET['action']=='edit') 
{
	header('Location: index.php?title='.$_GET['title'].'&veaction=edit&redlink=1'); 
	die();
}
163.8.84.67 (talkcontribs)

Thanks Tinss. Your solution solved my problem too.

Kevin

Jdforrester (WMF) (talkcontribs)

Note that this is now supported in VisualEditor-MediaWiki master (as will come out for compatibility with MW 1.27.0).

Quinnj09 (talkcontribs)

How is it supported?

Baongoc124 (talkcontribs)

@Ianmelchior Maybe a little late to the party. I am using Mediawiki 1.27.1 stable and to set visual editor as default for redlink I write a hook on LinkBegin. Hope it helps someone.

public static function onLinkBegin( $dummy, $target, &$html, &$customAttribs,

&$query, &$options, &$ret ) {

if ( in_array( 'broken', $options, true ) && empty( $query['action'] )

&& $target->getNamespace() !== NS_SPECIAL ) {

$ret = Html::rawElement ('a', ['href' => $target->getFullURL('veaction=edit&redlink=1'), 'class' => 'new'], $target->getPrefixedDBKey());

return false;

}

return true;

}

Tinss (talkcontribs)

Great idea @Baongoc124! But your code as is does not quite work as it needs to be hooked to the event ($wgHooks['LinkBegin'][] = 'onLinkBegin';) and would not display the correct link text. Here is an improved and simplified version:

# A hack that redirects users to the visual editor when clicking a redlink rather that to the wikicode editor.
function onLinkBegin( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) 
{
	if ( in_array( 'broken', $options, true ) && empty( $query['action'] ) && $target->getNamespace() !== NS_SPECIAL ) 
	{
		$query['veaction'] = 'edit';
		$query['action'] = 'view'; // Important! Otherwise MediaWiki will override veaction.
		$query['redlink'] = '1';
	}

	return true;
}
$wgHooks['LinkBegin'][] = 'onLinkBegin'; // WARNING! Will be superseded by HtmlPageLinkRendererBegin in MediaWiki 1.28.

Note: to cover all bases, you still need to modify the noarticletext message as @Vedmaka suggested.

213.33.71.5 (talkcontribs)

I have done this job with a little java script placed in page MediaWiki:Common.js

if ( wgArticleId === 0 && wgAction === 'edit' ) { window.location = 'index.php?title=' + wgPageName + '&veaction=edit&redlink=1'; }

It works for me. Hope it helps!

RobertoTH (talkcontribs)

Based on @Tinss answer, here is a hook using HtmlPageLinkRendererBegin that can be added to LocalSettings.php:

# Default to VisualEditor for red links
class MyHooks {
	public static function onHtmlPageLinkRendererBegin($linkRenderer, $target, &$text, &$extraAttribs, &$query, &$ret) {
		$title = Title::newFromLinkTarget($target);
		$isKnown = $title->isKnown();

		if (!$isKnown) {
			$query['veaction'] = 'edit';
			$query['action'] = 'view'; // prevent MediaWiki from overriding veaction
		}
	}
}

$wgHooks['HtmlPageLinkRendererBegin'][] = 'MyHooks::onHtmlPageLinkRendererBegin';
Sophivorus (talkcontribs)

Excellent work guys! This thread solved all my redlink problems XD Here is a shortened version of the snippet for those like me who don't like any fat in their code.

$wgHooks['HtmlPageLinkRendererBegin'][] = function ( $linkRenderer, $target, &$text, &$extraAttribs, &$query, &$ret ) {
	$title = Title::newFromLinkTarget( $target );
	if ( !$title->isKnown() ) {
		$query['veaction'] = 'edit';
		$query['action'] = 'view'; // Prevent MediaWiki from overriding veaction
	}
};
Aravind2905 (talkcontribs)

Thanks to @Beatlicker from the post Enable All Name space see this --> Topic:Spky5rat787g67fj

Add blow lines to your LocalSettings.php page

$wgVisualEditorNamespaces = array_merge( $wgContentNamespaces, array( NS_USER, NS_CATEGORY ) );

$wgVisualEditorAvailableNamespaces = [

    NS_MAIN => true,

    NS_USER => true,

NS_HELP => true,

    "_merge_strategy" => "array_plus"

];

If you need other standard namespace see Help:Namespaces to added standard that enable VisualEditor all the pages. Hope this Helps.

2001:4641:F835:0:5CFB:CDD6:6C21:37BA (talkcontribs)

This did not work, is there more to the instructions?@Aravind2905

Tinss (talkcontribs)

What are you trying to achieve? If it's enabling the Visual Editor for the create page, put Sophivorus' code at the bottom of LocalSettings.php.

Reply to "Enable VisualEditor for 'create' page"