qname = $value; $importValueParser = $this->dataValueServiceFactory->getValueParser( $this ); list( $this->namespace, $this->term, $this->uri, $this->declarativeName, $this->termType ) = $importValueParser->parse( $value ); if ( $importValueParser->getErrors() !== [] ) { foreach ( $importValueParser->getErrors() as $message ) { $this->addErrorMsg( $message ); } $this->m_dataitem = new DIBlob( 'ERROR' ); return; } // Encoded string for DB storage $this->m_dataitem = new DIBlob( $this->namespace . ' ' . $this->term . ' ' . $this->uri . ' ' . $this->termType ); // check whether caption is set, otherwise assign link statement to caption if ( $this->m_caption === false ) { $this->m_caption = $this->createCaption( $this->namespace, $this->qname, $this->uri, $this->declarativeName ); } } /** * @see SMWDataValue::loadDataItem * * @param DataItem $dataitem * * @return boolean */ protected function loadDataItem( DataItem $dataItem ) { if ( !$dataItem instanceof DIBlob ) { return false; } $this->m_dataitem = $dataItem; $parts = explode( ' ', $dataItem->getString(), 4 ); if ( count( $parts ) != 4 ) { $this->addErrorMsg( [ 'smw-datavalue-import-invalid-format', $dataItem->getString() ] ); } else { $this->namespace = $parts[0]; $this->term = $parts[1]; $this->uri = $parts[2]; $this->termType = $parts[3]; $this->qname = $this->namespace . ':' . $this->term; $this->declarativeName = ''; $this->m_caption = $this->createCaption( $this->namespace, $this->qname, $this->uri, $this->declarativeName ); } return true; } /** * @see DataValue::getShortWikiText */ public function getShortWikiText( $linked = null ) { return $this->m_caption; } /** * @see DataValue::getShortHTMLText */ public function getShortHTMLText( $linker = null ) { return htmlspecialchars( $this->qname ); } /** * @see DataValue::getLongWikiText */ public function getLongWikiText( $linked = null ) { if ( !$this->isValid() ) { return $this->getErrorText(); } return "[[MediaWiki:" . self::IMPORT_PREFIX . $this->namespace . "|" . $this->qname . "]]"; } /** * @see DataValue::getLongHTMLText */ public function getLongHTMLText( $linker = null ) { if ( !$this->isValid() ) { return $this->getErrorText(); } return htmlspecialchars( $this->qname ); } /** * @see DataValue::getWikiValue */ public function getWikiValue() { return $this->qname; } public function getNS() { return $this->uri; } public function getNSID() { return $this->namespace; } public function getLocalName() { return $this->term; } /** * @since 2.2 * * @return string */ public function getTermType() { return $this->termType; } /** * @since 2.2 * * @return string */ public function getImportReference() { return $this->namespace . ':' . $this->term . '|' . $this->uri; } private function createCaption( $namespace, $qname, $uri, $declarativeName ) { return "[[MediaWiki:" . self::IMPORT_PREFIX . $namespace . "|" . $qname . "]] " . Message::get( [ 'parentheses', "[$uri $namespace] | " . $declarativeName ], Message::PARSE ); } }