2011 January, 28 (Guerric)

    Table of contents
    No headers
    // Paste PHP Code
    Index: deki_ban.php
    ===================================================================
    --- deki_ban.php	(revision 24907)
    +++ deki_ban.php	(working copy)
    @@ -26,6 +26,10 @@
     
     class DekiBan implements IDekiApiObject
     {
    +	const BAN_MASK = 'BROWSE,READ,SUBSCRIBE,UPDATE,CREATE,DELETE,CHANGEPERMISSIONS,CONTROLPANEL,ADMIN';
    +	const TYPE_USER = 'username';
    +	const TYPE_IP = 'ip';
    +	
     	private $id = null;
     	private $ip = null;
     	private $type = null;
    @@ -35,7 +39,7 @@
     	private $expiry = null;
     	public $Bannee = null;
     	public $Bannor = null;
    -	private $banmask = null; //see the constructor ... should this be moved elsewhere?
    +	private $banmask = null;
     
     	/**
     	 * Find a ban by id
    @@ -78,10 +82,18 @@
     			$X->getVal('ban.addresses/address'),
     			$X->getVal('date.modified'), 
     			$X->getVal('date.expires'), 
    -			$X->getVal('description'), 
    -			$X->getVal('ban.users/user/username'), 
    -			$X->getVal('user.createdby/username')
    +			$X->getVal('description')
     		);
    +		$user = $X->getVal('user.createdby');
    +		if (!is_null($user))
    +		{
    +			$Ban->Bannor = DekiUser::newFromArray($user);
    +		}
    +		$user = $X->getVal('ban.users/user');
    +		if ($Ban->isUserBan() && !is_null($user))
    +		{
    +			$Ban->Bannee = DekiUser::newFromArray($user);
    +		}
     		return $Ban;
     	}
     	
    @@ -101,7 +113,7 @@
     
     	public function __construct($id = 0, $ip = null, $created = null, $expiry = null, $reason = null, $bannee = null, $bannor = null)
     	{
    -		$this->bantype = !is_null($ip) ? 'ip': 'username';
    +		$this->bantype = !is_null($ip) ? self::TYPE_IP : self::TYPE_USER;
     		$this->id = $id;
     		$this->ip = $ip;
     		$this->created = $created;
    @@ -115,23 +127,8 @@
     		$this->reason = $reason;
     		$this->expiry = $expiry;
     		
    -		if ($this->bantype == 'username') 
    -		{
    -			$Bannee = new DekiUser;
    -			$Bannee->setName($bannee);
    -			$this->Bannee = $Bannee;
    -		}
    -		else
    -		{
    -			$this->Bannee = null;	
    -		}
    -			
    -		$Bannor = new DekiUser;
    -		$Bannor->setName($bannor);
    -		$this->Bannor = $Bannor;
    +		$this->banmask = self::BAN_MASK;
     		
    -		$this->banmask = 'BROWSE,READ,SUBSCRIBE,UPDATE,CREATE,DELETE,CHANGEPERMISSIONS,CONTROLPANEL,ADMIN'; //configurable?
    -		
     	}
     	
     	public function getId() { return $this->id; }
    @@ -168,7 +165,7 @@
     	}
     		
     	public function getModified()
    -	{ 
    +	{
     		global $wgLang;
     		return $wgLang->date($this->created, true);
     	}
    @@ -176,12 +173,12 @@
     	public function setBannedUser($type, $user)
     	{
     		$this->setBanType($type);
    -		if ($type == 'ip') 
    +		if ($type == self::TYPE_IP) 
     		{
     			$this->ip = $user;
     		}
     		
    -		if ($type == 'username') 
    +		if ($type == self::TYPE_USER) 
     		{
     			$User = DekiUser::newFromText($user);
     			if (!is_null($User)) 
    @@ -200,6 +197,7 @@
     		return $this->ip;
     	}
     	
    +	public function isUserBan() { return $this->bantype == self::TYPE_USER; }
     	public function getReason() { return $this->reason; }
     	public function setReason($reason) { $this->reason = $reason; }
     	public function setBanType($type) { $this->bantype = $type; }
    @@ -229,7 +227,11 @@
     		return array('ban' => $ban);
     	}
     	
    -	public function toXml() {}
    +	public function toXml()
    +	{
    +		return HttpPlug::EncodeXml($this->toArray());
    +	}
    +	
     	public function toHtml()
     	{
     		$html = $this->getBannedName();
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by