function parseGallery( $input, $parser ) {
		global $wgSmoothGalleryDelimiter;
		global $wgSmoothGalleryAllowExternal;

		$galleryArray = Array();

		// Expand templates in the input
		$input = $parser->recursiveTagParse( $input );

		// The image array is a delimited list of images (strings)
		$line_arr = preg_split( "/$wgSmoothGalleryDelimiter/", $input, -1, PREG_SPLIT_NO_EMPTY );

		foreach ( $line_arr as $line ) {
			$img_arr = explode( "|", $line, 2 );
			$img = $img_arr[0];
			if ( count( $img_arr ) > 1 ) {
				SmoothGallery::debug( 'sgallery line has description: ' . $img_arr[1] );
				$img_desc = $img_arr[1];
			} else {
				$img_desc = '';
			}
			SmoothGallery::debug( 'sgallery line as img_arr: ', $img_arr );

			if ( $wgSmoothGalleryAllowExternal &&
			     ( ( strlen( $img ) >= 7 && substr( $img, 0, 7 ) == "http://" ) ||
			       ( strlen( $img ) >= 7 && substr( $img, 0, 8 ) == "https://" ) )
			   ) {
				$imageArray["title"] = null;
				// TODO: internationalize
				$imageArray["heading"] = "External Image";
				$imageArray["description"] = $img_desc;
				$imageArray["full_url"] = $img;
				$imageArray["view_url"] = $img;
				$imageArray["full_thumb_url"] = $img;
				$imageArray["icon_thumb_url"] = $img;
				$imageArray["image_object"] = null;
				$imageArray["external"] = true;

				$galleryArray["images"][] = $imageArray;

				continue;
			}

			$title = Title::newFromText( $img, NS_IMAGE );

			if ( is_null( $title ) ) {
				$galleryArray["missing_images"][] = $title;
				continue;
			}

			$ns = $title->getNamespace();

			if ( $ns == NS_IMAGE ) {
				$galleryArray = $this->parseImage( $title, $parser, $galleryArray, $img_desc );
			} elseif ( $ns == NS_CATEGORY ) {
				// list images in category
				$cat_images = $this->smoothGalleryImagesByCat( $title );
				if ( $cat_images ) {
					foreach ( $cat_images as $title ) {
						$galleryArray = $this->parseImage( $title, $parser, $galleryArray, '' );
					}
				}
			}
		}

		return $galleryArray;
	}
示例#2
0
/**
 * Hook callback that injects messages and things into the <head> tag
 * Does nothing if $parserOutput->mSmoothGalleryTag is not set
 */
function smoothGalleryParserOutput($outputPage, $parserOutput)
{
    if (!empty($parserOutput->mSmoothGalleryTag)) {
        SmoothGallery::setGalleryHeaders($outputPage);
    }
    if (!empty($parserOutput->mSmoothGallerySetTag)) {
        SmoothGallery::setGallerySetHeaders($outputPage);
    }
    return true;
}