public static function init() {
		parent::init( self::$magicWordKeys, self::$substitutes,
				self::$magicWordArray, self::$flipMagicWordKeys );
		self::$surname             = new self( self::surname );
		self::$given               = new self( self::given );
		self::$literal             = new self( self::literal );
		self::$nameLink            = new self( self::nameLink );
		self::$suffix              = new self( self::suffix );
		self::$droppingParticle    = new self( self::droppingParticle );
		self::$nonDroppingParticle = new self( self::nonDroppingParticle );
	}
Пример #2
0
	/**
	 * Read and parse arguments from a WCArgumentReader object.
	 * @param WCArgumentReader $wcArgumentReader = the argument reader
	 * @global $wikiCitationValidateArguments
	 */
	public function readArguments( WCArgumentReader $argumentReader ) {

		$this->citationType = $argumentReader->getCitationType();
		$this->citationLength = $argumentReader->getCitationLength();

		/**
		 * Recognize and process the parameters and names.
		 */
		foreach( $argumentReader->parameters as $var => $value ) {

			# See if scope name only is present, in which case the parameter is assumed to be the title.
			# This allows the user to enter "journal=Nature" or "work=Origin of Species", etc.
			$scope = WCScopeEnum::match( $var, WCScopeEnum::$magicWordArray,
					WCScopeEnum::$flipMagicWordKeys, 'WCScopeEnum' );
			if ( $scope ) {
				$property = WCPropertyEnum::$title;
				$this->reference->setProperty( $scope, $property, new WCTitle( $value ) );
				continue;
			}

			# Match the parameter scope.
			list( $scope, $parameterText ) = WCScopeEnum::matchPrefix( $var, WCScopeEnum::$magicWordArray,
					WCScopeEnum::$flipMagicWordKeys, 'WCScopeEnum' );
			if ( !$scope ) {
				$scope = WCScopeEnum::$work; # Set the default
			}

			# See if a type name is present, in which case the parameter is assumed to be the title.
			# This allows the wiki editor to enter "book=Origin of Species", "pamphlet=Common Sense," etc., or even "container-encyclopedia=Encyclopedia Brittanica."
			# If either the title or type have already been set, then neither will be set again.
			# Thus, it will be possible to use "book" as a locator.
			$type = WCSourceTypeEnum::match( $parameterText, WCSourceTypeEnum::$magicWordArray,
				WCSourceTypeEnum::$flipMagicWordKeys, 'WCTypeEnum' );
			if ( $type ) {
				$propertyEnumTitle = WCPropertyEnum::$title;
				$propertyEnumType = WCPropertyEnum::$type;
				$title = $this->reference->getProperty( $scope, $propertyEnumTitle );
				$type = $this->reference->getProperty( $scope, $propertyEnumType );
				if ( is_null( $this->reference->getProperty( $scope, $propertyEnumTitle ) ) && is_null( $this->getProperty( $scope, $propertyEnumType ) ) ) {
					$this->reference->setProperty( $scope, $propertyEnumTitle, new WCTitle( $value ) );
					$this->reference->setProperty( $scope, $propertyEnumType, new WCTypeData( $type ) );
				}
				continue;
			}

			global $wikiCitationValidateArguments;

			# Match properties.
			$property = WCPropertyEnum::match( $parameterText, WCPropertyEnum::$magicWordArray,
				WCPropertyEnum::$flipMagicWordKeys, 'WCPropertyEnum' );
			if ( $property ) {
				$attributeKey = $property->getAttribute()->key;
				$attributeClass = WCAttributeEnum::$attribute[ $attributeKey ];
				if ( $attributeKey == WCAttributeEnum::locator ) {
					# Locators disregard the scope.
					$locator = $this->getLocator( $property );
					if ( $wikiCitationValidateArguments && isset( $locator ) ) {
						throw new WCException( 'wc-parameter_defined_twice', $property );
					} else {
						$this->setLocator( $property, new WCLocator( $value ) );
					}
				} else {
					$prop = $this->reference->getProperty( $scope, $property );
					if ( $wikiCitationValidateArguments && isset( $prop ) ) {
						throw new WCException( 'wc-parameter_defined_twice', $property );
					} else {
						$this->reference->setProperty( $scope, $property, new $attributeClass( $value ) );
					}
				}
				# Set attribute
				continue;
			}

			# Match names.
			$match = False;
			list( $nameEnum, $namePartText ) = WCNameTypeEnum::matchPrefix( $parameterText,
				WCNameTypeEnum::$magicWordArray, WCNameTypeEnum::$flipMagicWordKeys, 'WCNameTypeEnum' );
			if ( $namePartText ) {
				list( $namePartEnum, $nameNum ) = WCNamePartEnum::matchPartAndNumber(
						$namePartText, WCNamePartEnum::$magicWordArray, WCNamePartEnum::$flipMagicWordKeys, 'WCNamePartEnum' );
				if ( $namePartEnum ) {
					if ( !$nameEnum ) {
						$nameEnum = new WCNameTypeEnum();
					}
					$match = True;
				} elseif ( $nameEnum ) {
					$namePartEnum = new WCNamePartEnum();
					$match = True;
				}
			} elseif ( $nameEnum ) {
				$namePartEnum = new WCNamePartEnum();
				$nameNum = 1;
				$match = True;
			}
			if ( $match ) {
				if ( is_null( $this->reference->getNames( $scope, $nameEnum ) ) ) {
					$this->reference->setNames( $scope, $nameEnum, new WCNames() );
				}
				$theNames = $this->reference->getNames( $scope, $nameEnum );
				$part = $theNames->getNamePart( $nameNum, $namePartEnum );
				if ( $wikiCitationValidateArguments && isset( $part ) ) {
					throw new WCException( 'wc-parameter_defined_twice', $nameEnum . $nameNum. '-' . $namePartEnum );
				} else {
					$theNames->setNamePart( $nameNum, $namePartEnum, $value );
				}
				continue;
			}

			# Argument has no matches.
			if ( $wikiCitationValidateArguments ) {
				throw new WCException( 'wc-parameter-unknown', $parameterText );
			}
		}

	}