Extension:Add Article to Category

From MediaWiki.org
Jump to: navigation, search

Other languages:
Deutsch • ‎English • ‎français • ‎italiano • ‎日本語 • ‎한국어 • ‎मराठी • ‎occitan • ‎polski • ‎中文
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
Add Article to Category

Release status:Extension status stable

Add Article To Category Extension.jpg
ImplementationTemplate:Extension#type Page action
DescriptionTemplate:Extension#description Adds an inputbox (to create a new article) to each category page. The content of the new page will contain "[[Category:]]" automatically.
Author(s)Template:Extension#username Liang Chen (BiGreattalk)
Latest versionTemplate:Extension#version 0.1.9 (2007-01-19)
MediaWikiTemplate:Extension#mediawiki 1.8+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license MIT License
Download See the code section
Hooks usedTemplate:Extension#hook

Translate the Add Article to Category extension if it is available at translatewiki.net

Check usage and version matrix.

The Add Article to Category extension adds an inputbox (to create a new article) to each category page. The content of new page will contain "[[Category:]]" automatically.


  • Copy the code into ArticleToCategory.php and place the file(s) in a directory called ArticleToCategory in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/ArticleToCategory/ArticleToCategory.php";
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


A Liang Chen's Extension for MediaWiki
Add Article to Category
Release Date: 2007/01/19
Update Date: 2007/03/09 to 0.1.9, fix a bug in zip file which may cause problem in style.
Contact: code@chen.technology
Demo: kaoshi.wobuxihuan.org

if( !defined( 'MEDIAWIKI' ) ) {

$wgExtensionCredits['other'][] = array(
    'name' => 'Add Article to Category',
    'description' => 'Provides an inputbox on each category page that allows to create a new page that is directly put into that category',
    'author' => 'Liang Chen',
     'url' => 'https://www.mediawiki.org/wiki/Extension:Add_Article_to_Category'

$wgHooks['EditFormPreloadText'][] = 'addcategory';
$wgHooks['CategoryPageView'][] = 'categorychange';

function addcategory(&$text)
    if(!array_key_exists('category', $_GET))
        return true;
    $cname = $_GET['category'];
    $wnew = $_GET['new'];
    global $wgContLang;

    if ($wnew==1)
        $ns = $wgContLang->getFormattedNsText(NS_CATEGORY);
        $text ="Add Your Content Here\r\n\r\n[[$ns:".$cname."]]";
    return true;

function categorychange($catpage)
    $boxtext  = "Create an Article in this category"; 
    $btext = "Submit";
    global $wgOut;
    global $wgScript;	
    $Action = htmlspecialchars( $wgScript );		
<!-- Add Article Extension Start -->
<script type="text/javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
function addText(thefield){
	if (thefield.value=="")
	thefield.value = thefield.defaultValue 
<table border="0" align="right" width="423" cellspacing="0" cellpadding="0">
<td width="100%" align="right" bgcolor="">
<form name="createbox" action="{$Action}" method="get" class="createbox">
	<input type='hidden' name="action" value="edit">
	<input type='hidden' name="new" value="1">
	<input type='hidden' name="category" value="{$catpage->mTitle->getText()}">

	<input class="createboxInput" name="title" type="text" value="{$boxtext}" size="30" style="color:#666;" onfocus="clearText(this);" onblur="addText(this);"/>	
	<input type='submit' name="create" class="createboxButton" value="{$btext}"/>	
<!-- Add Article Extension End -->
	return true;


If you want the option to not have the box on some pages, see Extension talk:Add_Article_to_Category/Archive_1#Added functionality to exclude some categories

See also[edit]


Category page
Edit page