Index: trunk/extensions/SemanticResultFormats/Gallery/SRF_Gallery.php |
— | — | @@ -31,22 +31,94 @@ |
32 | 32 | public function getResultText( $results, $outputmode ) |
33 | 33 | { |
34 | 34 | global $smwgIQRunningNumber, $wgUser, $wgParser; |
35 | | - $skin = $wgUser->getSkin(); |
36 | 35 | |
37 | 36 | $ig = new ImageGallery(); |
38 | 37 | $ig->setShowBytes( false ); |
39 | 38 | $ig->setShowFilename( false ); |
40 | 39 | $ig->setParser( $wgParser ); |
41 | | - $ig->useSkin( $skin ); |
| 40 | + $ig->useSkin( $wgUser->getSkin() ); |
42 | 41 | $ig->setCaption( $this->mIntro ); // set caption to IQ header |
43 | 42 | |
44 | | - if ( isset( $this->m_params['perrow'] ) ) |
| 43 | + if ( isset( $this->m_params['perrow'] ) ) { |
45 | 44 | $ig->setPerRow( $this->m_params['perrow'] ); |
46 | | - if ( isset( $this->m_params['widths'] ) ) |
| 45 | + } |
| 46 | + |
| 47 | + if ( isset( $this->m_params['widths'] ) ) { |
47 | 48 | $ig->setWidths( $this->m_params['widths'] ); |
48 | | - if ( isset( $this->m_params['heights'] ) ) |
| 49 | + } |
| 50 | + |
| 51 | + if ( isset( $this->m_params['heights'] ) ) { |
49 | 52 | $ig->setHeights( $this->m_params['heights'] ); |
| 53 | + } |
| 54 | + |
| 55 | + $this->m_params['autocaptions'] = isset( $this->m_params['autocaptions'] ) ? $this->m_params['autocaptions'] != 'off' : true; |
50 | 56 | |
| 57 | + $printReqLabels = array(); |
| 58 | + |
| 59 | + foreach ( $results->getPrintRequests() as $printReq ) { |
| 60 | + $printReqLabels[] = $printReq->getLabel(); |
| 61 | + } |
| 62 | + |
| 63 | + if ( isset( $this->m_params['imageproperty'] ) && in_array( $this->m_params['imageproperty'], $printReqLabels ) ) { |
| 64 | + $captionProperty = isset( $this->m_params['captionproperty'] ) ? $this->m_params['captionproperty'] : ''; |
| 65 | + $this->addImageProperties( $results, $ig, $this->m_params['imageproperty'], $captionProperty ); |
| 66 | + } |
| 67 | + else { |
| 68 | + $this->addImagePages( $results, $ig ); |
| 69 | + } |
| 70 | + |
| 71 | + return array( $ig->toHTML(), 'nowiki' => true, 'isHTML' => true ); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Handles queries where the images (and optionally their captions) are specified as properties. |
| 76 | + * |
| 77 | + * @since 1.5.3 |
| 78 | + * |
| 79 | + * @param SMWQueryResult $results |
| 80 | + * @param ImageGallery $ig |
| 81 | + * @param string $imageProperty |
| 82 | + * @param string $captionProperty |
| 83 | + */ |
| 84 | + protected function addImageProperties( SMWQueryResult $results, ImageGallery &$ig, $imageProperty, $captionProperty ) { |
| 85 | + while ( /* array of SMWResultArray */ $row = $results->getNext() ) { |
| 86 | + $images = array(); |
| 87 | + $captions = array(); |
| 88 | + |
| 89 | + for ( $i = 0, $n = count( $row ); $i < $n; $i++ ) { |
| 90 | + if ( $row[$i]->getPrintRequest()->getLabel() == $imageProperty ) { |
| 91 | + while ( ( $obj = $row[$i]->getNextObject() ) !== false ) { |
| 92 | + if ( $obj->getTypeID() == '_wpg' ) { |
| 93 | + $images[] = $obj->getTitle(); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + else if ( $row[$i]->getPrintRequest()->getLabel() == $captionProperty ) { |
| 98 | + while ( ( $obj = $row[$i]->getNextObject() ) !== false ) { |
| 99 | + $captions[] = $obj->getShortText( SMW_OUTPUT_HTML, $this->getLinker( true ) ); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + $amountMatches = count( $captions ) == count( $images ); |
| 105 | + $hasCaption = $amountMatches || count( $captions ) > 0; |
| 106 | + |
| 107 | + foreach ( $images as $imgTitle ) { |
| 108 | + $imgCaption= $hasCaption ? ( $amountMatches ? array_shift( $captions ) : $captions[0] ) : ''; |
| 109 | + $this->addImageToGallery( $ig, $imgTitle, $imgCaption ); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Handles queries where the result objects are image pages. |
| 116 | + * |
| 117 | + * @since 1.5.3 |
| 118 | + * |
| 119 | + * @param SMWQueryResult $results |
| 120 | + * @param ImageGallery $ig |
| 121 | + */ |
| 122 | + protected function addImagePages( SMWQueryResult $results, ImageGallery &$ig ) { |
51 | 123 | while ( $row = $results->getNext() ) { |
52 | 124 | $firstField = $row[0]; |
53 | 125 | $imgTitle = $firstField->getNextObject()->getTitle(); |
— | — | @@ -57,23 +129,39 @@ |
58 | 130 | $imgCaption = $row[1]->getNextObject(); |
59 | 131 | if ( is_object( $imgCaption ) ) { |
60 | 132 | $imgCaption = $imgCaption->getShortText( SMW_OUTPUT_HTML, $this->getLinker( true ) ); |
61 | | - $imgCaption = $wgParser->recursiveTagParse( $imgCaption ); |
62 | 133 | } |
63 | 134 | } |
64 | 135 | |
65 | | - if ( empty( $imgCaption ) ) { |
66 | | - $imgCaption = $imgTitle->getBaseText(); |
67 | | - $imgCaption = preg_replace( '#\.[^.]+$#', '', $imgCaption ); // Remove image extension |
68 | | - } |
| 136 | + $this->addImageToGallery( $ig, $imgTitle, $imgCaption ); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Adds a single image to the gallery. |
| 142 | + * Takes care of automatically adding a caption when none is provided and parsing it's wikitext. |
| 143 | + * |
| 144 | + * @since 1.5.3 |
| 145 | + * |
| 146 | + * @param ImageGallery $ig The gallery to add the image to |
| 147 | + * @param Title $imgTitle The title object of the page of the image |
| 148 | + * @param string $imgCaption An optional caption for the image |
| 149 | + */ |
| 150 | + protected function addImageToGallery( ImageGallery &$ig, Title $imgTitle, $imgCaption ) { |
| 151 | + global $wgParser; |
| 152 | + |
| 153 | + if ( empty( $imgCaption ) ) { |
| 154 | + $imgCaption = $this->m_params['autocaptions'] ? preg_replace( '#\.[^.]+$#', '', $imgTitle->getBaseText() ) : ''; |
| 155 | + } |
| 156 | + else { |
| 157 | + $imgCaption = $wgParser->recursiveTagParse( $imgCaption ); |
| 158 | + } |
69 | 159 | |
70 | | - $ig->add( $imgTitle, $imgCaption ); |
| 160 | + $ig->add( $imgTitle, $imgCaption ); |
71 | 161 | |
72 | | - // Only add real images (bug #5586) |
73 | | - if ( $imgTitle->getNamespace() == NS_IMAGE ) { |
74 | | - $wgParser->mOutput->addImage( $imgTitle->getDBkey() ); |
75 | | - } |
| 162 | + // Only add real images (bug #5586) |
| 163 | + if ( $imgTitle->getNamespace() == NS_IMAGE ) { |
| 164 | + $wgParser->mOutput->addImage( $imgTitle->getDBkey() ); |
76 | 165 | } |
77 | | - |
78 | | - return array( $ig->toHTML(), 'nowiki' => true, 'isHTML' => true ); |
79 | 166 | } |
| 167 | + |
80 | 168 | } |
Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES |
— | — | @@ -2,6 +2,11 @@ |
3 | 3 | http://semantic-mediawiki.org/wiki/Semantic_Result_Formats |
4 | 4 | |
5 | 5 | |
| 6 | +== SRF 1.5.3 == |
| 7 | + |
| 8 | +Changes in this version: |
| 9 | +* Support for images specified by properties in the gallery format. |
| 10 | + |
6 | 11 | == SRF 1.5.2 == |
7 | 12 | |
8 | 13 | Released on January 11 2011. |