00001 <?php
00015 class SMWDIWikiPage extends SMWDataItem {
00016
00021 protected $m_dbkey;
00026 protected $m_namespace;
00031 protected $m_interwiki;
00037 protected $m_subobjectname;
00038
00047 public function __construct( $dbkey, $namespace, $interwiki, $subobjectname = '' ) {
00048 if ( !is_numeric( $namespace ) ) {
00049 throw new SMWDataItemException( "Given namespace '$namespace' is not an integer." );
00050 }
00051
00052 $this->m_dbkey = $dbkey;
00053 $this->m_namespace = (int)$namespace;
00054 $this->m_interwiki = $interwiki;
00055 $this->m_subobjectname = $subobjectname;
00056 }
00057
00058 public function getDIType() {
00059 return SMWDataItem::TYPE_WIKIPAGE;
00060 }
00061
00062 public function getDBkey() {
00063 return $this->m_dbkey;
00064 }
00065
00066 public function getNamespace() {
00067 return $this->m_namespace;
00068 }
00069
00070 public function getInterwiki() {
00071 return $this->m_interwiki;
00072 }
00073
00074 public function getSubobjectName() {
00075 return $this->m_subobjectname;
00076 }
00077
00084 public function getSortKey() {
00085 return $this->m_dbkey;
00086 }
00087
00097 public function getTitle() {
00098 if ( $this->m_interwiki === '' ) {
00099 return Title::makeTitleSafe( $this->m_namespace, $this->m_dbkey, $this->m_subobjectname );
00100 } else {
00101 $datavalue = new SMWWikiPageValue( '_wpg' );
00102 $datavalue->setDataItem( $this );
00103 return Title::newFromText( $datavalue->getPrefixedText() );
00104 }
00105 }
00106
00107 public function getSerialization() {
00108 if ( $this->m_subobjectname === '' ) {
00109 return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki );
00110 } else {
00111 return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki . '#' . $this->m_subobjectname );
00112 }
00113 }
00114
00120 public static function doUnserialize( $serialization ) {
00121 $parts = explode( '#', $serialization, 4 );
00122 if ( count( $parts ) == 3 ) {
00123 return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2] );
00124 } elseif ( count( $parts ) == 4 ) {
00125 return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2], $parts[3] );
00126 } else {
00127 throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" was not understood." );
00128 }
00129 }
00130
00137 public static function newFromTitle( Title $title ) {
00138 return new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(),
00139 $title->getInterwiki(), str_replace( ' ', '_', $title->getFragment() ) );
00140 }
00141
00142 }