Edit Page Templates

From ChekMate Security Group

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

Contents

Installing the Hack

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

Step 1: Create MediaWiki:StartingText

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:Noarticletext

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 explainations on what each starting text is used for.

Step 3: Edit EditPage.php

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 4: Modify MakeBrokenLinkObj (Optional)

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 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: Test

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