public static function addMarkButton(SkinTemplate &$sktemplate, array &$links) { $title = $sktemplate->getRelevantTitle(); $user = $sktemplate->getUser(); if ($user->isAllowedAll('changetags', 'markmajorchange')) { $urlParams = array('action' => 'markmajorchange'); $links['actions']['markmajorchange'] = array('text' => $sktemplate->msg('markmajorchanges-mark-btn')->text(), 'href' => $title->getLocalURL($urlParams)); } }
/** * @param SkinTemplate $sktemplate a collection of views. Add the view that needs to be displayed * @param BaseTemplate $tpl currently logged in user. Not used in this context. * @return bool always true */ public function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { if (BsConfig::get('MW::BlueSpiceProjectFeedbackHelper::Active') == false) { return true; } if (!in_array('sysop', $sktemplate->getUser()->getGroups())) { return true; } $oView = new ViewBlueSpiceProjectFeedbackHelperPanel(); if (isset($tpl->data['dataAfterContent'])) { $tpl->data['dataAfterContent'] .= $oView->execute(); } else { $tpl->data['dataAfterContent'] = $oView->execute(); } return true; }
/** * Insert global watchlist page link into the personal URLs. * * @access public * @param array Peronsal URLs array. * @param object Title object for the current page. * @param object SkinTemplate instance that is setting up personal urls * @return boolean True */ public static function onPersonalUrls(array &$personalUrls, Title $title, SkinTemplate $skin) { $URL = Skin::makeSpecialUrl('GlobalWatchlist'); if (!$skin->getUser()->isAnon()) { $globalwatchlist = ['globalwatchlist' => ['text' => wfMessage('globalwatchlist')->text(), 'href' => $URL, 'active' => true]]; Curse::array_insert_before_key($personalUrls, 'watchlist', $globalwatchlist); } return true; }
/** * Changes the Edit tab and adds the VisualEditor tab. * * This is attached to the MediaWiki 'SkinTemplateNavigation' hook. * * @param SkinTemplate $skin * @param array $links Navigation links * @return boolean */ public static function onSkinTemplateNavigation(SkinTemplate &$skin, array &$links) { // Only do this if the user has VE enabled if (!$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable')) { return true; } $config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor'); if (!isset($links['views']['edit'])) { // There's no edit link, nothing to do return true; } $title = $skin->getRelevantTitle(); if (defined('EP_NS') && $title->inNamespace(EP_NS)) { return true; } $tabMessages = $config->get('VisualEditorTabMessages'); // Rebuild the $links['views'] array and inject the VisualEditor tab before or after // the edit tab as appropriate. We have to rebuild the array because PHP doesn't allow // us to splice into the middle of an associative array. $newViews = array(); foreach ($links['views'] as $action => $data) { if ($action === 'edit') { // Build the VisualEditor tab $existing = $title->exists() || $title->inNamespace(NS_MEDIAWIKI) && $title->getDefaultMessageText() !== false; $action = $existing ? 'edit' : 'create'; $veParams = $skin->editUrlOptions(); unset($veParams['action']); // Remove action=edit $veParams['veaction'] = 'edit'; // Set veaction=edit $veTabMessage = $tabMessages[$action]; $veTabText = $veTabMessage === null ? $data['text'] : $skin->msg($veTabMessage)->text(); $veTab = array('href' => $title->getLocalURL($veParams), 'text' => $veTabText, 'primary' => true, 'class' => ''); // Alter the edit tab $editTab = $data; if ($title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) { $editTabMessage = $tabMessages[$action . 'localdescriptionsource']; } else { $editTabMessage = $tabMessages[$action . 'source']; } if ($editTabMessage !== null) { $editTab['text'] = $skin->msg($editTabMessage)->text(); } // Inject the VE tab before or after the edit tab if ($config->get('VisualEditorTabPosition') === 'before') { $editTab['class'] .= ' collapsible'; $newViews['ve-edit'] = $veTab; $newViews['edit'] = $editTab; } else { $veTab['class'] .= ' collapsible'; $newViews['edit'] = $editTab; $newViews['ve-edit'] = $veTab; } } else { // Just pass through $newViews[$action] = $data; } } $links['views'] = $newViews; return true; }
/** * Adds a info to bs_personal_info * @param SkinTemplate $sktemplate * @param BaseTemplate $tpl * @return boolean Always true to keep hook running */ public function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { $oUser = $sktemplate->getUser(); if ($oUser->isAllowed('workflowview') === false) { return true; } $iCountReviews = count(BsReviewProcess::listReviews($oUser->getId())); $iCountFinishedReviews = BsReviewProcess::userHasWaitingReviews($oUser); if ($iCountReviews <= 0 && !$iCountFinishedReviews) { return true; } $tpl->data['bs_personal_info'][20] = array('id' => 'pi-review', 'href' => SpecialPage::getTitleFor('Review', $oUser->getName())->getLocalURL(), 'text' => $iCountReviews . "|" . $iCountFinishedReviews, 'class' => 'icon-eye', 'active' => $iCountReviews > 0 ? true : false); return true; }
/** * Adds Focus tab to main navigation * @param SkinTemplate $sktemplate * @param BaseTemplate $tpl * @return boolean Always true to keep hook running */ public function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { $aViews = array(); $oUser = $sktemplate->getUser(); $oCurrentTitle = $sktemplate->getTitle(); $sEditLink = ''; if ($oUser->isLoggedIn() === false) { $this->getDefaultWidgets($aViews, $oUser, $oCurrentTitle); } else { $oTitle = Title::makeTitle(NS_USER, $oUser->getName() . '/Sidebar'); $sEditLink = Linker::link($oTitle, '', array('id' => 'bs-usersidebar-edit', 'class' => 'icon-pencil'), array('action' => 'edit', 'preload' => '')); if ($oTitle->exists() === false) { $this->getDefaultWidgets($aViews, $oUser, $oTitle); } else { $aWidgets = BsWidgetListHelper::getInstanceForTitle($oTitle)->getWidgets(); if (empty($aWidgets)) { $this->getDefaultWidgets($aViews, $oUser, $oTitle); } $aViews = array_merge($aViews, $aWidgets); } } $aOut = array(); $aOut[] = $sEditLink; foreach ($aViews as $oView) { if ($oView instanceof ViewBaseElement) { $aOut[] = $oView->execute(); } } if ($tpl instanceof BsBaseTemplate) { $tpl->data['bs_navigation_main']['bs-usersidebar'] = array('position' => 20, 'label' => wfMessage('bs-tab_focus')->plain(), 'class' => 'icon-clipboard', 'content' => implode("\n", $aOut)); } else { $tpl->data['sidebar'][wfMessage('bs-tab_focus')->plain()] = implode("\n", $aOut); } return true; }
/** * Handler for PersonalUrls hook. * Add a "Notifications" item to the user toolbar ('personal URLs'). * @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls * @param &$personal_urls Array of URLs to append to. * @param &$title Title of page being visited. * @param SkinTemplate $sk * @return bool true in all cases */ static function onPersonalUrls(&$personal_urls, &$title, $sk) { global $wgEchoNewMsgAlert; $user = $sk->getUser(); if ($user->isAnon() || self::isEchoDisabled($user)) { return true; } // Add a "My notifications" item to personal URLs if ($user->getOption('echo-notify-show-link')) { $notificationCount = MWEchoNotifUser::newFromUser($user)->getNotificationCount(); $text = EchoNotificationController::formatNotificationCount($notificationCount); $url = SpecialPage::getTitleFor('Notifications')->getLocalURL(); if ($notificationCount == 0) { $linkClasses = array('mw-echo-notifications-badge'); } else { $linkClasses = array('mw-echo-unread-notifications', 'mw-echo-notifications-badge'); } $notificationsLink = array('href' => $url, 'text' => $text, 'active' => $url == $title->getLocalUrl(), 'class' => $linkClasses); $insertUrls = array('notifications' => $notificationsLink); $personal_urls = wfArrayInsertAfter($personal_urls, $insertUrls, 'userpage'); } // If the user has new messages, display a talk page alert if ($wgEchoNewMsgAlert && $user->getOption('echo-show-alert') && $user->getNewtalk()) { $personal_urls['mytalk']['text'] = $sk->msg('echo-new-messages')->text(); $personal_urls['mytalk']['class'] = array('mw-echo-alert'); $sk->getOutput()->addModuleStyles('ext.echo.alert'); } return true; }
/** * Adds WikiAdmin tab to main navigation * @param SkinTemplate $sktemplate * @param BaseTemplate $tpl * @return boolean Always true to keep hook running */ public static function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { if ($sktemplate->getUser()->isAllowed('wikiadmin') === false) { return true; } $oSpecialPage = SpecialPage::getTitleFor('WikiAdmin'); $aRegisteredModules = WikiAdmin::getRegisteredModules(); $aOutSortable = array(); $aOut = array(); $aOut[] = '<ul>'; foreach ($aRegisteredModules as $sModuleKey => $aModulParams) { $skeyLower = mb_strtolower($sModuleKey); $sModulLabel = wfMessage('bs-' . $skeyLower . '-label')->plain(); $sUrl = $oSpecialPage->getLocalURL(array('mode' => $sModuleKey)); //$sUrl = str_replace( '&', '&', $sUrl ); $sLink = Html::element('a', array('id' => 'bs-admin-' . $skeyLower, 'href' => $sUrl, 'title' => $sModulLabel), $sModulLabel); $aOutSortable[$sModulLabel] = '<li>' . $sLink . '</li>'; } $aOutSortable['Shop'] = self::getShopListItem(); $aOutSortable['SpecialPages'] = self::getMediaWikiSpecialPageItem(); ksort($aOutSortable); $aOut[] = implode("\n", $aOutSortable) . '</ul>'; $aOut[] = '</ul>'; if ($tpl instanceof BsBaseTemplate) { $tpl->data['bs_navigation_main']['bs-wikiadmin'] = array('position' => 100, 'label' => wfMessage('bs-tab_admin')->plain(), 'class' => 'icon-cog', 'content' => implode("\n", $aOut)); } else { $tpl->data['sidebar'][wfMessage('bs-tab_admin')->plain()] = implode("\n", $aOut); } return true; }
/** * Hook-Handler for 'BlueSpiceSkin:Widgets'. Adds Widgets to the Widgetbar. * @param SkinTemplate $sktemplate * @param BaseTemplate $tpl * @return boolean Always true to keep hook running */ public function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { $oCurrentTitle = $sktemplate->getTitle(); $oUser = $sktemplate->getUser(); $oView = $this->getWidgets($oCurrentTitle, $oUser); if ($tpl instanceof BsBaseTemplate) { $tpl->data['bs_dataBeforeContent']['bs-widgetbar'] = array('position' => 10, 'label' => wfMessage('prefs-widgetbar')->text(), 'content' => $oView); } else { $tpl->data['prebodyhtml'] .= $oView; } return true; }
/** * Changes the Edit tab and adds the VisualEditor tab. * * This is attached to the MediaWiki 'SkinTemplateNavigation' hook. * * @param SkinTemplate $skin * @param array $links Navigation links * @return boolean */ public static function onSkinTemplateNavigation(SkinTemplate &$skin, array &$links) { $config = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor'); // Exit if the user doesn't have VE enabled if (!$skin->getUser()->getOption('visualeditor-enable') || $skin->getUser()->getOption('visualeditor-betatempdisable') || $config->get('VisualEditorDisableForAnons') && $skin->getUser()->isAnon()) { return true; } // Exit if there's no edit link for whatever reason (e.g. protected page) if (!isset($links['views']['edit'])) { return true; } $availableNamespaces = $config->get('VisualEditorAvailableNamespaces'); $title = $skin->getRelevantTitle(); $namespaceEnabled = $title->inNamespaces(array_keys(array_filter($availableNamespaces))); $pageContentModel = $title->getContentModel(); // Don't exit if this page isn't VE-enabled, since we should still // change "Edit" to "Edit source". $isAvailable = $namespaceEnabled && $pageContentModel === CONTENT_MODEL_WIKITEXT; // HACK: Exit if we're in the Education Program namespace (even though it's content) if (defined('EP_NS') && $title->inNamespace(EP_NS)) { return true; } $tabMessages = $config->get('VisualEditorTabMessages'); // Rebuild the $links['views'] array and inject the VisualEditor tab before or after // the edit tab as appropriate. We have to rebuild the array because PHP doesn't allow // us to splice into the middle of an associative array. $newViews = array(); foreach ($links['views'] as $action => $data) { if ($action === 'edit') { // Build the VisualEditor tab $existing = $title->exists() || $title->inNamespace(NS_MEDIAWIKI) && $title->getDefaultMessageText() !== false; $action = $existing ? 'edit' : 'create'; $veParams = $skin->editUrlOptions(); unset($veParams['action']); // Remove action=edit $veParams['veaction'] = 'edit'; // Set veaction=edit $veTabMessage = $tabMessages[$action]; $veTabText = $veTabMessage === null ? $data['text'] : $skin->msg($veTabMessage)->text(); $veTab = array('href' => $title->getLocalURL($veParams), 'text' => $veTabText, 'primary' => true, 'class' => ''); // Alter the edit tab $editTab = $data; if ($title->inNamespace(NS_FILE) && WikiPage::factory($title) instanceof WikiFilePage && !WikiPage::factory($title)->isLocal()) { $editTabMessage = $tabMessages[$action . 'localdescriptionsource']; } else { $editTabMessage = $tabMessages[$action . 'source']; } if ($editTabMessage !== null) { $editTab['text'] = $skin->msg($editTabMessage)->text(); } if ($isAvailable) { // Inject the VE tab before or after the edit tab if ($config->get('VisualEditorTabPosition') === 'before') { $editTab['class'] .= ' collapsible'; $newViews['ve-edit'] = $veTab; $newViews['edit'] = $editTab; } else { $veTab['class'] .= ' collapsible'; $newViews['edit'] = $editTab; $newViews['ve-edit'] = $veTab; } } else { // Don't add ve-edit, but do update the edit tab (e.g. "Edit source"). $newViews['edit'] = $editTab; } } else { // Just pass through $newViews[$action] = $data; } } $links['views'] = $newViews; return true; }
public static function addApprovalButton(SkinTemplate &$sktemplate, array &$links) { $title = $sktemplate->getRelevantTitle(); $user = $sktemplate->getUser(); if ($sktemplate->isRevisionCurrent() && ApprovedRevs::isAssignedToProject($title) && ApprovedRevs::userCanApprovePage($title, $user) && !ApprovedRevs::isLatestRevisionApproved($title)) { /* This is somewhat a replication of code from SkinTemplate::buildContentNavigationUrls() */ $onPage = $title->equals($sktemplate->getTitle()); $request = $sktemplate->getRequest(); $action = $request->getVal('action', 'view'); /* /Code Replication */ $isInAction = $onPage && $action == 'approveprojectpage'; $links['actions']['approveprojectpage'] = array('text' => 'אישור הדף', 'href' => $title->getLocalURL('action=approveprojectpage'), 'class' => $isInAction ? 'selected' : ''); } return true; }
/** * Creates the StateBar. on articles. * @param SkinTemplate $sktemplate * @param BaseTemplate $tpl * @return boolean Always true to keep hook running */ public function onSkinTemplateOutputPageBeforeExec(&$sktemplate, &$tpl) { if (BsExtensionManager::isContextActive('MW::StateBarShow') === false) { return true; } if (!is_null($this->oRedirectTargetTitle)) { $oTitle = $this->oRedirectTargetTitle; } wfRunHooks('BSStateBarBeforeTopViewAdd', array($this, &$this->aTopViews, $sktemplate->getUser(), $sktemplate->getTitle(), $sktemplate)); if (count($this->aTopViews) == 0) { // TODO RBV (01.07.11 18:26): Ain't this too late? BsExtensionManager::removeContext('MW::StateBarShow'); return true; } $aSortTopVars = BsConfig::get('MW::StateBar::SortTopVars'); if (!empty($aSortTopVars)) { $this->aTopViews = $this->reorderViews($this->aTopViews, $aSortTopVars); } $oViewStateBar = new ViewStateBar(); foreach ($this->aTopViews as $mKey => $oTopView) { $oViewStateBar->addStateBarTopView($oTopView); } if ($tpl instanceof BsBaseTemplate) { $tpl->data['bs_dataBeforeContent']['bs-statebar'] = array('position' => 20, 'label' => wfMessage('prefs-statebar')->text(), 'content' => $oViewStateBar); } else { //this is the case when BlueSpice Skin is not active, so use vector methods. $tpl->data['prebodyhtml'] .= $oViewStateBar; } return true; }
/** * Display the tabs for a course or institution. * * @since 0.1 * * @param SkinTemplate $sktemplate * @param array $links * @param Title $title */ protected static function displayTabs(SkinTemplate &$sktemplate, array &$links, Title $title) { $classes = array(EP_NS_INSTITUTION => 'EPOrg', EP_NS_COURSE => 'EPCourse'); $exists = null; if (array_key_exists($title->getNamespace(), $classes)) { $links['views'] = array(); $links['actions'] = array(); $user = $sktemplate->getUser(); $class = $classes[$title->getNamespace()]; $exists = $class::hasIdentifier($title->getText()); $type = $sktemplate->getRequest()->getText('action'); $isSpecial = $sktemplate->getTitle()->isSpecialPage(); if ($exists) { $links['views']['view'] = array('class' => !$isSpecial && $type === '' ? 'selected' : false, 'text' => wfMsg('ep-tab-view'), 'href' => $title->getLocalUrl()); } if ($user->isAllowed($class::getEditRight())) { $links['views']['edit'] = array('class' => $type === 'edit' ? 'selected' : false, 'text' => wfMsg($exists ? 'ep-tab-edit' : 'ep-tab-create'), 'href' => $title->getLocalUrl(array('action' => 'edit'))); } if ($exists) { $links['views']['history'] = array('class' => $type === 'history' ? 'selected' : false, 'text' => wfMsg('ep-tab-history'), 'href' => $title->getLocalUrl(array('action' => 'history'))); if ($title->getNamespace() === EP_NS_COURSE) { if ($user->isAllowed('ep-enroll')) { $student = EPStudent::newFromUser($user); if ($student === false || !$student->hasCourse(array('name' => $title->getText()))) { $links['views']['enroll'] = array('class' => $isSpecial ? 'selected' : false, 'text' => wfMsg('ep-tab-enroll'), 'href' => SpecialPage::getTitleFor('Enroll', $title->getText())->getLocalURL()); } } } } } }