<?php
/*--------------------------------------------
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: anything@liang-chen.com
Demo: kaoshi.wobuxihuan.org
Download: http://www.liang-chen.com/myworld/content/view/36/70/
--------------------------------------------
* Extended by Cynthia Mattingly @ Marketing Factory Consulting
* Add Category under Category added
* Localisation file created and built in
*
*/
if( !defined( 'MEDIAWIKI' ) )
die();
$wgExtensionCredits['other'][] = array(
'name' => 'Add Article to Category',
'description' => 'Your MediaWiki will get an inputbox on each Category page, and you can create a new article directly to that category',
'author' => 'Liang Chen The BiGreat',
'url' => 'http://www.liang-chen.com/myworld/content/view/36/70/'
);
$wgHooks['EditFormPreloadText'][] = 'addcategory';
$wgHooks['CategoryPageView'][] = 'categorychange';
$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['AddArticleToCategory'] = $dir . 'AddArticleToCategory.i18n.php';
function addcategory(&$text)
{
wfLoadExtensionMessages( 'AddArticleToCategory' );
if ( array_key_exists('category', $_GET) && array_key_exists('new', $_GET)) {
$cname = $_GET['category'];
$wnew = $_GET['new'];
if ($wnew==1)
{
$text = "\n\n [[category:".$cname."]]";
}
}
return true;
}
function categorychange($catpage)
{
global $wgContLang;
wfLoadExtensionMessages( 'AddArticleToCategory' );
$boxtext = wfMsg( 'createarticleundercategory_text' );
$btext = wfMsg( 'createarticleundercategory_button' );;
$boxtext2 = wfMsg( 'createcategoryundercategory_text' );
$btext2 = wfMsg( 'createcategoryundercategory_button' );;
global $wgOut;
global $wgScript;
$Action = htmlspecialchars( $wgScript );
$cattitle = $wgContLang->getNsText( NS_CATEGORY );
$temp2=<<<ENDFORM
<!-- Add Article Extension Start - P by BiGreat-->
<script type="text/javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
function addText(thefield){
if (thefield.value=="")
thefield.value = thefield.defaultValue
}
function addTextTitle(thefield){
if (thefield.value=="") {
thefield.value = thefield.defaultValue;
} else {
thefield.value = '{$cattitle}:'+thefield.value;
}
}
</script>
<table border="0" align="right" width="423" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="right" bgcolor="">
<form name="createbox" action="{$Action}" onsubmit="addTitle('createboxInput')" 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="38" style="color:#666;" onfocus="clearText(this);" onblur="addText(this);"/>
<input type='submit' name="create" class="createboxButton" value="{$btext}"/>
</form>
<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="{$boxtext2}" size="38" style="color:#666;" onfocus="clearText(this);" onblur="addTextTitle(this);"/>
<input type='submit' name="create" class="createboxButton" value="{$btext2}"/>
</form>
</td>
</tr>
</table>
<!-- Add Article Extension End - P by BiGreat-->
ENDFORM;
$wgOut->addHTML($temp2);
return true;
}
?>