Jump to content

Extension talk:NewArticleTemplates

Add topic
From mediawiki.org

article and user page templates

[edit]

i want two custom templates...it works for the article...but how to add USER PAGE namespace?

$wgNewArticleTemplatesNamespaces = array(
        NS_MAIN                 => 1,
        100                     => 1,
        102                     => 1,
        104                     => 1,
        106                     => 1,

        NS_USER                 => 2,
        100                     => 2,
        102                     => 2,
        104                     => 2,
        106                     => 2
);
 
# new pages in the main namespace use MediaWiki:NewArticleTemplate:
$wgNewArticleTemplates_PerNamespace = array(
        NS_MAIN                 => "MediaWiki:NewArticleTemplate",
        NS_USER                 => "MediaWiki:NewArticleTemplateUser",
);


Preloader for Image/Media Upload

[edit]

Does the extension work with NS_IMAGE? Thank you for any replying. :-) --Roc michael 22:59, 11 May 2008 (UTC)Reply

Oo.et.oO 18:35, 12 August 2008 (UTC):Reply
Hi Roc michael,
I added:
         NS_IMAGE                => 1,
to $wgNewArticleTemplatesNamespaces and it works... kinda. when adding an article named "Image:fake_test.jpg" the article used the template specified (in this case : $wgNewArticleTemplatesDefault). Of course after the article creation it says that no such file exists.
However, using the "Upload file" link in the toolbox does not use the template.
i might also find that useful if i need users to always put certain markup in the "summary".
where would you have the template add the preload markup? in the "summary" box?
anyone else have comments on how it would work with upload file?

Download error

[edit]

Hi Mati, When I tried to download the extension, I will see the following message:

Not Found
The requested URL /mediawiki/trunk/NewArticleTemplates was not found on this server.
Oo.et.oO 18:09, 12 August 2008 (UTC): works for me using both the download http link as well as subversion.Reply

merging of extensions?

[edit]

I'm the author of the extension described on the subject-page. The See-Also chapter had this added:

Perhaps Extension:Preloader, Extension:PreloadManager, Extension:NewArticleTemplates and Extension:Boilerplate should be merged?

I skimmed through the other extensions and couldn't find much functionality that is not provided by this extension. If there is functionality that would be "nice to have" in this extension and exists in other extensions, I'm happy to integrate them here - so please post suggestions here. It would also be ok to move it to the MediaWiki SVN, if the MediaWiki-team would like that. Let me know what you think! -- Mati 11:14, 12 October 2008 (UTC)Reply


You have a error in you PHP code

[edit]
       NS_MAIN                 => "MediaWiki:NewArticleTemplate",

should be

       NS_MAIN                 => "MediaWiki:NewArticleTemplate"
actually, thats not an error. PHP accepts the coma after the last element in an array. This eases code-maintenance, i.e. consider this:
$arr = array (
    "first" => 1,
    "second" => 2,
    "third" => 3,
); # to err is human, to arr is pirate!
In this code, you can safely add another line at the end and the code still works. If you comment the last line out, again, there is no problem with php. -- Mati 17:33, 12 November 2008 (UTC)Reply

Quick & Dirty patch to add page's name to the template

[edit]

Thanks for the great extension! I needed a way to put the new page's name into the template text (I'm calling another template that uses {{PAGENAME}} in a comparison) and I couldn't see any obvious way to do this, so I made a very quick patch:

Index: NewArticleTemplate.php
===================================================================
--- NewArticleTemplate.php	(revision 328)
+++ NewArticleTemplate.php	(working copy)
@@ -79,8 +79,9 @@
 				$template = $template . '/Subpage';
 			}
 		}
-
-		$newPage->textbox1 = preload( $template );
+		$templateText = preload( $template );
+		$templateText = str_replace("__PAGENAME__", $title->getText(), $templateText);
+		$newPage->textbox1 = $templateText;
 #			$newPage->textbox1 = preload($wgNewArticleTemplatesDefault);
 	}
 	return true;

This can be easily modified to mangle the text in any way you please.

Danielsoneg 01:16, 27 February 2010 (UTC)Reply

How can i make this extension working for Categories ?

[edit]

Hi,

I'm a newbie in mediaWiki and i need such that extension for customizing special categories like Category:People or Category:Book. is it possible to use this extension for that kind ?

Thank's in advance for any reply

It is working on MW 1.27?

[edit]

Does anybody if this extension if it working for MW 1.27?

Thanks!

It likely worked on MW 1.28 but definitely does not work on MW 1.29. This extension and the Preloader extension both break with error Call to undefined method Revision::getText(). The best alternative I could find is MultiBoilerplate though that extension does not have per-namespace templates and instead uses a dropdown box listing available boilerplate items by name. Alchemistmatt (talk) 20:30, 24 July 2017 (UTC)Reply
It is definitely broken in 1.29. If you're comfortable editing PHP code, I fixed it by replacing the line $text = $rev->getText(); with the following two lines in the NewArticleTemplate.php file:
  • $content = $rev->getContent( Revision::RAW );
  • $text = ContentHandler::getContentText( $content );

Hope this helps.

Yes, with my MediaWiki 1.30 the codechange worked. I have requested a Pull

[edit]

Error:

[WvT9tp-H9f-dyfteCeIq0AAAAFE] /index.php?title=Tag:Baloney&action=edit&redlink=1 Error from line 25 of /home/gunsywtx/public_html/extensions/NewArticleTemplate/NewArticleTemplate.php: Call to undefined method Revision::getText()

Backtrace:
#0 /home/gunsywtx/public_html/extensions/NewArticleTemplate/NewArticleTemplate.php(87): preload(string)
#1 /home/gunsywtx/public_html/includes/Hooks.php(177): newArticleTemplates(EditPage, OutputPage)
#2 /home/gunsywtx/public_html/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#3 /home/gunsywtx/public_html/includes/EditPage.php(2657): Hooks::run(string, array)
#4 /home/gunsywtx/public_html/includes/EditPage.php(689): EditPage->showEditForm()
#5 /home/gunsywtx/public_html/includes/actions/EditAction.php(60): EditPage->edit()
#6 /home/gunsywtx/public_html/includes/MediaWiki.php(499): EditAction->show()
#7 /home/gunsywtx/public_html/includes/MediaWiki.php(293): MediaWiki->performAction(Article, Title)
#8 /home/gunsywtx/public_html/includes/MediaWiki.php(851): MediaWiki->performRequest()
#9 /home/gunsywtx/public_html/includes/MediaWiki.php(523): MediaWiki->main()
#10 /home/gunsywtx/public_html/index.php(43): MediaWiki->run()
#11 {main}

Steps:

  1. Install the extension
  2. localsettings.php:
require_once ("$IP/extensions/NewArticleTemplate/NewArticleTemplate.php");
$wgNewArticleTemplatesEnable = true;

# enable on subpages:
$wgNewArticleTemplatesOnSubpages = true;

# Templates are used in these namespaces:
$wgNewArticleTemplatesNamespaces = array(
        NS_TAG                 => 1);

# new pages in the main namespace use MediaWiki:NewArticleTemplate:
$wgNewArticleTemplates_PerNamespace = array(
        NS_TAG                 => "Template:Tag/Preload",
);

# new pages in any other namespace defined by $wgNewArticleTemplatesNamespaces use MediaWiki:NewArticleTemplateDefault:
# $wgNewArticleTemplatesDefault = "MediaWiki:NewArticleTemplateDefault";
  1. Place a link or transclude on a page:
[[Tag:Baloney]]
{{Tag:Baloney}}
  1. click the link or transclude

Setting for namespaces ignored in 1.3 & MediaWiki 1.35.4 [BUG, SOLVED]

[edit]

Unfortunately, this extension seems to fully ignore any settings in $wgNewArticleTemplatesNamespaces and $wgNewArticleTemplatesPerNamespace. Template is applied only to NS_MAIN, even if this namespace is missing in $wgNewArticleTemplatesNamespaces. Sample of my code follows:

# Templates are used in these namespaces:
$wgNewArticleTemplatesNamespaces = [
  3000  => 1
];

# new pages in the main namespace use MediaWiki:NewArticleTemplates
$wgNewArticleTemplatesPerNamespace = array(
  3000 => "MediaWiki:NewArticleTemplate",
);

--Radouch (talk) 08:32, 29 November 2021 (UTC)Reply

Now I know the cause. There is bug in extension.json. Change default values for NewArticleTemplatesNamespaces and NewArticleTemplatesPerNamespace from [] to null in this file, see below:
 "NewArticleTemplatesNamespaces": {
   "value": null, // instead of []
   "description": "Templates are used in these namespaces"
  },
  "NewArticleTemplatesPerNamespace": {
    "value": null, // instead of []
    "description": "Mapping template namespaces for page namespaces"
  },
--Radouch (talk) 11:32, 29 November 2021 (UTC)Reply