/** * @brief Hooks into GetRailModuleList * * @return boolean true */ public static function onGetRailModuleList(&$modules) { global $UPPNamespaces; $wg = F::app()->wg; if (!in_array($wg->Title->getNamespace(), $UPPNamespaces)) { return true; } wfProfileIn(__METHOD__); $pageOwner = UserProfilePageHelper::getUserFromTitle(); if (!$pageOwner->getGlobalPreference('hidefollowedpages') && !$wg->Title->isSpecial('Following') && !$wg->Title->isSpecial('Contributions')) { $modules[1101] = array('FollowedPages', 'Index', array('showDeletedPages' => false)); } wfProfileOut(__METHOD__); return true; }
/** * Don't send 404 status for user pages with filled in masthead (bugid:44602) * @brief hook handler * * @param Article $article * * @return Boolean */ public static function onBeforeDisplayNoArticleText($article) { global $UPPNamespaces; $wg = F::app()->wg; $title = $article->getTitle(); if ($title instanceof Title && in_array($title->getNamespace(), $UPPNamespaces)) { $user = UserProfilePageHelper::getUserFromTitle($title); if ($user instanceof User && $user->getId() > 0) { $userIdentityBox = new UserIdentityBox($user); $userData = $userIdentityBox->getFullData(); if (is_array($userData) && array_key_exists('showZeroStates', $userData)) { if (!$userData['showZeroStates']) { $wg->Out->setStatusCode(200); } } } } return true; }
/** * @brief Renders new action button * * @author Andrzej 'nAndy' Łukaszewski */ public function renderActionButton() { wfProfileIn(__METHOD__); $namespace = $this->title->getNamespace(); $this->setRequest(new WikiaRequest($this->app->wg->Request->getValues())); $user = UserProfilePageHelper::getUserFromTitle(); /** * @var $sessionUser User */ $sessionUser = $this->wg->User; $canRename = $sessionUser->isAllowed('renameprofilev3'); $canProtect = $sessionUser->isAllowed('protect'); $canDelete = $sessionUser->isAllowed('deleteprofilev3'); $isUserPageOwner = $user instanceof User && !$user->isAnon() && $user->getId() == $sessionUser->getId() ? true : false; $editQuery = array('action' => 'edit'); // check if this is an older version of the page $oldid = $this->app->wg->Request->getInt('oldid', 0); if ($oldid) { $editQuery['oldid'] = $oldid; } $actionButtonArray = array(); if ($namespace == NS_USER) { // profile page $actionButtonArray = array('action' => array('href' => $this->title->getLocalUrl($editQuery), 'text' => wfMessage('user-action-menu-edit-profile')->escaped(), 'id' => 'ca-edit', 'accesskey' => wfMessage('accesskey-ca-edit')->escaped()), 'image' => MenuButtonController::EDIT_ICON, 'name' => 'editprofile'); } else { if ($namespace == NS_USER_TALK && empty($this->app->wg->EnableWallExt)) { // talk page /** * @var $title Title */ $title = Title::newFromText($user->getName(), NS_USER_TALK); if ($title instanceof Title) { // sometimes title isn't created, I've tried to reproduce it on my devbox and I couldn't // checking if $title is instance of Title is a quick fix -- if it isn't no action button will be shown if ($isUserPageOwner || $this->app->wg->Request->getVal('oldid')) { $actionButtonArray = array('action' => array('href' => $this->title->getLocalUrl($editQuery), 'text' => wfMessage('user-action-menu-edit')->escaped(), 'id' => 'ca-edit', 'accesskey' => wfMessage('accesskey-ca-edit')->escaped()), 'image' => MenuButtonController::EDIT_ICON, 'name' => 'editprofile'); } else { $actionButtonArray = array('action' => array('href' => $title->getLocalUrl(array_merge($editQuery, array('section' => 'new'))), 'text' => wfMessage('user-action-menu-leave-message')->escaped(), 'id' => 'ca-addsection', 'accesskey' => wfMessage('accesskey-ca-addsection')->escaped()), 'image' => MenuButtonController::MESSAGE_ICON, 'name' => 'leavemessage', 'dropdown' => array('edit' => array('href' => $this->title->getFullUrl($editQuery), 'text' => wfMessage('user-action-menu-edit')->escaped(), 'id' => 'ca-edit', 'accesskey' => wfMessage('accesskey-ca-edit')->escaped()))); } } } else { if (defined('NS_BLOG_ARTICLE') && $namespace == NS_BLOG_ARTICLE && $isUserPageOwner) { // blog page global $wgCreateBlogPagePreload; $actionButtonArray = array('action' => array('href' => SpecialPage::getTitleFor('CreateBlogPage')->getLocalUrl(!empty($wgCreateBlogPagePreload) ? 'preload=$wgCreateBlogPagePreload' : ''), 'text' => wfMessage('blog-create-post-label')->escaped()), 'image' => MenuButtonController::BLOG_ICON, 'name' => 'createblogpost'); } } } if (in_array($namespace, array(NS_USER, NS_USER_TALK))) { // profile & talk page if ($canRename) { /** * @var $specialMovePage Title */ $specialMovePage = SpecialPage::getTitleFor('MovePage'); $renameUrl = $specialMovePage->getLocalUrl() . '/' . $this->title->__toString(); $actionButtonArray['dropdown']['rename'] = array('href' => $renameUrl, 'text' => wfMessage('user-action-menu-rename')->escaped(), 'id' => 'ca-move', 'accesskey' => wfMessage('accesskey-ca-move')->escaped()); } if ($canProtect) { $protectStatus = $this->title->isProtected() ? 'unprotect' : 'protect'; $actionButtonArray['dropdown']['protect'] = array('href' => $this->title->getLocalUrl(array('action' => $protectStatus)), 'text' => wfMessage('user-action-menu-' . $protectStatus)->escaped(), 'id' => 'ca-protect', 'accesskey' => wfMessage('accesskey-ca-protect')->escaped()); } if ($canDelete) { $actionButtonArray['dropdown']['delete'] = array('href' => $this->title->getLocalUrl(array('action' => 'delete')), 'text' => wfMessage('user-action-menu-delete')->escaped(), 'id' => 'ca-delete', 'accesskey' => wfMessage('accesskey-ca-delete')->escaped()); } $actionButtonArray['dropdown']['history'] = array('href' => $this->title->getLocalUrl(array('action' => 'history')), 'text' => wfMessage('user-action-menu-history')->escaped(), 'id' => 'ca-history', 'accesskey' => wfMessage('accesskey-ca-history')->escaped()); } wfRunHooks('UserProfilePageAfterGetActionButtonData', array(&$actionButtonArray, $namespace, $canRename, $canProtect, $canDelete, $isUserPageOwner)); $actionButton = wfRenderModule('MenuButton', 'Index', $actionButtonArray); $this->setVal('actionButton', $actionButton); wfProfileOut(__METHOD__); }
public function getUser() { $title = F::app()->wg->Title; $ns = $title->getNamespace(); $user = null; if ($ns == NS_USER_WALL) { /** * @var $w Wall */ $w = Wall::newFromTitle($title); $user = $w->getUser(); } else { if ($ns == NS_USER_WALL_MESSAGE) { // title to wall thread is Thread:dddd, which does not exist in the db. this will // result in articleId being 0, which will break the logic later. So we need // to fetch the existing title here (Username/@comment-...) if (intval($title->getText()) > 0) { $mainTitle = Title::newFromId($title->getText()); if (empty($mainTitle)) { $mainTitle = Title::newFromId($title->getText(), Title::GAID_FOR_UPDATE); } if (!empty($mainTitle)) { $title = $mainTitle; } } /** * @var $wm WallMessage */ $wm = WallMessage::newFromTitle($title); $user = $wm->getWallOwner(); } } if (is_null($user)) { return UserProfilePageHelper::getUserFromTitle($title); } return $user; }