/**
	 * Inserts an entry into the database
	 *
	 * @param $channel ServerAdminLogChannel
	 * @param $user User|string
	 * @param $message string
	 * @return int ID of the new entry
	 */
	public static function create( ServerAdminLogChannel $channel, $user, $message ) {
		$db = wfGetDB( DB_MASTER );

		if ( $user instanceof User ) {
			$userId = $user->getId();
			$userText = null; // We use JOINs here
		} else {
			$userId = 0;
			$userText = $user;
		}

		$db->insert(
			'sal_entry',
			array(
				'sale_channel' => $channel->getId(),
				'sale_user' => $userId,
				'sale_user_text' => $userText,
				'sale_timestamp' => $db->timestamp(),
				'sale_comment' => $message,
			),
			__METHOD__
		);

		return $db->insertId();
	}
	/**
	 * Evaluates the parameters, performs the requested query, and sets up
	 * the result. Concrete implementations of ApiBase must override this
	 * method to provide whatever functionality their module offers.
	 * Implementations must not produce any output on their own and are not
	 * expected to handle any errors.
	 *
	 * The execute() method will be invoked directly by ApiMain immediately
	 * before the result of the module is output. Aside from the
	 * constructor, implementations should assume that no other methods
	 * will be called externally on the module before the result is
	 * processed.
	 *
	 * The result data should be stored in the ApiResult object available
	 * through getResult().
	 */
	public function execute() {
		$user = $this->getUser();
		if ( !$user->isAllowed( 'serveradminlog-entry' ) ) {
			$this->dieUsage( "You don't have the right to add an entry to the admin log", 'permissiondenied' );
		} elseif( $user->isBlocked() ) {
			$this->dieUsageMsg( array( 'blockedtext' ) );
		}

		$entryUser = $this->getParameter( 'user' );
		if ( $entryUser !== null ) {
			if ( !$user->isAllowed( 'serveradminlog-spoof' ) ) {
				$this->dieUsage( "You don't have the right to spoof log entries", 'permissiondenied' );
			}
		} else {
			$entryUser = $user;
		}

		$channel = ServerAdminLogChannel::newFromCode( $this->getParameter( 'channel' ) );

		if ( $channel === null ) {
			$this->dieUsage( "Invalid channel '{$this->getParameter( 'channel' )}'", 'invalidchannel' );
		}

		ServerAdminLogEntry::create(
			$channel,
			$entryUser,
			$this->getParameter( 'message' )
		);

		$this->getResult()->addValue(
			null, $this->getModuleName(), array( 'result' => 'Success' ) );
	}
	/**
	 * Display information for one channel
	 *
	 * @param $par
	 * @throws ErrorPageError
	 */
	private function showChannel( $par ) {
		$channel = ServerAdminLogChannel::newFromCode( $par );
		if ( $channel === null ) {
			throw new ErrorPageError( 'serveradminlog-invalidchannel', 'serveradminlog-invalidchannel-msg', $par );
		}

		$out = $this->getOutput();
		$out->setPageTitle( $channel->getName() );

		$this->pager->setChannel( $channel->getId() );

		$out->addHTML( $this->pager->getBody() );


	}