Talk:Multiple starting text hack

From Meta, a Wikimedia project coordination wiki

Different Starting Text for Different Namespaces[edit]

Would it be possible (without MAJOR code changes) to make different namespaces have different default starting text? Does anyone have ideas on how to go about coding that? Jon the Geek 22:15, 22 August 2005 (UTC)[reply]

Absolutely. What I did (being an absolute php/sql/etc n00b) was to take the "Newbug" starttext link below:
** With NewBug starting text
and change it to:
** With appropriate starting text
In other words, changing the &starttext=NewBug to &starttext={{NAMESPACE}}_StartText
I realize that's not a very pretty solution, but it works fine for me. Lemme know if that helps or if I messed anything up explaining it.
Kalisphoenix 00:46, 27 August 2005 (UTC)[reply]
Looks good to me. --ProgMania 23:20, 31 August 2005 (UTC)[reply]


Using a seperate namespace for the starting text templates[edit]

I decided to put all my starting text articles in a seperate namespace, instead of using the messages (MediaWiki:) namespace. Here's how: (MediaWiki version 1.5rc4)

  • Edit LocalSettings.php:
INSERT:
# Starting Text Namespace
$wgExtraNamespaces = array();
$wgExtraNamespaces[100] = 'Starting_Text';
$wgExtraNamespaces[101] = 'Starting_Text_Notes';

(Change the numbers if you have others, just follow the normal rules.)

  • Edit includes/EditPage.php:
FIND:
function editForm( $formtype, $firsttime = false ) {

INSERT (AFTER):
global $wgRequest;

$startText = '';

FIND:
if($addstandardintro) {
	$wgOut->addWikiText(wfmsg('newarticletext'));				
}

INSERT (AFTER):
if (!$this->preview) {
	$startText = $wgRequest->getVal('starttext', '');
	if ($startText != '') {
		$startText = Article::getPreloadedText('Starting Text:'.$startText);
	}
}

FIND:
. htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) .

REPLACE WITH:
. htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) . $startText ) .
  • Create links as before, not including the "Starting_Text:" namespace prefix:
[{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit&starttext=Software}} New Software Page]

becomes: New Software Page using the template Starting_Text:Software


Please let me know if you spot any bugs - I only just came up with it and it's gone midnight!

--ProgMania 23:20, 31 August 2005 (UTC)[reply]

Works stunningly well.
Kalisphoenix 13:30, 28 September 2005 (UTC)[reply]

Does it matter what $wgGoToEdit is?[edit]

If you're having trouble -- check this...

You (may) also need to have $wgGoToEdit = false; in LocalSettings.php or DefaultSettings.php. In 1.5, it defaults to being false, but if you changed it it will take you to the edit page before the Noarticletext page. The default in DefaultSettings.php for 1.5: /** Go button goes straight to the edit screen if the article doesn't exist. */ $wgGoToEdit = false;

This did not work for me. Any ideas?[edit]

I'm using MW 1.5.5 installed at home on windows and using xampp. I followed the instructions with a minor modification. It must be an update in MW 1.5.5. The funtion

if(!$this->mTitle->getArticleID()) { # new article

is slightly different. I have:

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

Any ideas why this doesn't work? Steveire 20:46, 16 February 2006 (UTC)[reply]

Update for newer version?[edit]

has anyone updated this to work on Mediawiki 1.6.5?

Yes. I applied the description to 1.7.1, and it works. 213.157.0.90 10:58, 12 October 2006 (UTC)[reply]

This would be GREAT, but when looking in the EditPage.php in version 1.8.2 the code is different and I'm not programmer savvy enough to be able to figure it out. Can someone post an update? Thanks --Jmaas 01:06, 23 January 2007 (UTC)[reply]

I am using version 1.9.1. I did all the steps (including step 3b, and not 3a), but unfortunately it did not work correctly. Not the text of article NewX was shown in textbox1, but the following text was shown: <NewX>, where NewX was the value which was posted for StartTest. I found a solution: I replaced

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

with

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


I think getPreloadedText was not designed to do this task. Unfortunately I to not understand the MediaWiki code good enough to judge if this is a stable solution.

How does it compare to Extension:Preloader?[edit]

Is there an advantage over Extension:Preloader? Thanks! -79.179.190.96 02:17, 24 November 2007 (UTC)[reply]

Does it use the official preload technique?[edit]

Should it be mentioned in the official preloading manual? -79.179.111.10 12:10, 28 November 2007 (UTC)[reply]

Extension:Boilerplate[edit]

I successfully modified extension Boilerplate to replace step 3. Only tested in version 1.11.0.


<?php

$wgHooks['EditPage::showEditForm:initial'][] = array('boilerplate');

function boilerplate($editpage) {

    // EditFormPreloadText
    global $wgOut; global $wgRequest;

    $wgOut->enableClientCache(false);

    if (!$editpage->preview
        && !$editpage->mArticle->mContentLoaded
        && $editpage->mArticle->mTitle->mNamespace==0) {

         $startText = $wgRequest->getVal( 'starttext', '');
         if ('' != $startText) {
          $boilerplate_title = Title::newFromText($startText);
          $boilerplate_article = new Article($boilerplate_title);
          $editpage->textbox1=$boilerplate_article->GetContent();
          $editpage->textbox2=$editpage->textbox1;
         }
    }

    return true;

}

?>