Monday, October 18, 2010

Media Wiki - Upload file configuration

To enable uploading of files on media wiki, first enable the settings on PHP.INI

file_uploads = On

Then on your LocalSettings.php (under wiki site root folder), apply these changes:

Turn on the file upload:

$wgEnableUploads   = true

Set your upload directory. This is where your uploaded files will be saved:

$wgUploadDirectory = "c:/Sites/PHP/mediawiki-1.16.0/uploads";

Set your upload url. This is the url to use for downloading your files.

$wgUploadPath  = $wgScriptPath."/uploads";
For example: http://wiki.mysite.com/uploads/myfile.txt.

To modify the file types that can be uploaded:
$wgFileExtensions = array_merge($wgFileExtensions, array('doc', 'xls'));



To access the upload page, add this string on the url:

index.php?title=Special:Upload

For example:

http://wiki.mysite.com/index.php?title=Special:Upload


If you want some advanced configurations on file uploads such as setting upload size limit, file types, etc, you can find it on their media wiki's website.

Media Wiki - Edit navigation/menu

Add this string on your url: index.php?title=MediaWiki:Sidebar

For example:

http://wiki.mysite.com/index.php?title=MediaWiki:Sidebar

Apache - Add authentication on site

To enable login on your site, you need two files:

1. .htpasswd - can be saved anywhere as long as it's secure
2. .htaccess - must be on the root directory of the site

On your .htpasswd, define the username and password on this format:

username:password

On your .htaccess, have these lines:

AuthUserFile "C:/wamp/pwds/.htpasswd"
AuthName "Valid Users"
AuthType Basic
require valid-user

Sunday, October 3, 2010

C# get credit card type

Usage:

String cardType = CreditCardUtility.GetTypeName("4111 1111 1111 1111");

This will return "Visa"

Here is the full code (or you can just copy the lines of code that you need):


/** CreditCardUtility.cs ***/ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

using System.Collections.Specialized; namespace CreditCard
{
    public class CreditCardUtility
    {
        protected static CreditCardUtility _instance = new CreditCardUtility();
        protected CreditCard _card;
        public CreditCard Card
        {
            get
            {
                if (this._card == null)
                    this._card = new CreditCard();
                return this._card;
            }
            set
            {
                this._card = value;
            }
        }
        public static CreditCardUtility Instance
        {
            get
            {
                if(_instance == null)
                    _instance = new CreditCardUtility();
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }

        private CreditCardUtility()
        {
        }

        static CreditCardUtility()
        {
        }

        public static String GetTypeName(String cardNumber)
        {
            return Instance.Card.GetCardType(cardNumber);   
        }
    }
} 
/** CreditCard.cs ***/  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Text.RegularExpressions;

namespace CreditCard
{
    public class CreditCard
    {
        //http://www.regular-expressions.info/creditcard.html
        //# Visa: ^4[0-9]{12}(?:[0-9]{3})?$ All Visa card numbers start with a 4. New cards have 16 digits. Old cards have 13.
        //# MasterCard:  All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
        //# American Express: ^3[47][0-9]{13}$ American Express card numbers start with 34 or 37 and have 15 digits.
        //# Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{11}$ Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits. There are Diners Club cards that begin with 5 and have 16 digits. These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.
        //# Discover: ^6(?:011|5[0-9]{2})[0-9]{12}$ Discover card numbers begin with 6011 or 65. All have 16 digits.
        //# JCB: ^(?:2131|1800|35\d{3})\d{11}$ JCB 

        public const String AMEXPattern = @"^3[47][0-9]{13}$";
        public const String MasterCardPattern = @"^5[1-5][0-9]{14}$";
        public const String VisaCardPattern = @"^4[0-9]{12}(?:[0-9]{3})?$";
        public const String DinersClubCardPattern = @"^3(?:0[0-5]|[68][0-9])[0-9]{11}$";
        public const String enRouteCardPattern = @"^(2014|2149)";
        public const String DiscoverCardPattern = @"^6(?:011|5[0-9]{2})[0-9]{12}$";
        public const String JCBCardPattern = @"^(?:2131|1800|35\d{3})\d{11}$";

        protected NameValueCollection _patterns;
        public NameValueCollection CardPatterns
        {
            get
            {
                if(this._patterns == null)
                {
                    this._patterns = new NameValueCollection();
                    this._patterns.Add("AMEX",AMEXPattern);
                    this._patterns.Add("MasterCard",MasterCardPattern);
                    this._patterns.Add("Visa",VisaCardPattern);
                    this._patterns.Add("DinersClub",DinersClubCardPattern);
                    this._patterns.Add("enRoute",enRouteCardPattern);
                    this._patterns.Add("Discover",DiscoverCardPattern);
                    this._patterns.Add("JCB",JCBCardPattern);

                }
                return this._patterns;
            }
            set
            {
                this._patterns = value;
            }
        }

        public CreditCard()
        {
        }

        public String GetCardType(String cardNumber)
        {
            
            String cardType = "Unknown";
            
            try
            {
                String cardNum = cardNumber.Replace(" ", "").Replace("-", "");
                Regex regex;
                foreach (String cardTypeName in this.CardPatterns.Keys)
                {
                    regex = new Regex(this.CardPatterns[cardTypeName]);
                    if (regex.IsMatch(cardNum))
                    {
                        cardType = cardTypeName;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return cardType;

        }
    }
}

Friday, October 1, 2010

Root directory as subdirectory

One way to point your root directory to a subdirectory, you need these lines on your .htaccess file on the root directory:


Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^httpdocs/
RewriteRule ^(.*)$ /httpdocs/$1 [L]