00001 <?php
00022 class SMWPageProperty extends SpecialPage {
00023
00027 public function __construct() {
00028 parent::__construct( 'PageProperty', '', false );
00029 }
00030
00031 public function execute( $query ) {
00032 global $wgRequest, $wgOut;
00033 $linker = smwfGetLinker();
00034 $this->setHeaders();
00035
00036
00037 $pagename = $wgRequest->getVal( 'from' );
00038 $propname = $wgRequest->getVal( 'type' );
00039 $limit = $wgRequest->getVal( 'limit' );
00040 $offset = $wgRequest->getVal( 'offset' );
00041
00042 if ( $limit === '' ) $limit = 20;
00043 if ( $offset === '' ) $offset = 0;
00044
00045 if ( $propname === '' ) {
00046 $queryparts = explode( '::', $query );
00047 $propname = $query;
00048 if ( count( $queryparts ) > 1 ) {
00049 $pagename = $queryparts[0];
00050 $propname = implode( '::', array_slice( $queryparts, 1 ) );
00051 }
00052 }
00053
00054 $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename );
00055 $pagename = $subject->isValid() ? $subject->getPrefixedText() : '';
00056 $property = SMWPropertyValue::makeUserProperty( $propname );
00057 $propname = $property->isValid() ? $property->getWikiValue() : '';
00058
00059
00060 $html = '';
00061 if ( ( $propname === '' ) ) {
00062 $html .= wfMsg( 'smw_pp_docu' ) . "\n";
00063 } else {
00064
00065 $wgOut->setPagetitle( ( $pagename !== '' ? $pagename . ' ':'' ) . $property->getWikiValue() );
00066
00067
00068 $options = new SMWRequestOptions();
00069 $options->limit = $limit + 1;
00070 $options->offset = $offset;
00071 $options->sort = true;
00072 $results = smwfGetStore()->getPropertyValues( $pagename !== '' ? $subject->getDataItem() : null, $property->getDataItem(), $options );
00073
00074
00075 if ( ( $offset > 0 ) || ( count( $results ) > $limit ) ) {
00076 if ( $offset > 0 ) {
00077 $navigation = Html::element(
00078 'a',
00079 array(
00080 'href' => $this->getTitle()->getLocalURL( array(
00081 'offset' => max( 0, $offset - $limit ),
00082 'limit' => $limit,
00083 'type' => $propname,
00084 'from' => $pagename
00085 ) )
00086 ),
00087 wfMsg( 'smw_result_prev' )
00088 );
00089 } else {
00090 $navigation = wfMsg( 'smw_result_prev' );
00091 }
00092
00093 $navigation .=
00094 '     <b>' .
00095 wfMsg( 'smw_result_results' ) . ' ' .
00096 ( $offset + 1 ) . '– ' . ( $offset + min( count( $results ), $limit ) ) .
00097 '</b>    ';
00098
00099 if ( count( $results ) == ( $limit + 1 ) ) {
00100 $navigation = Html::element(
00101 'a',
00102 array(
00103 'href' => $this->getTitle()->getLocalURL( array(
00104 'offset' => ( $offset + $limit ),
00105 'limit' => $limit,
00106 'type' => $propname,
00107 'from' => $pagename
00108 ) )
00109 ),
00110 wfMsg( 'smw_result_next' )
00111 );
00112 } else {
00113 $navigation .= wfMsg( 'smw_result_next' );
00114 }
00115 } else {
00116 $navigation = '';
00117 }
00118
00119
00120 $html .= '<br />' . $navigation;
00121 if ( count( $results ) == 0 ) {
00122 $html .= wfMsg( 'smw_result_noresults' );
00123 } else {
00124 $html .= "<ul>\n";
00125 $count = $limit + 1;
00126
00127 foreach ( $results as $di ) {
00128 $count--;
00129 if ( $count < 1 ) continue;
00130
00131 $dv = SMWDataValueFactory::newDataItemValue( $di, $property->getDataItem() );
00132 $html .= '<li>' . $dv->getLongHTMLText( $linker );
00133
00134 if ( $property->getDataItem()->findPropertyTypeID() == '_wpg' ) {
00135 $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() );
00136 $html .= '  ' . $browselink->getHTML( $linker );
00137 }
00138
00139 $html .= "</li> \n";
00140 }
00141
00142 $html .= "</ul>\n";
00143 }
00144
00145 $html .= $navigation;
00146 }
00147
00148
00149 $spectitle = $this->getTitle();
00150 $html .= '<p> </p>';
00151 $html .= '<form name="pageproperty" action="' . htmlspecialchars( $spectitle->getLocalURL() ) . '" method="get">' . "\n" .
00152 '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>' ;
00153 $html .= wfMsg( 'smw_pp_from' ) . ' <input type="text" name="from" value="' . htmlspecialchars( $pagename ) . '" />' . "   \n";
00154 $html .= wfMsg( 'smw_pp_type' ) . ' <input type="text" name="type" value="' . htmlspecialchars( $propname ) . '" />' . "\n";
00155 $html .= '<input type="submit" value="' . wfMsg( 'smw_pp_submit' ) . "\"/>\n</form>\n";
00156
00157 $wgOut->addHTML( $html );
00158 SMWOutputs::commitToOutputPage( $wgOut );
00159 }
00160
00161 }