Пример #1
0
 /**
  * Add a vote for the item
  *
  * @author ADi
  *
  */
 public static function voteItem()
 {
     global $wgRequest;
     $result = array('result' => false);
     $titleText = $wgRequest->getVal('title');
     if (!empty($titleText)) {
         $item = TopListItem::newFromText($titleText);
         if ($item instanceof TopListItem && $item->getList() instanceof TopList && $item->getList()->exists() && $item->getList()->userCanVote()) {
             $result['result'] = $item->vote();
             $result['votedId'] = $item->getTitle()->getSubpageText();
             $result['message'] = wfMsg('toplists-list-item-voted');
             $result['listBody'] = TopListParser::parse($item->getList());
         }
     }
     $json = json_encode($result);
     $response = new AjaxResponse($json);
     $response->setContentType('application/json; charset=utf-8');
     return $response;
 }
Пример #2
0
 /**
  * @author Federico "Lox" Lucignano
  *
  * Creates and returns a new TopListItem for this list (saving the item is done per item, see TopListItem::save)
  *
  * @return TopListItem|Bool|mixed an instance of the TopListItem class representing the new item, false in case of errors
  */
 public function createItem()
 {
     if (!empty($this->mTitle)) {
         $item = TopListItem::newFromText($this->mTitle->getText() . '/' . uniqid(self::ITEM_TITLE_PREFIX));
         if (!empty($item)) {
             $this->mItems[] = $item;
             return $item;
         }
     }
     return false;
 }