public function execute() { global $wgUser; if ($wgUser->isBlocked(false)) { $this->dieUsageMsg(array('blockedtext')); } // Disallow anonymous user to mark/unmark an 'Mark As Helpful' item if ($wgUser->isAnon()) { $this->noPermissionError(); } $params = $this->extractRequestParams(); $page = Title::newFromText($params['page']); if (!$page) { throw new MWApiMarkAsHelpfulInvalidPageException('Invalid page!'); } // check if current user has permission to mark the item, $isAbleToMark = false; // check if the page has permission to request the item $isAbleToShow = false; // Gives other extension the last chance to specify mark as helpful permission rules wfRunHooks('onMarkItemAsHelpful', array($params['type'], $params['item'], $wgUser, &$isAbleToMark, $page, &$isAbleToShow)); if (!$isAbleToShow || !$isAbleToMark) { $this->noPermissionError(); } $error = false; switch ($params['mahaction']) { case 'mark': $item = new MarkAsHelpfulItem(); $item->loadFromRequest($params); $item->mark(); break; case 'unmark': $item = new MarkAsHelpfulItem(); $conds = array('mah_type' => $params['type'], 'mah_item' => $params['item'], 'mah_user_id' => $wgUser->getId()); $status = $item->loadFromDatabase($conds); if ($status) { $item->unmark($wgUser); } else { $error = true; } break; default: throw new MWApiMarkAsHelpfulInvalidActionException("Action {$params['mbaction']} not implemented"); } if ($error === false) { $result = array('result' => 'success'); } else { $result = array('result' => 'error', 'error' => 'mah-action-error'); } $this->getResult()->addValue(null, $this->getModuleName(), $result); }
public function execute() { global $wgUser; $params = $this->extractRequestParams(); $page = Title::newFromText($params['page']); if (!$page) { throw new MWApiGetMarkAsHelpfulItemInvalidPageException('Invalid page!'); } // check if current user has permission to mark the item, $isAbleToMark = false; // check if the page has permission to request the item $isAbleToShow = false; wfRunHooks('onMarkItemAsHelpful', array($params['type'], $params['item'], $wgUser, &$isAbleToMark, $page, &$isAbleToShow)); if ($isAbleToShow) { $HelpfulUserList = MarkAsHelpfulItem::getMarkAsHelpfulList($params['type'], $params['item']); if ($params['prop'] == 'metadata') { $data = $HelpfulUserList; $format = 'metadata'; } else { $data = MarkAsHelpfulUtil::getMarkAsHelpfulTemplate($wgUser, $isAbleToMark, $HelpfulUserList, $params['type'], $params['item']); $format = 'formatted'; } } else { $data = ''; if ($params['prop'] == 'metadata') { $format = 'metadata'; } else { $format = 'formatted'; } } $result = array('result' => 'success', $format => $data); $this->getResult()->addValue(null, $this->getModuleName(), $result); }