/**
     * Write (or delte, if $delete is set to true) the data in the object
     * variables, to the wiki page corresponding to this page handler
     * @param boolean $delete
     */
    public function writeOrDeleteDataToWiki( $delete = false ) {
        if ( $delete ) {
            if ( $this->checkWikiPageExists() ) {
                $this->initSMWWriter( $delete = true );
            } else {
                return;
            }
        } else {
            $this->ensureWikiPageExists();
            $this->initSMWWriter();
        }

        $properties = $this->m_properties;
        foreach ( $properties as $cur_prop ) {
            $propertystring = $cur_prop['p'];
            // TODO: Remove old code:
            // $property = SMWPropertyValue::makeUserProperty( $propertystring );
            $property_di = SMWDIProperty::newFromUserLabel($propertystring);
            $valuestring = RDFIOUtils::sanitizeSMWValue( $cur_prop['v'] );
            $value    = SMWDataValueFactory::newPropertyObjectValue( $property_di, $valuestring );

            $propertyErrorText = $property->getErrorText();
            $propertyHasError = ( $propertyErrorText != '' );
            if ( $propertyHasError ) {
                $this->addError( "<p>In RDFIOPageHandler::writeOrDeleteDataToWiki(): " . $property->getErrorText() . "</p>" );
            }

            $valueErrorText = $value->getErrorText();
            $valueHasError = ( $valueErrorText != '' );
            if ( $valueHasError ) {
                $this->addError( "<p>Error creating property value object in RDFIOPageHandler::writeOrDeleteDataToWiki():</p><p>" . $value->getErrorText() . "</p>" );
            }
            if ( $delete ) {
                $this->m_smwwriter_remove->addPropertyObjectValue( $property, $value );
                $editmessage = "Deleting properties. Last property delete: " . $propertystring . " : " . $valuestring;
            } else {
                $this->m_smwwriter_add->addPropertyObjectValue( $property, $value );
                $editmessage = "Importing properties. Last property added: " . $propertystring . " : " . $valuestring;
            }
        }

        $this->m_smwwriter->update( $this->m_smwwriter_remove, $this->m_smwwriter_add, $editmessage );
        $smwWriterError = $this->m_smwwriter->getError();
        $smwWriterHasError = ( $smwWriterError != '' );
        if ( $smwWriterHasError ) {
            $this->addError( "<p>SMWWriter Error: " . $smwWriterError . "</p>" );
        }
    }
    /**
     * Prepare page handlers, which represent wiki pages to be written to/deleted from,
     * and the corresponding facts to add/remove
     */
    private function preparePageHandlers() {
        // The page below should not be deleted on delete operations
        if ( !$this->m_delete ) {
            // Add type info to the Original URI property
            $property_hastypeurl = array( array( 'p' => 'Has type', 'v' => 'URL' ) );
            $origuripage = new RDFIOPageHandler( 'Original URI', SMW_NS_PROPERTY, $property_hastypeurl );
            $this->addToPages( $origuripage );
        }

        // Prepare for storing the data to write in internal data structure ($this->m_pages)
        $unique_subject_uris = $this->getUniqueSubjectURIs();
        foreach ( $unique_subject_uris as $subject_uri ) {
            $properties = array();
            // A URIResolver URI indicates that internal titles only are used and we have no Original URI available
            if (  !$this->m_delete && !RDFIOUtils::isURIResolverURI( $subject_uri ) && !RDFIOUtils::isArcUntitledNode( $subject_uri ) ) {
                // Add the Original URI fact to the list of properties
                $properties[0] = $this->createOrigURIPropertyArray( $subject_uri );
                $properties[1] = $this->createEquivURIPropertyArray( $subject_uri );
                $i++;
            }

            $wikititle = $this->getWikiTitleForURI( $subject_uri );
            $triplesforpage = $this->getTriplesForSubject( $subject_uri );

            $i = 2;
            foreach ( $triplesforpage as $triple ) {
                $propertyuri = $triple['p'];
                $valueorig = $triple['o'];
                $valuetype = $triple['o_type'];
                $property = $this->getWikiTitleForURI( $propertyuri, $isproperty = true );
                if ( $valuetype == 'uri' ) {
                    $value = $this->getWikiTitleForURI( $valueorig );
                } else {
                    $value = RDFIOUtils::sanitizeSMWValue( $valueorig );
                }
                $properties[$i] = array( 'p' => $property, 'v' => $value );
                $i++;
            }

            $this->addToPages( new RDFIOPageHandler( $wikititle, NS_MAIN, $properties ) );
        }

        // The data generated below should not be deleted when doing delete operations, and thus,
        // pagehandlers for them should not be prepared on delete.
        if ( !$this->m_delete ) {
            // Prepare property pages
            $unique_property_uris = $this->getUniquePropertyURIs();
            foreach ( $unique_property_uris as $property_uri => $property_uridata ) {
                $wikititle = $this->getWikiTitleForURI( $property_uri, $isproperty = true );

                $type = $this->convertARCTypeToSMWType( $property_uridata['type'], $property_uridata['datatype'] );
                $property_hastype = array( 'p' => 'Has type', 'v' => $type );
                // A URIResolver URI indicates that internal titles only are used and we have no Original URI available
                if ( !RDFIOUtils::isURIResolverURI( $property_uri ) && !RDFIOUtils::isArcUntitledNode( $wikititle ) ) {
                    $property_origuri = $this->createOrigURIPropertyArray( $property_uri );
                    $property_equivuri = $this->createEquivURIPropertyArray( $property_uri );
                    $properties = array( $property_origuri, $property_equivuri, $property_hastype );
                } else {
                    $properties = array( $property_hastype );
                }
                $propertypage = new RDFIOPageHandler( $wikititle, SMW_NS_PROPERTY, $properties );
                $this->addToPages( $propertypage );
            }

            // Prepare value pages
            // TODO: Look for a way to merge with the above code, or otherwise refactor ...
            $unique_value_uris = $this->getUniqueValueURIs();
            foreach ( $unique_value_uris as $unique_value_uri ) {
                $wikititle = $this->getWikiTitleForURI( $unique_value_uri );

                // A URIResolver URI indicates that internal titles only are used and we have no Original URI available
                if ( !RDFIOUtils::isURIResolverURI( $unique_value_uri ) && !RDFIOUtils::isArcUntitledNode( $unique_value_uri ) ) {
                    $value_origuri = $this->createOrigURIPropertyArray( $unique_value_uri );
                    $value_equivuri = $this->createEquivURIPropertyArray( $unique_value_uri );
                    $values = array( $value_origuri, $value_equivuri );
                }
                $valuepage = new RDFIOPageHandler( $wikititle, NS_MAIN, $values );
                $this->addToPages( $valuepage );
            }
        }
    }