m_dbkey = str_replace( ' ', '_', $dbkey ); $this->m_namespace = (int)$namespace; // really make this an integer $this->m_interwiki = $interwiki; $this->m_subobjectname = $subobjectname; } public function getDIType() { return SMWDataItem::TYPE_WIKIPAGE; } public function getDBkey() { return $this->m_dbkey; } public function getNamespace() { return $this->m_namespace; } public function getInterwiki() { return $this->m_interwiki; } public function getSubobjectName() { return $this->m_subobjectname; } /** * @since 2.1 * * @param string $sortkey */ public function setSortKey( $sortkey ) { $this->sortkey = str_replace( '_', ' ', $sortkey ); } /** * Get the sortkey of the wiki page data item. Note that this is not * the sortkey that might have been set for the corresponding wiki * page. To obtain the latter, query for the values of the property * "new SMW\DIProperty( '_SKEY' )". */ public function getSortKey() { if ( $this->sortkey === null || $this->sortkey === '' ) { $this->sortkey = str_replace( '_', ' ', $this->m_dbkey ); } return $this->sortkey; } /** * @since 2.3 * * @param string $contextReference */ public function setContextReference( $contextReference ) { $this->contextReference = $contextReference; } /** * Returns a reference for the processing context (parser etc.). * * @since 2.3 * * @return string */ public function getContextReference() { return $this->contextReference; } /** * Returns the page content language * * @since 2.5 * * @return string */ public function getPageLanguage() { if ( $this->pageLanguage === null ) { $this->pageLanguage = false; if ( ( $title = $this->getTitle() ) !== null ) { $this->pageLanguage = $title->getPageLanguage()->getCode(); } } return $this->pageLanguage; } /** * @since 2.5 * * @param integer $id */ public function setId( $id ) { $this->id = (int)$id; } /** * @since 2.5 * * @return string */ public function getId() { return $this->id; } /** * Create a MediaWiki Title object for this DIWikiPage. The result * can be null if an error occurred. * * @return Title|null */ public function getTitle() { return Title::makeTitleSafe( $this->m_namespace, $this->m_dbkey, $this->m_subobjectname, $this->m_interwiki ); } /** * Returns the base part (without a fragment) of a wikipage representation. * * @since 2.4 * * @return DIWikiPage */ public function asBase() { return new self ( $this->m_dbkey, $this->m_namespace, $this->m_interwiki ); } /** * @since 1.6 * * @return string */ public function getSerialization() { $segments = [ $this->m_dbkey, $this->m_namespace, $this->m_interwiki ]; $segments[] = $this->m_subobjectname; return implode( '#', $segments ); } /** * Create a data item from the provided serialization string and type ID. * * @param string $serialization * * @return DIWikiPage * @throws DataItemDeserializationException */ public static function doUnserialize( $serialization ) { $parts = explode( '#', $serialization, 4 ); if ( count( $parts ) == 3 ) { return new self( $parts[0], intval( $parts[1] ), $parts[2] ); } elseif ( count( $parts ) == 4 ) { return new self( $parts[0], intval( $parts[1] ), $parts[2], $parts[3] ); } else { throw new DataItemDeserializationException( "Unserialization failed: the string \"$serialization\" was not understood." ); } } /** * Create a data item from a MediaWiki Title. * * @param Title $title * @return DIWikiPage */ public static function newFromTitle( Title $title ) { return new self( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), str_replace( ' ', '_', $title->getFragment() ) ); } /** * @since 2.1 * * @param string $text * @param integer namespace * * @return DIWikiPage */ public static function newFromText( $text, $namespace = NS_MAIN ) { return new self( $text, $namespace ); } public function equals( SMWDataItem $di ) { if ( $di->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) { return false; } return $di->getSerialization() === $this->getSerialization(); } }