コード例 #1
0
 /**
  * factory method, create either Item or List object from title
  *
  * @author ADi
  * @param Title $title
  * @return TopListBase
  */
 public static function newFromTitle(Title $title)
 {
     $object = null;
     if ($title->getNamespace() == NS_TOPLIST) {
         if (!$title->isSubpage()) {
             $object = TopList::newFromTitle($title);
         } else {
             $object = TopListItem::newFromTitle($title);
         }
     }
     return $object;
 }
コード例 #2
0
 /**
  * @author Federico "Lox" Lucignano <*****@*****.**>
  *
  * Implementation of a parser function
  */
 public static function parseTag($input, $args, $parser)
 {
     $relatedTitle = null;
     $relatedImage = null;
     $relatedUrl = null;
     if (!empty($args[TOPLIST_ATTRIBUTE_RELATED])) {
         self::$mAttributes[TOPLIST_ATTRIBUTE_RELATED] = $args[TOPLIST_ATTRIBUTE_RELATED];
         $relatedTitle = Title::newFromText($args[TOPLIST_ATTRIBUTE_RELATED]);
         $relatedUrl = $relatedTitle->getLocalUrl();
     }
     if (!empty($args[TOPLIST_ATTRIBUTE_PICTURE])) {
         self::$mAttributes[TOPLIST_ATTRIBUTE_PICTURE] = $args[TOPLIST_ATTRIBUTE_PICTURE];
         if (!empty(self::$mAttributes[TOPLIST_ATTRIBUTE_PICTURE])) {
             $source = new ImageServing(null, 200);
             $result = $source->getThumbnails(array(self::$mAttributes[TOPLIST_ATTRIBUTE_PICTURE]));
             if (!empty($result[self::$mAttributes[TOPLIST_ATTRIBUTE_PICTURE]])) {
                 $relatedImage = $result[self::$mAttributes[TOPLIST_ATTRIBUTE_PICTURE]];
                 if (empty($relatedUrl)) {
                     $title = Title::newFromText($relatedImage['name'], NS_FILE);
                     $relatedUrl = $title->getLocalURL();
                 }
             }
         }
     }
     self::$mAttributes[TOPLIST_ATTRIBUTE_DESCRIPTION] = '';
     if (!empty($args[TOPLIST_ATTRIBUTE_DESCRIPTION])) {
         self::$mAttributes[TOPLIST_ATTRIBUTE_DESCRIPTION] = $args[TOPLIST_ATTRIBUTE_DESCRIPTION];
     }
     if (!empty(self::$mList)) {
         $list = self::$mList;
         self::$mList = null;
     } else {
         $list = TopList::newFromTitle($parser->mTitle);
     }
     if (!empty($list)) {
         $template = new EasyTemplate(dirname(__FILE__) . "/templates/");
         if ($relatedTitle instanceof Title) {
             $relatedTitleData = array('localURL' => $relatedTitle->getLocalURL(), 'text' => $relatedTitle->getText());
         } else {
             $relatedTitleData = null;
         }
         $template->set_vars(array('list' => $list, 'listTitle' => $list->getTitle()->getText(), 'relatedTitleData' => $relatedTitleData, 'relatedImage' => $relatedImage, 'attribs' => self::$mAttributes, 'relatedUrl' => $relatedUrl, 'description' => self::$mAttributes[TOPLIST_ATTRIBUTE_DESCRIPTION]));
         self::$mOutput = $template->render('list');
         // remove whitespaces to avoid extra <p> tags
         self::$mOutput = preg_replace("#[\n\t]+#", '', self::$mOutput);
     } else {
         self::$mOutput = '';
     }
     return self::$mOutput;
 }
コード例 #3
0
 /**
  * @static
  * @brief Hook: Customizes description and og:description metatags for Top10Lists fb#23281
  * @desc Checks if namespace of an article title is NS_TOPLIST and if it's true overwrites $content variable which is passed to description metatag later along with og:description metatag
  *
  * @param Article $oArticle
  * @param string $content
  * @param integer $length
  *
  * @return bool
  *
  * @author Andrzej 'nAndy' Łukaszewski
  */
 public static function onArticleServiceBeforeStripping(&$oArticle, &$content, $length)
 {
     $title = $oArticle->getTitle();
     if ($title instanceof Title && $title->getNamespace() == NS_TOPLIST) {
         $topList = TopList::newFromTitle($title);
         if (!$topList) {
             //fb#27831 when the title is a subpage of toplist (its item)
             //TopList::newFromTitle will return false
             return true;
         }
         $desc = $topList->getDescription();
         if (empty($desc)) {
             $desc = $topList->getDescription(true);
         }
         if (!empty($desc)) {
             $content = $desc;
         }
     }
     return true;
 }