Multiple starting text hack

This is a quick and simple hack of starting text hack. Starting text hack only allows one set of starting text. For this mod, when you click on a wiki page that does not exist, a page will be shown allowing you to add the page with blank text, or any available start texts.
This feature is also present in MoinMoin http://moinmoin.wikiwikiweb.de/MoinMoinBugs/pagetemplatessdfs

Installing the HackEdit

This hack should be quite easy to install. (Installation instructions modified from Starting text hack)

Step 1: Create MediaWiki:StartingTextEdit

First, create the different starting texts that you want, e.g. MediaWiki:NewFeature, MediaWiki:NewBug, MediaWiki:NewFilm. You will have to login as an administrator to create this page. The page should include whatever text and formatting should appear by default in each article.

Step 2: Edit MediaWiki:NoarticletextEdit

This page is shown when a page that does not exist is visited. Sample template is as shown.. (Modified from wikipedia)


This article does not exist


Source

 '''This article does not exist'''
 * [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit|}} Start the {{PAGENAME}} article]
 ** With [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit&starttext=NewBug|}} NewBug starting text]
 ** With [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit&starttext=NewFeature|}} NewFeature starting text] 
 * [[{{ns:special}}:Search/{{PAGENAME}}|Search for {{PAGENAME}}]] in other articles.
 * [[Wikipedia:{{NAMESPACE}}:{{PAGENAME}}|Look for {{PAGENAME}}]] in Wikipedia

You can also add some explanations on what each starting text is used for.

Step 3a: Edit EditPage.phpEdit

This step will enable you to type in a new article in the address bar and choose a template.



Edit includes/EditPage.php. Warning: editing this file could lead to problems throughout your wiki, so be very careful.

Find function editForm. In the list of variables at the top of this function, add this:

$startText = '';
global $wgRequest;

Find an if statement that looks like this:

if(!$this->mTitle->getArticleID()) { # new article
 $wgOut->addWikiText(wfmsg('newarticletext'));
}

Within that statement, nest this if statement:

if(!$this->preview) {
 $startText = $wgRequest->getVal( 'starttext', '');
 if ('' != $startText) {
  $startText = htmlspecialchars(wfMsgForContent($startText));
 }
}

So the overall statement now looks like this:

if(!$this->mTitle->getArticleID()) { # new article
 $wgOut->addWikiText(wfmsg('newarticletext'));
 if(!$this->preview) {
  $startText = $wgRequest->getVal( 'starttext', '');
  if ('' != $startText) {
   $startText = htmlspecialchars(wfMsgForContent($startText));
  }
 }
}

Finally, find the first textarea block of code:

<textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
 cols='{$cols}'{$ew}>" .
 htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) . 
 "
</textarea>

Between the . and ", add $startText ., so now you have this:

<textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
 cols='{$cols}'{$ew}>" .
 htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) . $startText .
 "
</textarea>

If the article is new and not being previewed, the contents of MediaWiki:$starttext will be added to the editing textbox. Otherwise, nothing is added.

Step 3b: Edit EditPage.php - Version 1.6.6 and 1.7.1Edit

The layout of EditPage.php in 1.6.5 appears to be the same as version 1.6.6. However, these changes have not been tested.

In version 1.6.6 function editForm does not exist. Instead, you need to edit function edit.

After the global declarations at the start of the function, insert the following

global $startText;
$startText='';

Note: $wgRequest has already been defined.

Find the line:

if(!$this->mTitle->getArticleID() && ('initial' == $this->formtype || $this->firsttime )) { # new article 

and after the line:

$this->showIntro();

insert:

if(!$this->preview) {
 $startText = $wgRequest->getVal( 'starttext', '');
 if ('' != $startText) {
  $startText = htmlspecialchars(wfMsgForContent($startText));
 }
}

Now the block looks like this:

if(!$this->mTitle->getArticleID() && ('initial' == $this->formtype || $this->firsttime )) { # new      article
this->showIntro();
if(!$this->preview) {
 $startText = $wgRequest->getVal( 'starttext', '');
 if ('' != $startText) {
  $startText = htmlspecialchars(wfMsgForContent($startText));
 }
}

Remark: If you are planning to use template inclusions in your starting text, it will be better to use wfMsgForContentNoTrans instead of wfMsgForContent.

In function showEditForm, after the global declarations at the start of the function, insert the following

global $startText; 

Then, find the line:

htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) 

and add the $startText variable to give you this:

. htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) .$startText .

Step 4: Modify MakeBrokenLinkObj (Optional)Edit

Mediawiki makes a link to a wikipage that does not exist go directly to the edit page. This modification makes it display the MediaWiki:Noarticletext page.

Edit includes/Skin.php (or includes/Linker.php for 1.5 and 1.7.1) In function MakeBrokenLinkObj, replace

$q = 'action=edit'; 

with

$q = '';

and

$q = 'action=edit&'.$query; 

with

$q = $query;

Alternatively, you can edit the MediaWiki:Newarticletext to add a link to the MediaWiki:Noarticletext. Something like this:

 You've followed a link to a page that doesn't exist yet.
 To create the page, start typing in the box below
 ([[Project:Help|More info]] or [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}}} More Options])
 If you are here by mistake, just click your browser's '''back''' button.

Step 5: Edit Article.php (optional)Edit

This has been tested for 1.7.1 only

If your users use different interface languages in their preferences, it can be helpful to use the same Noarticletext message for all of them. Otherwise, you will have to manage different messages for all languages. To achieve this, edit the file includes/Article.php. Find function getContent. In this function, change the line

$ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );

to

$ret = wfMsgForContent( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );

Step 6: TestEdit

Try editing a new article and an old article, and confirm that the hack works as intended.