Starting text hack

From Meta, a Wikimedia project coordination wiki

This hack starts each new article with a default set of text when someone chooses "edit". This hack may be useful for wikis in which most articles will have the same general layout, especially if the contributors are new to wikis and may not know all of the markup.

Installing the Hack[edit]

This hack is relatively simple to install.

Step 1: Create MediaWiki:New[edit]

First, create MediaWiki:New in your wiki. 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 EditPage.php[edit]

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 = '';

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.

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 = htmlspecialchars(wfMsgForContent("new"));
}

So the overall statement now looks like this:

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

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:New will be added to the editing textbox. Otherwise, nothing is added.

Step 3: Upload and Test[edit]

If you worked on a local copy of EditPage.php, upload this file to your live includes directory. Try editing a new article and an old article, and confirm that the hack works as intended.