Extension:Add Article to Category

From MediaWiki.org
Jump to: navigation, search
Language: English  • français • 中文
MediaWiki extensions manual - list
Crystal Clear action run.png
Add Article to Category

Release status: stable

Add Article To Category Extension.jpg
Implementation Page action
Description Adds an inputbox (for create new article) to each category page. The content of new page will contain "[[category:]]" automatically.
Author(s) Liang Chen The BiGreat (BiGreattalk)
Last version 0.1.9 (2007-01-19)
MediaWiki 1.8 +
License No license specified
Download below and on liang-chen.com
Example kaoshi.wobuxihuan.org (demo)or Hindupedia
Hooks used
EditFormPreloadText

CategoryPageView

Check usage and version matrix

Add the ability to add an inputbox (for create new article) to each category page. The content of new page will contain "[[category:]]" automatically.

Contents

Install [edit]

  1. Download the extension here or in the section below.
  2. Upload the articletocategory.php to your extensions/ directory.
  3. Add require_once("$IP/extensions/articletocategory.php"); to your LocalSettings.php file (near the end).
  4. Done

Screenshots [edit]


Screenshot 1
Category Page
Screenshot 2
Edit Page

Update [edit]

03/09 -- Fix a bug in the zip file, please download again.

Code [edit]

  1. <?php
    
  2. /*--------------------------------------------
    
  3. A Liang Chen's Extension for MediaWiki
    
  4. Add Article to Category
    
  5. Release Date: 2007/01/19
    
  6. Update Date: 2007/03/09 to 0.1.9, fix a bug in zip file which may cause problem in style.
    
  7. Contact: anything@liang-chen.com
    
  8. Demo: kaoshi.wobuxihuan.org
    
  9. Download: http://www.liang-chen.com/myworld/content/view/36/70/
    
  10. --------------------------------------------*/
    
  11.  
    
  12.  
    
  13. if( !defined( 'MEDIAWIKI' ) )
    
  14. die();
    
  15.  
    
  16. $wgExtensionCredits['other'][] = array(
    
  17.     'name' => 'Add Article to Category',
    
  18.     'description' => 'Your MediaWiki will get an inputbox on each Category page, and you can create a new article directly to that category',
    
  19.     'author' => 'Liang Chen The BiGreat',
    
  20.      'url' => 'http://www.liang-chen.com/myworld/content/view/36/70/'
    
  21. );
    
  22. $wgHooks['EditFormPreloadText'][] = 'addcategory';
    
  23. $wgHooks['CategoryPageView'][] = 'categorychange';
    
  24. function addcategory(&$text)
    
  25. {
    
  26.         $cname = $_GET['category'];
    
  27.         $wnew = $_GET['new'];
    
  28.         global $wgContLang;
    
  29.  
    
  30.         if ($wnew==1)
    
  31.         {
    
  32.                  $ns = $wgContLang->getFormattedNsText(NS_CATEGORY);
    
  33.                  $text ="Add Your Content Here\r\n\r\n[[$ns:".$cname."]]";
    
  34.         }
    
  35.         return true;
    
  36. }
    
  37.  
    
  38.  
    
  39.  
    
  40. function categorychange($catpage)
    
  41. {
    
  42.  
    
  43.         $boxtext  = "Create an Article in this category"; 
    
  44.         $btext = "Submit";
    
  45.         global $wgOut;
    
  46.         global $wgScript;       
    
  47.         $Action = htmlspecialchars( $wgScript );                
    
  48.  
    
  49.  
    
  50.  
    
  51. //$wgOut->addWikiText( "Test");
    
  52. $temp2=<<<ENDFORM
    
  53. <!-- Add Article Extension Start - P by BiGreat-->
    
  54. <script type="text/javascript">
    
  55. function clearText(thefield){
    
  56. if (thefield.defaultValue==thefield.value)
    
  57. thefield.value = ""
    
  58. } 
    
  59. function addText(thefield){
    
  60.         if (thefield.value=="")
    
  61.         thefield.value = thefield.defaultValue 
    
  62. }
    
  63. </script>
    
  64. <table border="0" align="right" width="423" cellspacing="0" cellpadding="0">
    
  65. <tr>
    
  66. <td width="100%" align="right" bgcolor="">
    
  67. <form name="createbox" action="{$Action}" method="get" class="createbox">
    
  68.         <input type='hidden' name="action" value="edit">
    
  69.         <input type='hidden' name="new" value="1">
    
  70.         <input type='hidden' name="category" value="{$catpage->mTitle->getText()}">
    
  71.  
    
  72.         <input class="createboxInput" name="title" type="text" value="{$boxtext}" size="30" style="color:#666;" onfocus="clearText(this);" onblur="addText(this);"/>    
    
  73.         <input type='submit' name="create" class="createboxButton" value="{$btext}"/>   
    
  74. </form>
    
  75. </td>
    
  76. </tr>
    
  77. </table>
    
  78. <!-- Add Article Extension End - P by BiGreat-->
    
  79. ENDFORM;
    
  80. $wgOut->addHTML($temp2);
    
  81.         return true;
    
  82. }
    

DEMO [edit]

Tweaks [edit]

If you want the option to not have the box on some pages, see Extension talk:Add Article to Category #Added functionality to exclude some categories


See also [edit]