00001 <?php
00002
00018 class SMWSpecialTypes extends SpecialPage {
00019
00020 public function __construct() {
00021 parent::__construct( 'Types' );
00022 }
00023
00024 public function execute( $param ) {
00025 global $wgOut;
00026 wfProfileIn( 'smwfDoSpecialTypes (SMW)' );
00027
00028 $params = SMWInfolink::decodeParameters( $param, false );
00029 $typeLabel = reset( $params );
00030
00031 if ( $typeLabel == false ) {
00032 $wgOut->setPageTitle( wfMsg( 'types' ) );
00033 $html = $this->getTypesList();
00034 } else {
00035 $typeName = str_replace( '_', ' ', $typeLabel );
00036 $wgOut->setPageTitle( $typeName );
00037 $html = $this->getTypeProperties( $typeLabel );
00038 }
00039
00040 $wgOut->addHTML( $html );
00041 SMWOutputs::commitToOutputPage( $wgOut );
00042
00043 wfProfileOut( 'smwfDoSpecialTypes (SMW)' );
00044 }
00045
00046 protected function getTypesList() {
00047 $html = '<p>' . htmlspecialchars( wfMsg( 'smw_types_docu' ) ) . "</p><br />\n";
00048
00049 $typeLabels = SMWDataValueFactory::getKnownTypeLabels();
00050 asort( $typeLabels, SORT_STRING );
00051
00052 $html .= "<ul>\n";
00053 foreach ( $typeLabels as $typeId => $label ) {
00054 $typeValue = SMWTypesValue::newFromTypeId( $typeId );
00055 $html .= '<li>' . $typeValue->getLongHTMLText( smwfGetLinker() ) . "</li>\n";
00056 }
00057 $html .= "</ul>\n";
00058
00059 return $html;
00060 }
00061
00062 protected function getTypeProperties( $typeLabel ) {
00063 global $wgRequest, $smwgTypePagingLimit;
00064
00065 if ( $smwgTypePagingLimit <= 0 ) return '';
00066
00067 $from = $wgRequest->getVal( 'from' );
00068 $until = $wgRequest->getVal( 'until' );
00069 $typeValue = SMWDataValueFactory::newTypeIDValue( '__typ', $typeLabel );
00070
00071 $store = smwfGetStore();
00072 $options = SMWPageLister::getRequestOptions( $smwgTypePagingLimit, $from, $until );
00073 $diWikiPages = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typeValue->getDataItem(), $options );
00074 if ( !$options->ascending ) {
00075 $diWikiPages = array_reverse( $diWikiPages );
00076 }
00077
00078 $result = '';
00079
00080 if ( count( $diWikiPages ) > 0 ) {
00081 $pageLister = new SMWPageLister( $diWikiPages, null, $smwgTypePagingLimit, $from, $until );
00082
00083 $title = $this->getTitleFor( 'Types', $typeLabel );
00084 $title->setFragment( '#SMWResults' );
00085 $navigation = $pageLister->getNavigationLinks( $title );
00086
00087 $resultNumber = min( $smwgTypePagingLimit, count( $diWikiPages ) );
00088 $typeName = $typeValue->getLongWikiText();
00089
00090 $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" .
00091 '<h2>' . wfMsg( 'smw_type_header', $typeName ) . "</h2>\n<p>" .
00092 wfMsgExt( 'smw_typearticlecount', array( 'parsemag' ), $resultNumber ) . "</p>\n" .
00093 $navigation . $pageLister->formatList() . $navigation . "\n</div>";
00094 }
00095
00096 return $result;
00097 }
00098
00099 }