/** * @author Federico "Lox" Lucignano * * overrides TopListBase::_loadData */ protected function _loadData($forceReload = false) { parent::_loadData($forceReload); if (!$this->mDataLoaded || $forceReload) { if ($this->exists()) { TopListParser::parse($this); $relatedArticle = TopListParser::getAttribute(TOPLIST_ATTRIBUTE_RELATED); if (!empty($relatedArticle)) { $relatedArticle = Title::newFromText($relatedArticle); } $this->setRelatedArticle($relatedArticle); $picture = TopListParser::getAttribute(TOPLIST_ATTRIBUTE_PICTURE); if (!empty($picture)) { $picture = Title::newFromText($picture); } $this->setPicture($picture); $description = TopListParser::getAttribute(TOPLIST_ATTRIBUTE_DESCRIPTION); if (!empty($description)) { $this->setDescription($description); } } $this->mDataLoaded = true; } }
/** * @static * @return AjaxResponse * * @var */ public static function addItem() { global $wgRequest, $wgUser; $result = array('result' => false); $errors = array(); $listText = $wgRequest->getVal('list'); $itemText = trim($wgRequest->getVal('text')); if (!empty($listText) && !empty($itemText)) { $list = TopList::newFromText($listText); if ($wgUser->isAllowed('toplists-create-item')) { if (!empty($list) && $list->exists()) { //check for duplicated foreach ($list->getItems() as $item) { if (strtolower($item->getArticle()->getContent()) == strtolower($itemText)) { $errors[] = wfMsg('toplists-error-duplicated-entry'); break; } } if (empty($errors)) { $newItem = $list->createItem(); $newItem->setNewContent($itemText); $saveResult = $newItem->save(TOPLISTS_SAVE_CREATE); if ($saveResult !== true) { foreach ($saveResult as $errorTuple) { $errors[] = wfMsg($errorTuple['msg'], $errorTuple['params']); } } else { //invalidate caches and trigger save event for the list article $newItem->getTitle()->invalidateCache(); $list->save(TOPLISTS_SAVE_UPDATE); $list->invalidateCache(); $result['result'] = true; $result['listBody'] = TopListParser::parse($list); } } } else { $errors[] = wfMsg('toplists-error-add-item-list-not-exists', $listText); } } else { if ($wgUser->isAnon()) { $loginURL = SpecialPage::getTitleFor('Signup')->getLocalURL() . '?returnto=' . $list->getTitle()->getPrefixedDBkey(); $errors[] = wfMsg('toplists-error-add-item-anon', array("{$loginURL}&type=login", "{$loginURL}&type=signup")); } else { $errors[] = wfMsg('toplists-error-add-item-permission'); } } } else { $errors[] = wfMsg('toplists-error-empty-item-name'); } if (!empty($errors)) { $result['errors'] = $errors; } $json = json_encode($result); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); return $response; }
/** * @author Federico "Lox" Lucignano <*****@*****.**> * * Helper method to trigger parsing of a list article comment manually * * @param TopList $list the list object representing the article to parse */ public static function parse(TopList $list) { self::$mList = $list; $text = F::app()->wg->Out->parse($list->getArticle()->getContent()); $list->invalidateCache(); return $text; }