/**
  * @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;
 }
 /**
  * Collect restricted wiki ids
  */
 public static function collectAndSave()
 {
     global $wgExternalSharedDB;
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $res = $dbr->select('city_variables', array('cv_city_id', 'cv_value'), array('cv_variable_id' => WikiFactory::getVarIdByName('wgGroupPermissionsLocal')), __FUNCTION__);
     $count = $dbr->numRows($res);
     $restrictedWikis = array();
     $i = 0;
     while ($row = $dbr->fetchRow($res)) {
         if (self::isRestrictedWiki($row['cv_value'])) {
             $restrictedWikis[] = (int) $row['cv_city_id'];
         }
         if ($i % 1000 == 0) {
             echo $i . '/' . $count . PHP_EOL;
         }
         $i++;
     }
     UserProfilePageHelper::saveRestrictedWikisDB($restrictedWikis);
 }
 /**
  * @brief Hook on WikiFactory value remove and update wikis's visibility if the wgGroupPermissionsLocal is removed
  *
  * @param String $cv_name
  * @param Integer $city_id
  *
  * @return Boolean
  *
  * @author Evgeniy (aquilax)
  */
 public static function onWikiFactoryVariableRemoved($cv_name, $city_id)
 {
     global $wgExternalDatawareDB;
     if (empty($wgExternalDatawareDB)) {
         // Exit if there is no Dataware DB
         return true;
     }
     if ($cv_name === 'wgGroupPermissionsLocal') {
         UserProfilePageHelper::updateRestrictedWikis((int) $city_id, false);
     }
     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__);
 }
 /**
  * @desc Helper method which can be mocked in unit tests
  *
  * @return Array
  */
 public function getRestrictedWikis()
 {
     return UserProfilePageHelper::getRestrictedWikisIds();
 }
Beispiel #6
0
 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;
 }