Ejemplo n.º 1
0
 public function getResultText(SMWQueryResult $results, $outputmode)
 {
     global $wgUser, $wgParser;
     $ig = new ImageGallery();
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($wgParser);
     $ig->setCaption($this->mIntro);
     // set caption to IQ header
     if ($this->params['galleryformat'] == 'carousel') {
         static $carouselNr = 0;
         // Set attributes for jcarousel
         $dataAttribs = array('wrap' => 'both', 'vertical' => 'false', 'rtl' => 'false');
         // Use perrow parameter to determine the scroll sequence.
         if (empty($this->params['perrow'])) {
             $dataAttribs['scroll'] = 1;
             // default 1
         } else {
             $dataAttribs['scroll'] = $this->params['perrow'];
             $dataAttribs['visible'] = $this->params['perrow'];
         }
         $attribs = array('id' => 'carousel' . ++$carouselNr, 'class' => 'jcarousel jcarousel-skin-smw', 'style' => 'display:none;');
         foreach ($dataAttribs as $name => $value) {
             $attribs['data-' . $name] = $value;
         }
         $ig->setAttributes($attribs);
         // Load javascript module
         SMWOutputs::requireResource('ext.srf.jcarousel');
     }
     // In case galleryformat = carousel, perrow should not be set
     if ($this->params['perrow'] !== '' && $this->params['galleryformat'] !== 'carousel') {
         $ig->setPerRow($this->params['perrow']);
     }
     if ($this->params['widths'] !== '') {
         $ig->setWidths($this->params['widths']);
     }
     if ($this->params['heights'] !== '') {
         $ig->setHeights($this->params['heights']);
     }
     $printReqLabels = array();
     foreach ($results->getPrintRequests() as $printReq) {
         $printReqLabels[] = $printReq->getLabel();
     }
     if ($this->params['imageproperty'] !== '' && in_array($this->params['imageproperty'], $printReqLabels)) {
         $this->addImageProperties($results, $ig, $this->params['imageproperty'], $this->params['captionproperty']);
     } else {
         $this->addImagePages($results, $ig);
     }
     return array($ig->toHTML(), 'nowiki' => true, 'isHTML' => true);
 }
Ejemplo n.º 2
0
 public function getResultText($results, $outputmode)
 {
     global $smwgIQRunningNumber, $wgUser, $wgParser;
     $skin = $wgUser->getSkin();
     $ig = new ImageGallery();
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($wgParser);
     $ig->useSkin($skin);
     $ig->setCaption($this->mIntro);
     // set caption to IQ header
     if (isset($this->m_params['perrow'])) {
         $ig->setPerRow($this->m_params['perrow']);
     }
     if (isset($this->m_params['widths'])) {
         $ig->setWidths($this->m_params['widths']);
     }
     if (isset($this->m_params['heights'])) {
         $ig->setHeights($this->m_params['heights']);
     }
     while ($row = $results->getNext()) {
         $firstField = $row[0];
         $imgTitle = $firstField->getNextObject()->getTitle();
         $imgCaption = '';
         // Is there a property queried for display with ?property
         if (isset($row[1])) {
             $imgCaption = $row[1]->getNextObject();
             if (is_object($imgCaption)) {
                 $imgCaption = $imgCaption->getShortText(SMW_OUTPUT_HTML, $this->getLinker(true));
                 $imgCaption = $wgParser->recursiveTagParse($imgCaption);
             }
         }
         if (empty($imgCaption)) {
             $imgCaption = $imgTitle->getBaseText();
             $imgCaption = preg_replace('#\\.[^.]+$#', '', $imgCaption);
             // Remove image extension
         }
         $ig->add($imgTitle, $imgCaption);
         // Only add real images (bug #5586)
         if ($imgTitle->getNamespace() == NS_IMAGE) {
             $wgParser->mOutput->addImage($imgTitle->getDBkey());
         }
     }
     return array($ig->toHTML(), 'nowiki' => true, 'isHTML' => true);
 }
Ejemplo n.º 3
0
	public function getResultText( SMWQueryResult $results, $outputmode ) {
		global $wgUser, $wgParser;

		$ig = new ImageGallery();
		$ig->setShowBytes( false );
		$ig->setShowFilename( false );
		$ig->setParser( $wgParser );
		$ig->setCaption( $this->mIntro ); // set caption to IQ header

		if ( $this->m_params['perrow'] !== '' ) {
			$ig->setPerRow( $this->m_params['perrow'] );
		}

		if ( $this->m_params['widths'] !== '' ) {
			$ig->setWidths( $this->m_params['widths'] );
		}

		if ( $this->m_params['heights'] !== '' ) {
			$ig->setHeights( $this->m_params['heights'] );
		}

		$printReqLabels = array();

		foreach ( $results->getPrintRequests() as /* SMWPrintRequest */ $printReq ) {
			$printReqLabels[] = $printReq->getLabel();
		}

		if ( $this->m_params['imageproperty'] !== '' && in_array( $this->m_params['imageproperty'], $printReqLabels ) ) {
			$this->addImageProperties( $results, $ig, $this->m_params['imageproperty'], $this->m_params['captionproperty'] );
		}
		else {
			$this->addImagePages( $results, $ig );
		}

		return array( $ig->toHTML(), 'nowiki' => true, 'isHTML' => true );
	}
Ejemplo n.º 4
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     $ig->useSkin($this->mOptions->getSkin());
     $ig->mRevisionId = $this->mRevisionId;
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig));
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = urldecode($matches[1]);
         }
         $tp = Title::newFromText($matches[1]);
         $nt =& $tp;
         if (is_null($nt)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         if (isset($matches[3])) {
             $label = $matches[3];
         } else {
             $label = '';
         }
         $html = $this->recursiveTagParse(trim($label));
         $ig->add($nt, $html);
         # Only add real images (bug #5586)
         if ($nt->getNamespace() == NS_FILE) {
             $this->mOutput->addImage($nt->getDBkey());
         }
     }
     return $ig->toHTML();
 }
Ejemplo n.º 5
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  *
  * @param string $text
  * @param array $params
  * @return string HTML
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     if (isset($params['showfilename'])) {
         $ig->setShowFilename(true);
     } else {
         $ig->setShowFilename(false);
     }
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig));
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = rawurldecode($matches[1]);
         }
         $title = Title::newFromText($matches[1], NS_FILE);
         if (is_null($title)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         $label = '';
         $alt = '';
         $link = '';
         if (isset($matches[3])) {
             // look for an |alt= definition while trying not to break existing
             // captions with multiple pipes (|) in it, until a more sensible grammar
             // is defined for images in galleries
             $matches[3] = $this->recursiveTagParse(trim($matches[3]));
             $parameterMatches = StringUtils::explode('|', $matches[3]);
             $magicWordAlt = MagicWord::get('img_alt');
             $magicWordLink = MagicWord::get('img_link');
             foreach ($parameterMatches as $parameterMatch) {
                 if ($match = $magicWordAlt->matchVariableStartToEnd($parameterMatch)) {
                     $alt = $this->stripAltText($match, false);
                 } elseif ($match = $magicWordLink->matchVariableStartToEnd($parameterMatch)) {
                     $link = strip_tags($this->replaceLinkHoldersText($match));
                     $chars = self::EXT_LINK_URL_CLASS;
                     $prots = $this->mUrlProtocols;
                     //check to see if link matches an absolute url, if not then it must be a wiki link.
                     if (!preg_match("/^({$prots}){$chars}+\$/u", $link)) {
                         $localLinkTitle = Title::newFromText($link);
                         $link = $localLinkTitle->getLocalURL();
                     }
                 } else {
                     // concatenate all other pipes
                     $label .= '|' . $parameterMatch;
                 }
             }
             // remove the first pipe
             $label = substr($label, 1);
         }
         $ig->add($title, $label, $alt, $link);
     }
     return $ig->toHTML();
 }
Ejemplo n.º 6
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  *
  * @param string $text
  * @param array $params
  * @return string HTML
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     /* Wikia change begin - @author: Macbre */
     /* Allow extensions to use different class to render image gallery */
     wfRunHooks('renderImageGallerySetup', array(&$ig, &$text, &$params));
     /* Wikia change end */
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     if (isset($params['showfilename'])) {
         $ig->setShowFilename(true);
     } else {
         $ig->setShowFilename(false);
     }
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     /* Wikia change begin */
     /* Allow extensions to use their own "parser" for <gallery> tag content */
     if (!wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig))) {
         return $ig->toHTML();
     }
     /* Wikia change end */
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = rawurldecode($matches[1]);
         }
         $title = Title::newFromText($matches[1], NS_FILE);
         if (is_null($title)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         $label = '';
         $alt = '';
         if (isset($matches[3])) {
             // look for an |alt= definition while trying not to break existing
             // captions with multiple pipes (|) in it, until a more sensible grammar
             // is defined for images in galleries
             $matches[3] = $this->recursiveTagParse(trim($matches[3]));
             $altmatches = StringUtils::explode('|', $matches[3]);
             $magicWordAlt = MagicWord::get('img_alt');
             foreach ($altmatches as $altmatch) {
                 $match = $magicWordAlt->matchVariableStartToEnd($altmatch);
                 if ($match) {
                     $alt = $this->stripAltText($match, false);
                 } else {
                     // concatenate all other pipes
                     $label .= '|' . $altmatch;
                 }
             }
             // remove the first pipe
             $label = substr($label, 1);
         }
         $ig->add($title, $label, $alt);
     }
     return $ig->toHTML();
 }
Ejemplo n.º 7
0
 /**
  * @see SMWResultPrinter::getResultText
  *
  * @param $results SMWQueryResult
  * @param $fullParams array
  * @param $outputmode integer
  *
  * @return string
  */
 public function getResultText(SMWQueryResult $results, $outputmode)
 {
     $ig = new ImageGallery();
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setCaption($this->mIntro);
     // set caption to IQ header
     // No need for a special page to use the parser but for the "normal" page
     // view we have to ensure caption text is parsed correctly through the parser
     if (!$this->isSpecialPage()) {
         $ig->setParser($GLOBALS['wgParser']);
     }
     // Initialize
     static $statNr = 0;
     $html = '';
     $processing = '';
     if ($this->params['widget'] == 'carousel') {
         // Carousel widget
         $ig->setAttributes($this->getCarouselWidget());
     } elseif ($this->params['widget'] == 'slideshow') {
         // Slideshow widget
         $ig->setAttributes($this->getSlideshowWidget());
     } else {
         // Standard gallery attributes
         $attribs = array('id' => uniqid(), 'class' => $this->getImageOverlay());
         $ig->setAttributes($attribs);
     }
     // Only use redirects where the overlay option is not used and redirect
     // thumb images towards a different target
     if ($this->params['redirects'] !== '' && !$this->params['overlay']) {
         SMWOutputs::requireResource('ext.srf.gallery.redirect');
     }
     // For the carousel widget, the perrow option should not be set
     if ($this->params['perrow'] !== '' && $this->params['widget'] !== 'carousel') {
         $ig->setPerRow($this->params['perrow']);
     }
     if ($this->params['widths'] !== '') {
         $ig->setWidths($this->params['widths']);
     }
     if ($this->params['heights'] !== '') {
         $ig->setHeights($this->params['heights']);
     }
     $printReqLabels = array();
     $redirectType = '';
     /**
      * @var SMWPrintRequest $printReq
      */
     foreach ($results->getPrintRequests() as $printReq) {
         $printReqLabels[] = $printReq->getLabel();
         // Get redirect type
         if ($this->params['redirects'] === $printReq->getLabel()) {
             $redirectType = $printReq->getTypeID();
         }
     }
     if ($this->params['imageproperty'] !== '' && in_array($this->params['imageproperty'], $printReqLabels) || $this->params['redirects'] !== '' && in_array($this->params['redirects'], $printReqLabels)) {
         $this->addImageProperties($results, $ig, $this->params['imageproperty'], $this->params['captionproperty'], $this->params['redirects'], $outputmode);
     } else {
         $this->addImagePages($results, $ig);
     }
     // SRF Global settings
     SRFUtils::addGlobalJSVariables();
     // Display a processing image as long as the DOM is no ready
     if ($this->params['widget'] !== '') {
         $processing = SRFUtils::htmlProcessingElement();
     }
     // Beautify the class selector
     $class = $this->params['widget'] ? '-' . $this->params['widget'] . ' ' : '';
     $class = $this->params['redirects'] !== '' && $this->params['overlay'] === false ? $class . ' srf-redirect' . ' ' : $class;
     $class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class;
     // Separate content from result output
     if (!$ig->isEmpty()) {
         $attribs = array('class' => 'srf-gallery' . $class, 'align' => 'justify', 'data-redirect-type' => $redirectType);
         $html = Html::rawElement('div', $attribs, $processing . $ig->toHTML());
     }
     // If available, create a link that points to further results
     if ($this->linkFurtherResults($results)) {
         $html .= $this->getLink($results, SMW_OUTPUT_HTML)->getText(SMW_OUTPUT_HTML, $this->mLinker);
     }
     return array($html, 'nowiki' => true, 'isHTML' => true);
 }
Ejemplo n.º 8
0
function renderDynamicPageList($input, $args, $mwParser)
{
    global $wgUser, $wgContLang;
    global $wgDisableCounters;
    // to determine if to allow sorting by #hits.
    global $wgDLPmaxCategories, $wgDLPMaxResultCount, $wgDLPMaxCacheTime;
    global $wgDLPAllowUnlimitedResults, $wgDLPAllowUnlimitedCategories;
    if ($wgDLPMaxCacheTime !== false) {
        $mwParser->getOutput()->updateCacheExpiry($wgDLPMaxCacheTime);
    }
    $countSet = false;
    $startList = '<ul>';
    $endList = '</ul>';
    $startItem = '<li>';
    $endItem = '</li>';
    $inlineMode = false;
    $useGallery = false;
    $galleryFileSize = false;
    $galleryFileName = true;
    $galleryImageHeight = 0;
    $galleryImageWidth = 0;
    $galleryNumbRows = 0;
    $galleryCaption = '';
    $gallery = null;
    $orderMethod = 'categoryadd';
    $order = 'descending';
    $redirects = 'exclude';
    $stable = $quality = 'include';
    $flaggedRevs = false;
    $namespaceFiltering = false;
    $namespaceIndex = 0;
    $offset = 0;
    $googleHack = false;
    $suppressErrors = false;
    $showNamespace = true;
    $addFirstCategoryDate = false;
    $dateFormat = '';
    $stripYear = false;
    $linkOptions = array();
    $categories = array();
    $excludeCategories = array();
    $parameters = explode("\n", $input);
    $parser = new Parser();
    $poptions = new ParserOptions();
    foreach ($parameters as $parameter) {
        $paramField = explode('=', $parameter, 2);
        if (count($paramField) < 2) {
            continue;
        }
        $type = trim($paramField[0]);
        $arg = trim($paramField[1]);
        switch ($type) {
            case 'category':
                $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions));
                if (is_null($title)) {
                    continue;
                }
                $categories[] = $title;
                break;
            case 'notcategory':
                $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions));
                if (is_null($title)) {
                    continue;
                }
                $excludeCategories[] = $title;
                break;
            case 'namespace':
                $ns = $wgContLang->getNsIndex($arg);
                if ($ns != null) {
                    $namespaceIndex = $ns;
                    $namespaceFiltering = true;
                } else {
                    // Note, since intval("some string") = 0
                    // this considers pretty much anything
                    // invalid here as the main namespace.
                    // This was probably originally a bug,
                    // but is now depended upon by people
                    // writing things like namespace=main
                    // so be careful when changing this code.
                    $namespaceIndex = intval($arg);
                    if ($namespaceIndex >= 0) {
                        $namespaceFiltering = true;
                    } else {
                        $namespaceFiltering = false;
                    }
                }
                break;
            case 'count':
                // ensure that $count is a number;
                $count = intval($arg);
                $countSet = true;
                break;
            case 'offset':
                $offset = intval($arg);
                break;
            case 'imagewidth':
                $galleryImageWidth = intval($arg);
                break;
            case 'imageheight':
                $galleryImageHeight = intval($arg);
                break;
            case 'imagesperrow':
                $galleryNumbRows = intval($arg);
                break;
            case 'mode':
                switch ($arg) {
                    case 'gallery':
                        $useGallery = true;
                        $gallery = new ImageGallery();
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '';
                        break;
                    case 'none':
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '<br />';
                        $inlineMode = false;
                        break;
                    case 'ordered':
                        $startList = '<ol>';
                        $endList = '</ol>';
                        $startItem = '<li>';
                        $endItem = '</li>';
                        $inlineMode = false;
                        break;
                    case 'inline':
                        // aka comma seperated list
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '';
                        $inlineMode = true;
                        break;
                    case 'unordered':
                    default:
                        $startList = '<ul>';
                        $endList = '</ul>';
                        $startItem = '<li>';
                        $endItem = '</li>';
                        $inlineMode = false;
                        break;
                }
                break;
            case 'gallerycaption':
                // Should perhaps actually parse caption instead
                // as links and what not in caption might be useful.
                $galleryCaption = $parser->transformMsg($arg, $poptions);
                break;
            case 'galleryshowfilesize':
                switch ($arg) {
                    case 'no':
                    case 'false':
                        $galleryFileSize = false;
                        break;
                    case 'true':
                    default:
                        $galleryFileSize = true;
                }
                break;
            case 'galleryshowfilename':
                switch ($arg) {
                    case 'no':
                    case 'false':
                        $galleryFileName = false;
                        break;
                    case 'true':
                    default:
                        $galleryFileName = true;
                        break;
                }
                break;
            case 'order':
                switch ($arg) {
                    case 'ascending':
                        $order = 'ascending';
                        break;
                    case 'descending':
                    default:
                        $order = 'descending';
                        break;
                }
                break;
            case 'ordermethod':
                switch ($arg) {
                    case 'lastedit':
                        $orderMethod = 'lastedit';
                        break;
                    case 'length':
                        $orderMethod = 'length';
                        break;
                    case 'created':
                        $orderMethod = 'created';
                        break;
                    case 'sortkey':
                    case 'categorysortkey':
                        $orderMethod = 'categorysortkey';
                        break;
                    case 'popularity':
                        if (!$wgDisableCounters) {
                            $orderMethod = 'popularity';
                        } else {
                            $orderMethod = 'categoyadd';
                            // default if hitcounter disabled.
                        }
                        break;
                    case 'categoryadd':
                    default:
                        $orderMethod = 'categoryadd';
                        break;
                }
                break;
            case 'redirects':
                switch ($arg) {
                    case 'include':
                        $redirects = 'include';
                        break;
                    case 'only':
                        $redirects = 'only';
                        break;
                    case 'exclude':
                    default:
                        $redirects = 'exclude';
                        break;
                }
                break;
            case 'stablepages':
                switch ($arg) {
                    case 'include':
                        $stable = 'include';
                        break;
                    case 'only':
                        $flaggedRevs = true;
                        $stable = 'only';
                        break;
                    case 'exclude':
                    default:
                        $flaggedRevs = true;
                        $stable = 'exclude';
                        break;
                }
                break;
            case 'qualitypages':
                switch ($arg) {
                    case 'include':
                        $quality = 'include';
                        break;
                    case 'only':
                        $flaggedRevs = true;
                        $quality = 'only';
                        break;
                    case 'exclude':
                    default:
                        $flaggedRevs = true;
                        $quality = 'exclude';
                        break;
                }
                break;
            case 'suppresserrors':
                if ($arg == 'true') {
                    $suppressErrors = true;
                } else {
                    $suppressErrors = false;
                }
                break;
            case 'addfirstcategorydate':
                if ($arg == 'true') {
                    $addFirstCategoryDate = true;
                } elseif (preg_match('/^(?:[ymd]{2,3}|ISO 8601)$/', $arg)) {
                    // if it more or less is valid dateformat.
                    $addFirstCategoryDate = true;
                    $dateFormat = $arg;
                    if (strlen($dateFormat) == 2) {
                        $dateFormat = $dateFormat . 'y';
                        # DateFormatter does not support no year. work around
                        $stripYear = true;
                    }
                } else {
                    $addFirstCategoryDate = false;
                }
                break;
            case 'shownamespace':
                if ('false' == $arg) {
                    $showNamespace = false;
                } else {
                    $showNamespace = true;
                }
                break;
            case 'googlehack':
                if ('false' == $arg) {
                    $googleHack = false;
                } else {
                    $googleHack = true;
                }
                break;
            case 'nofollow':
                # bug 6658
                if ('false' != $arg) {
                    $linkOptions['rel'] = 'nofollow';
                }
                break;
        }
        // end main switch()
    }
    // end foreach()
    $catCount = count($categories);
    $excludeCatCount = count($excludeCategories);
    $totalCatCount = $catCount + $excludeCatCount;
    if ($catCount < 1 && false == $namespaceFiltering) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_noincludecats'));
            // "!!no included categories!!";
        } else {
            return '';
        }
    }
    if ($totalCatCount > $wgDLPmaxCategories && !$wgDLPAllowUnlimitedCategories) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_toomanycats'));
            // "!!too many categories!!";
        } else {
            return '';
        }
    }
    if ($countSet) {
        if ($count < 1) {
            $count = 1;
        }
        if ($count > $wgDLPMaxResultCount) {
            $count = $wgDLPMaxResultCount;
        }
    } elseif (!$wgDLPAllowUnlimitedResults) {
        $count = $wgDLPMaxResultCount;
        $countSet = true;
    }
    // disallow showing date if the query doesn't have an inclusion category parameter
    if ($catCount < 1) {
        $addFirstCategoryDate = false;
        // don't sort by fields relating to categories if there are no categories.
        if ($orderMethod == 'categoryadd' || $orderMethod == 'categorysortkey') {
            $orderMethod = 'created';
        }
    }
    // build the SQL query
    $dbr = wfGetDB(DB_SLAVE);
    $tables = array('page');
    $fields = array('page_namespace', 'page_title');
    $where = array();
    $join = array();
    $options = array();
    if ($googleHack) {
        $fields[] = 'page_id';
    }
    if ($addFirstCategoryDate) {
        $fields[] = 'c1.cl_timestamp';
    }
    if ($namespaceFiltering == true) {
        $where['page_namespace'] = $namespaceIndex;
    }
    // Bug 14943 - Allow filtering based on FlaggedRevs stability.
    // Check if the extension actually exists before changing the query...
    if ($flaggedRevs && defined('FLAGGED_REVISIONS')) {
        $tables[] = 'flaggedpages';
        $join['flaggedpages'] = array('LEFT JOIN', 'page_id = fp_page_id');
        switch ($stable) {
            case 'only':
                $where[] = 'fp_stable IS NOT NULL';
                break;
            case 'exclude':
                $where['fp_stable'] = null;
                break;
        }
        switch ($quality) {
            case 'only':
                $where[] = 'fp_quality >= 1';
                break;
            case 'exclude':
                $where[] = 'fp_quality = 0 OR fp_quality IS NULL';
                break;
        }
    }
    switch ($redirects) {
        case 'only':
            $where['page_is_redirect'] = 1;
            break;
        case 'exclude':
            $where['page_is_redirect'] = 0;
            break;
    }
    $currentTableNumber = 1;
    $categorylinks = $dbr->tableName('categorylinks');
    for ($i = 0; $i < $catCount; $i++) {
        $join["{$categorylinks} AS c{$currentTableNumber}"] = array('INNER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($categories[$i]->getDBKey())}"));
        $tables[] = "{$categorylinks} AS c{$currentTableNumber}";
        $currentTableNumber++;
    }
    for ($i = 0; $i < $excludeCatCount; $i++) {
        $join["{$categorylinks} AS c{$currentTableNumber}"] = array('LEFT OUTER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($excludeCategories[$i]->getDBKey())}"));
        $tables[] = "{$categorylinks} AS c{$currentTableNumber}";
        $where["c{$currentTableNumber}.cl_to"] = null;
        $currentTableNumber++;
    }
    if ('descending' == $order) {
        $sqlOrder = 'DESC';
    } else {
        $sqlOrder = 'ASC';
    }
    switch ($orderMethod) {
        case 'lastedit':
            $sqlSort = 'page_touched';
            break;
        case 'length':
            $sqlSort = 'page_len';
            break;
        case 'created':
            $sqlSort = 'page_id';
            # Since they're never reused and increasing
            break;
        case 'categorysortkey':
            $sqlSort = "c1.cl_type {$sqlOrder}, c1.cl_sortkey";
            break;
        case 'popularity':
            $sqlSort = 'page_counter';
            break;
        case 'categoryadd':
        default:
            $sqlSort = 'c1.cl_timestamp';
            break;
    }
    $options['ORDER BY'] = "{$sqlSort} {$sqlOrder}";
    if ($countSet) {
        $options['LIMIT'] = $count;
    }
    if ($offset > 0) {
        $options['OFFSET'] = $offset;
    }
    // process the query
    $res = $dbr->select($tables, $fields, $where, __METHOD__, $options, $join);
    $sk = $wgUser->getSkin();
    if ($dbr->numRows($res) == 0) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_noresults'));
        } else {
            return '';
        }
    }
    // start unordered list
    $output = $startList . "\n";
    $categoryDate = '';
    $df = null;
    if ($dateFormat != '' && $addFirstCategoryDate) {
        $df = DateFormatter::getInstance();
    }
    // process results of query, outputing equivalent of <li>[[Article]]</li>
    // for each result, or something similar if the list uses other
    // startlist/endlist
    $articleList = array();
    foreach ($res as $row) {
        $title = Title::makeTitle($row->page_namespace, $row->page_title);
        if (true == $addFirstCategoryDate) {
            if ($dateFormat != '') {
                # this is a tad ugly
                # use DateFormatter, and support disgarding year.
                $categoryDate = wfTimestamp(TS_ISO_8601, $row->cl_timestamp);
                if ($stripYear) {
                    $categoryDate = $wgContLang->getMonthName(substr($categoryDate, 5, 2)) . ' ' . substr($categoryDate, 8, 2);
                } else {
                    $categoryDate = substr($categoryDate, 0, 10);
                }
                $categoryDate = $df->reformat($dateFormat, $categoryDate, array('match-whole'));
            } else {
                $categoryDate = $wgContLang->date(wfTimestamp(TS_MW, $row->cl_timestamp));
            }
            if (!$useGallery) {
                $categoryDate .= wfMsgForContent('colon-separator');
            } else {
                $categoryDate .= ' ';
            }
        }
        $query = array();
        if ($googleHack == true) {
            $query['dpl_id'] = intval($row->page_id);
        }
        if ($showNamespace == true) {
            $titleText = $title->getPrefixedText();
        } else {
            $titleText = $title->getText();
        }
        if ($useGallery) {
            # Note, $categoryDate is treated as raw html
            # this is safe since the only html present
            # would come from the dateformatter <span>.
            $gallery->add($title, $categoryDate);
        } else {
            $articleList[] = $categoryDate . $sk->link($title, htmlspecialchars($titleText), $linkOptions, $query, array('forcearticlepath', 'known'));
        }
    }
    // end unordered list
    if ($useGallery) {
        $gallery->setHideBadImages();
        $gallery->setShowFilename($galleryFileName);
        $gallery->setShowBytes($galleryFileSize);
        if ($galleryImageHeight > 0) {
            $gallery->setHeights($galleryImageHeight);
        }
        if ($galleryImageWidth > 0) {
            $gallery->setWidths($galleryImageWidth);
        }
        if ($galleryNumbRows > 0) {
            $gallery->setPerRow($galleryNumbRows);
        }
        if ($galleryCaption != '') {
            $gallery->setCaption($galleryCaption);
            # gallery class escapes string
        }
        $output = $gallery->toHtml();
    } else {
        $output .= $startItem;
        if ($inlineMode) {
            $output .= $wgContLang->commaList($articleList);
        } else {
            $output .= implode("{$endItem} \n{$startItem}", $articleList);
        }
        $output .= $endItem;
        $output .= $endList . "\n";
    }
    return $output;
}
Ejemplo n.º 9
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParsing();
     $ig->useSkin($this->mOptions->getSkin());
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     $lines = explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         $tp = Title::newFromText($matches[1]);
         $nt =& $tp;
         if (is_null($nt)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         if (isset($matches[3])) {
             $label = $matches[3];
         } else {
             $label = '';
         }
         $pout = $this->parse($label, $this->mTitle, $this->mOptions, false, false);
         $html = $pout->getText();
         $ig->add(new Image($nt), $html);
         # Only add real images (bug #5586)
         if ($nt->getNamespace() == NS_IMAGE) {
             $this->mOutput->addImage($nt->getDBkey());
         }
     }
     return $ig->toHTML();
 }