/**
  * Retrieves the text for display in FormattingHelp. Called via AJAX.
  * @param string $sOutput rendered HTML output that is to be displayed.
  * @return bool allow other hooked methods to be executed. Always true.
  */
 public static function getFormattingHelp()
 {
     if (BsCore::checkAccessAdmission('edit') === false) {
         return true;
     }
     $sOutput = "<table id='bs-formattinghelp-table' class='wikitable'>\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th></th>\n\t\t\t\t\t<th>" . wfMessage('bs-formattinghelp-help-syntax')->escaped() . "</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t\t\t<tr>\n\t\t\t\t\t<td width='20%'><strong>" . wfMessage('bs-formattinghelp-help-bold')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>'''" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "'''</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td width='20%'><strong>" . wfMessage('bs-formattinghelp-help-italic')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>''" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "''</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-whitespace')->escaped() . "</strong></td>\n\t\t\t\t\t<td>&amp;nbsp;</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-nowiki')->escaped() . "</strong></td>\n\t\t\t\t\t<td>&lt;nowiki&gt;'''" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "'''&lt;/nowiki&gt;</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-color')->escaped() . "</strong></td>\n\t\t\t\t\t<td>&lt;font color=\"#DDBB65\"&gt;" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "&lt;/font&gt;</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-headline')->escaped() . "</strong></td>\n\t\t\t\t\t<td>= " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 1 =<br/>\n\t\t\t\t\t\t== " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 2 ==<br/>\n\t\t\t\t\t\t=== " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 3 ===<br/>\n\t\t\t\t\t\t==== " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 4 ====<br/>\n\t\t\t\t\t\t===== " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 5 =====<br/>\n\t\t\t\t\t\t====== " . wfMessage('bs-formattinghelp-help-headline')->escaped() . " 6 ======</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-linebreak')->escaped() . "</strong></td>\n\t\t\t\t\t<td>&lt;br /&gt;</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-ul')->escaped() . "</strong></td>\n\t\t\t\t\t<td>* " . wfMessage('bs-formattinghelp-help-listitem')->escaped() . "<br/>\n\t\t\t\t\t\t** " . wfMessage('bs-formattinghelp-help-subitem')->escaped() . "<br/>\n\t\t\t\t\t\t* " . wfMessage('bs-formattinghelp-help-listitem')->escaped() . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-numberedlist')->escaped() . "</strong></td>\n\t\t\t\t\t<td># " . wfMessage('bs-formattinghelp-help-listitem')->escaped() . "<br/>\n\t\t\t\t\t\t## " . wfMessage('bs-formattinghelp-help-subitem')->escaped() . "<br/>\n\t\t\t\t\t\t# " . wfMessage('bs-formattinghelp-help-listitem')->escaped() . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-link')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>[[" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "]]</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-link-alt')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>[[" . wfMessage('bs-ns')->escaped() . ":" . wfMessage('bs-formattinghelp-help-example-text')->escaped() . "|" . wfMessage('bs-formattinghelp-help-caption')->escaped() . "]]</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-extlink')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>[http://www.hallowelt.biz http://www.hallowelt.biz]</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-hr')->escaped() . "</strong></td>\n\t\t\t\t\t<td>----</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><strong>" . wfMessage('bs-formattinghelp-help-template')->escaped() . "</strong></td>\n\t\t\t\t\t<td><nowiki>{{" . wfMessage('bs-formattinghelp-help-templatename')->escaped() . "}}</nowiki></td>\n\t\t\t\t</tr>\n\t\t\t</tbody>\n\t\t\t</table>";
     return $sOutput;
 }
 public static function ajaxGetArticlesByNamespaceId()
 {
     if (BsCore::checkAccessAdmission('edit') === false) {
         return true;
     }
     global $wgOut, $wgRequest;
     $wgOut->disable();
     $oParams = BsExtJSStoreParams::newFromRequest();
     $iStart = $wgRequest->getInt('start', 0);
     $sSort = $oParams->getSort('page_title');
     $sDirection = $oParams->getDirection();
     $iLimit = $wgRequest->getInt('limit', 25);
     $sDisplayMode = $wgRequest->getVal('displayMode', 'only-assigned');
     $iNamespaceId = $wgRequest->getInt('namespaceId', -99);
     $aActivatedNamespaces = BsConfig::get('MW::ResponsibleEditors::ActivatedNamespaces');
     $oResult = new stdClass();
     $aTables = array('bs_responsible_editors', 'user', 'page');
     $aVariables = array('page_id', 'page_title', 'page_namespace');
     $aConditions = array('page_namespace' => $aActivatedNamespaces);
     if ($sDisplayMode == 'only-assigned') {
         $aConditions[] = 're_user_id IS NOT NULL ';
     } else {
         if ($sDisplayMode == 'only-not-assigned') {
             $aConditions[] = 're_user_id IS NULL ';
         }
     }
     if ($iNamespaceId != -99) {
         $aConditions['page_namespace'] = $iNamespaceId;
     }
     $aOptions = array('ORDER BY' => $sSort . ' ' . $sDirection, 'LIMIT' => $iLimit, 'OFFSET' => $iStart, 'GROUP BY' => 'page_id');
     if ($sSort == 'user_displayname') {
         $aOptions['ORDER BY'] = 'user_real_name, user_name ' . $sDirection;
     }
     $aJoinOptions = array('user' => array('JOIN', 'user_id = re_user_id'), 'page' => array('RIGHT JOIN', 'page_id = re_page_id'));
     $dbr = wfGetDB(DB_SLAVE);
     //TODO: Rework "total" calculation. This seems very complicated but it
     //should be as easy as excuting the main query without LIMIT/OFFSET.
     if ($sDisplayMode == 'only-assigned' || $sDisplayMode == 'only-not-assigned') {
         $row = $dbr->select(array('page', 'bs_responsible_editors'), 'page_id AS cnt', $aConditions, __METHOD__, array('GROUP BY' => 'page_id'), array('page' => array('RIGHT JOIN', 'page_id = re_page_id')));
         $oResult->total = $row->numRows();
     }
     if ($sDisplayMode == 'all') {
         $aConditionsWithoutRePageID = $aConditions;
         unset($aConditionsWithoutRePageID[0]);
         $row = $dbr->selectRow('page', 'COUNT( page_id ) AS cnt', $aConditionsWithoutRePageID);
         $oResult->total = $row->cnt;
     }
     $res = $dbr->select($aTables, $aVariables, $aConditions, __METHOD__, $aOptions, $aJoinOptions);
     $oResult->pages = array();
     foreach ($res as $row) {
         $oTitle = Title::newFromId($row->page_id);
         $iPageId = $row->page_id;
         $sPageNsId = !empty($row->page_namespace) ? $row->page_namespace : 0;
         $sPageTitle = $row->page_title;
         $oPage = new stdClass();
         $oPage->page_id = $iPageId;
         $oPage->page_namespace = $sPageNsId;
         $oPage->page_title = $sPageTitle;
         $oPage->page_prefixedtext = $oTitle->getPrefixedText();
         $oPage->users = array();
         $aEditorIDs = BsExtensionManager::getExtension('ResponsibleEditors')->getResponsibleEditorIdsByArticleId($row->page_id);
         $aEditorIDs = array_unique($aEditorIDs);
         foreach ($aEditorIDs as $iEditorID) {
             $oUser = User::newFromId($iEditorID);
             if ($oUser == null) {
                 continue;
             }
             $oPage->users[] = array('user_id' => $iEditorID, 'user_page_link_url' => $oUser->getUserPage()->getFullUrl(), 'user_displayname' => BsCore::getUserDisplayName($oUser));
         }
         $oResult->pages[] = $oPage;
     }
     return FormatJson::encode($oResult);
 }
 /**
  * Creates or changes a review for a page. Called by remote handler.
  * @return bool Allow other hooked methods to be executed. Always true.
  */
 public static function doEditReview()
 {
     if (BsCore::checkAccessAdmission('workflowedit') === false) {
         return true;
     }
     $aAnswer = array('success' => true, 'errors' => array(), 'messages' => array());
     $oUser = BsCore::loadCurrentUser();
     $oReview = BsExtensionManager::getExtension('Review');
     $userIsSysop = in_array('sysop', $oUser->getGroups());
     //TODO: getEffectiveGroups()?
     if (!$userIsSysop && !$oUser->isAllowed('workflowedit')) {
         $aAnswer['success'] = false;
         $aAnswer['messages'][] = wfMessage('bs-review-save-norights')->plain();
         return json_encode($aAnswer);
     }
     global $wgRequest;
     $paramRvPid = $wgRequest->getInt('pid', -1);
     // Check for id 0 prevents special pages to be put on a review
     if (empty($paramRvPid)) {
         $aAnswer['success'] = false;
         $aAnswer['messages'][] = wfMessage('bs-review-save-noid')->plain();
         return json_encode($aAnswer);
     }
     $oReviewProcess = BsReviewProcess::newFromPid($paramRvPid);
     $bIsEdit = false;
     if (is_object($oReviewProcess) && $oReviewProcess->hasSteps()) {
         $bIsEdit = true;
     }
     if (!$userIsSysop && $oReviewProcess && BsConfig::get('MW::Review::CheckOwner') && $oReviewProcess->owner != $oUser->getID()) {
         $aAnswer['success'] = false;
         $aAnswer['messages'][] = wfMessage('bs-review-save-norights')->plain();
         return json_encode($aAnswer);
     }
     $paramCmd = $wgRequest->getVal('cmd', '');
     $paramSaveTmpl = $wgRequest->getInt('save_tmpl', 0);
     if (!($paramCmd === false)) {
         switch ($paramCmd) {
             case 'insert':
                 $aErrors = array();
                 $review = BsReviewProcess::newFromJSON($wgRequest->getVal('review', ''), $aErrors);
                 if (is_array($aErrors) && count($aErrors) > 0) {
                     $aAnswer['success'] = false;
                     foreach ($aErrors as $sError) {
                         $aAnswer['messages'][] = wfMessage('bs-review-' . $sError)->plain();
                     }
                     return json_encode($aAnswer);
                 }
                 $review->setOwner($oUser->getID());
                 $oOldReview = BsReviewProcess::newFromPid($paramRvPid);
                 $update = is_object($oOldReview) ? $oOldReview->getPid() : false;
                 BsReviewProcess::removeReviewSteps($paramRvPid);
                 if ($paramSaveTmpl == 1) {
                     $paramTmplChoice = $wgRequest->getInt('tmpl_choice', -1);
                     $paramTmplName = $wgRequest->getVal('tmpl_name', '');
                     $review->asTemplate($paramTmplChoice, $paramTmplName);
                 }
                 if (!is_array($review->steps)) {
                     $aAnswer['success'] = false;
                     $aAnswer['messages'][] = wfMessage('bs-review-save-nosteps')->plain();
                     return json_encode($aAnswer);
                 }
                 if ($review->store($update)) {
                     $oTitle = Title::newFromID($paramRvPid);
                     $oTitle->invalidateCache();
                     $oWatchlist = WatchedItem::fromUserTitle($oUser, $oTitle);
                     if (!$oWatchlist->isWatched()) {
                         $oWatchlist->addWatch();
                     }
                     $aParams = array('action' => $bIsEdit ? 'modify' : 'create', 'target' => $oTitle, 'comment' => '', 'params' => null, 'doer' => $oUser);
                     $oReview->oLogger->addEntry($aParams['action'], $aParams['target'], $aParams['comment'], $aParams['params'], $aParams['doer']);
                     $aAnswer['messages'][] = wfMessage('bs-review-save-success')->plain();
                     // Identify owner
                     $oReviewProcess = BsReviewProcess::newFromPid($paramRvPid);
                     $oReview->emailNotifyNextUsers($oReviewProcess);
                     return json_encode($aAnswer);
                 } else {
                     $aAnswer['success'] = false;
                     $aAnswer['messages'][] = wfMessage('bs-review-save-error')->plain();
                     return json_encode($aAnswer);
                 }
                 break;
                 // 22.08.13 STM: WTF?
             // 22.08.13 STM: WTF?
             case 'delete':
                 BsReviewProcess::removeReviews($paramRvPid);
                 $oTitle = Title::newFromID($paramRvPid);
                 $oTitle->invalidateCache();
                 $oWatchlist = WatchedItem::fromUserTitle($oUser, $oTitle);
                 if ($oWatchlist->isWatched()) {
                     $oWatchlist->removeWatch();
                 }
                 $aParams = array('action' => 'delete', 'target' => $oTitle, 'comment' => '', 'params' => null, 'doer' => $oUser);
                 $oReview->oLogger->addEntry($aParams['action'], $aParams['target'], $aParams['comment'], $aParams['params'], $aParams['doer']);
                 $aAnswer['messages'][] = wfMessage('bs-review-save-removed')->plain();
                 return json_encode($aAnswer);
                 break;
         }
     }
     return true;
 }
 public static function addCategoriesToArticle($iArticleId)
 {
     if (BsCore::checkAccessAdmission('read') === false) {
         return FormatJson::encode(array('success' => false));
     }
     if (wfReadOnly()) {
         global $wgReadOnly;
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-readonly', $wgReadOnly)->plain()));
     }
     $sTags = RequestContext::getMain()->getRequest()->getVal('categories');
     $aTags = empty($sTags) ? array() : explode(',', $sTags);
     $oTitle = Title::newFromID($iArticleId);
     if (is_null($oTitle) || !$oTitle->exists()) {
         $oRequest = RequestContext::getMain()->getRequest();
         $sPageName = $oRequest->getVal("page_name", "");
         $oTitle = Title::newFromText($sPageName);
     }
     $sCat = BsNamespaceHelper::getNamespaceName(NS_CATEGORY);
     $sText = BsPageContentProvider::getInstance()->getContentFromTitle($oTitle, Revision::RAW);
     // Remove all before adding
     $sPattern = '#^\\[\\[' . $sCat . ':.*?\\]\\]#im';
     $sText = preg_replace($sPattern, '', $sText);
     if (!empty($aTags)) {
         foreach ($aTags as $sTag) {
             $sText .= "\n[[" . $sCat . ":{$sTag}]]";
         }
     }
     $oWikiPage = new WikiPage($oTitle);
     $oUser = RequestContext::getMain()->getUser();
     $oContent = new WikitextContent($sText);
     $oStatus = $oWikiPage->doEditContent($oContent, "", 0, false, $oUser);
     if (!$oStatus->isGood()) {
         return FormatJson::encode(array('success' => false, 'msg' => $oStatus->getMessage()));
     }
     return FormatJson::encode(array('success' => true));
 }
 /**
  * removes a usergroup
  * @param string $output the ajax output string
  */
 public static function removeGroup($sGroup)
 {
     if (wfReadOnly()) {
         global $wgReadOnly;
         return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-readonly', $wgReadOnly)->plain()));
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         return true;
     }
     global $wgGroupPermissions, $wgAdditionalGroups, $wgNamespacePermissionLockdown;
     $output = FormatJson::encode(array('success' => true, 'message' => wfMessage('bs-groupmanager-grpremoved')->plain()));
     if ($sGroup) {
         if (!isset($wgAdditionalGroups[$sGroup])) {
             return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-groupmanager-msgnotremovable')->plain()));
         }
         $wgAdditionalGroups[$sGroup] = false;
         $dbw = wfGetDB(DB_MASTER);
         $res = $dbw->delete('user_groups', array('ug_group' => $sGroup));
         if ($res === false) {
             return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-groupmanager-removegroup-message-unknown')->plain()));
         }
         $result = BsExtensionManager::getExtension('GroupManager')->saveData();
         wfRunHooks("BSGroupManagerGroupDeleted", array($sGroup, &$result));
         if ($result['success'] === false) {
             return FormatJson::encode($result);
         }
     }
     return $output;
 }
 /**
  * Deletes an interwiki link. Called via AJAX function
  * @return bool allow other hooked methods to be executed. always true.
  */
 public static function doDeleteInterWikiLink($iw_prefix)
 {
     if (wfReadOnly()) {
         global $wgReadOnly;
         return FormatJson::encode(array('success' => false, 'message' => array(wfMessage('bs-readonly', $wgReadOnly)->plain())));
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         return true;
     }
     $aAnswer = array('success' => true, 'errors' => array(), 'message' => array());
     if ($aAnswer['success']) {
         $dbw = wfGetDB(DB_MASTER);
         $res1 = $dbw->delete('interwiki', array('iw_prefix' => $iw_prefix));
     }
     if ($res1 === false) {
         $aAnswer['success'] = false;
         $aAnswer['errors'][] = array('message' => wfMessage('bs-interwikilinks-nourl')->plain());
     }
     if ($aAnswer['success']) {
         $aAnswer['message'][] = wfMessage('bs-interwikilinks-link-deleted')->plain();
     }
     self::purgeTitles($iw_prefix);
     return FormatJson::encode($aAnswer);
 }
 /**
  * PW(25.03.2015) TODO: Use API
  * @global User $wgUser
  * @global Language $wgLang
  * @return string
  */
 public static function doSaveArticle()
 {
     $aResult = $aOutput = array('saveresult' => 'fail', 'message' => '', 'edittime' => '', 'summary' => '', 'starttime' => wfTimestamp(TS_MW, time() + 2));
     if (BsCore::checkAccessAdmission('read') === false) {
         $aResult['message'] = wfMessage('bs-permissionerror')->plain();
         return FormatJson::encode($aResult);
     }
     global $wgLang, $wgRequest;
     $sArticleId = $wgRequest->getInt('articleId', 0);
     $sText = $wgRequest->getVal('text', '');
     $sPageName = $wgRequest->getVal('pageName', '');
     $sSummary = $wgRequest->getVal('summary', '');
     $iSection = $wgRequest->getInt('editsection', 0);
     $sReturnEditTime = wfTimestampNow();
     if ($sSummary == 'false') {
         $sSummary = '/* ' . wfMessage('bs-visualeditor-no-summary')->plain() . ' */';
     }
     //PW(25.03.2015) TODO: Use Wikipage
     $oArticle = Article::newFromID($sArticleId);
     if (is_null($oArticle)) {
         $oTitle = Title::newFromText($sPageName);
         if (is_null($oTitle) || !$oTitle->exists()) {
             $aResult['message'] = wfMessage('badtitle')->plain();
             return FormatJson::encode($aResult);
         }
         $oArticle = new Article($oTitle);
     }
     if ($iSection) {
         $sText = $oArticle->replaceSection($iSection, $sText);
     }
     //PW(25.03.2015) TODO: Deprecated since MW 1.21 use
     //Wikipage::doEditContent instead
     $oSaveResult = $oArticle->doEdit($sText, $sSummary);
     if ($oSaveResult->isGood()) {
         $sTime = $wgLang->timeanddate($sReturnEditTime, true);
         $aResult['edittime'] = $sReturnEditTime;
         $aResult['saveresult'] = 'ok';
         $aResult['message'] = wfMessage('bs-visualeditor-save-message', $sTime, $sSummary)->plain();
         $aResult['summary'] = $sSummary;
     } else {
         $aResult['message'] = $oSaveResult->getMessage()->plain();
     }
     return FormatJson::encode($aResult);
 }
 /**
  * Handles the get wanted articles ajax request.
  * @param string $sOut The server response string.
  * @return bool true on correct processing. JSON answer is in $sOut parameter.
  */
 public static function ajaxGetWantedArticles($iCount, $sSort, $sOrder, $sType, $sTitle)
 {
     if (BsCore::checkAccessAdmission('read') === false) {
         return true;
     }
     $aResult = array('success' => false, 'view' => '', 'message' => '');
     //Validation
     $oValidationICount = BsValidator::isValid('IntegerRange', $iCount, array('fullResponse' => true, 'lowerBoundary' => 1, 'upperBoundary' => 30));
     if ($oValidationICount->getErrorCode()) {
         return false;
     }
     if (!in_array($sSort, array('', 'time', 'title'))) {
         return false;
     }
     if (!in_array($sOrder, array('', 'ASC', 'DESC'))) {
         return false;
     }
     $oWantedArticle = BsExtensionManager::getExtension('WantedArticle');
     //Create list
     $aWishList = $oWantedArticle->getTitleListFromTitle($oWantedArticle->getDataSourceTemplateArticle()->getTitle());
     switch ($sSort) {
         case 'title':
             $aTitleList = $oWantedArticle->sortWishListByTitle($aWishList);
             break;
         case 'time':
         default:
             $aTitleList = $oWantedArticle->getDefaultTitleList($aWishList);
     }
     if ($sOrder == 'ASC') {
         $aTitleList = array_reverse($aTitleList);
     }
     $oWishListView = new ViewWantedArticleTag();
     $oWishListView->setTitle($sTitle)->setType($sType)->setOrder($sOrder)->setSort($sSort)->setCount($iCount)->setList($aTitleList);
     //result
     $aResult['success'] = true;
     $aResult['view'] = $oWishListView->execute();
     return json_encode($aResult);
 }
 public static function getPages()
 {
     if (BsCore::checkAccessAdmission('read') === false) {
         return true;
     }
     global $wgUser, $wgContLang;
     $dbr = wfGetDB(DB_SLAVE);
     $dbr->clearFlag(DBO_TRX);
     $aNamespaces = $wgContLang->getNamespaces();
     $res = $dbr->select('page', array('page_title', 'page_namespace'), array(), __METHOD__, array('ORDER BY' => 'page_title'));
     $oSpecialRSS = SpecialPage::getTitleFor('RSSFeeder');
     $sUserName = $wgUser->getName();
     $sUserToken = $wgUser->getToken();
     $aPageRSS = array();
     while ($row = $res->fetchObject()) {
         $sNSPrefix = '';
         if ($row->page_namespace && isset($aNamespaces[$row->page_namespace])) {
             $sNSPrefix = ' (NS:' . $aNamespaces[$row->page_namespace] . ')';
         }
         $aPageRSS[] = array('page' => str_replace('_', ' ', $row->page_title . $sNSPrefix), 'url' => $oSpecialRSS->getLinkUrl(array('Page' => 'followPage', 'p' => $row->page_title, 'ns' => $row->page_namespace, 'u' => $sUserName, 'h' => $sUserToken)));
     }
     return FormatJson::encode(array('pages' => $aPageRSS));
 }
 protected static function writeGroupSettings($aGroupPermissions, $aNamespacePermissionLockdown)
 {
     global $bsgPermissionManagerGroupSettingsFile;
     if (wfReadOnly()) {
         global $wgReadOnly;
         return array('success' => false, 'msg' => wfMessage('bs-readonly', $wgReadOnly)->plain());
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         return true;
     }
     wfRunHooks('BsNamespacemanageOnSavePermission', array(&$aNamespacePermissionLockdown, &$aGroupPermissions));
     wfRunHooks('BsPermissionManager::writeGroupSettings', array(&$aNamespacePermissionLockdown, &$aGroupPermissions));
     self::backupExistingSettings();
     $sSaveContent = "<?php\n";
     foreach ($aGroupPermissions as $sGroup => $aPermissions) {
         foreach ($aPermissions as $sPermission => $bValue) {
             $sSaveContent .= "\$wgGroupPermissions['{$sGroup}']['{$sPermission}'] = " . ($bValue ? 'true' : 'false') . ";\n";
         }
     }
     if (is_array($aNamespacePermissionLockdown)) {
         foreach ($aNamespacePermissionLockdown as $iNS => $aPermissions) {
             $isReadLockdown = false;
             $sNsCanonicalName = MWNamespace::getCanonicalName($iNS);
             if ($iNS == NS_MAIN) {
                 $sNsCanonicalName = 'MAIN';
             }
             $sNsConstant = 'NS_' . strtoupper($sNsCanonicalName);
             foreach ($aPermissions as $sPermission => $aGroups) {
                 if (empty($aGroups)) {
                     continue;
                 }
                 $sSaveContent .= "\$wgNamespacePermissionLockdown[{$sNsConstant}]['{$sPermission}']" . " = array(" . (count($aGroups) ? "'" . implode("','", $aGroups) . "'" : '') . ");\n";
                 if ($sPermission == 'read') {
                     $isReadLockdown = true;
                 }
             }
             if ($isReadLockdown) {
                 $sSaveContent .= "\$wgNonincludableNamespaces[] = {$sNsConstant};\n";
             }
         }
     }
     $res = file_put_contents($bsgPermissionManagerGroupSettingsFile, $sSaveContent);
     if ($res) {
         return array('success' => true);
     } else {
         return array('success' => false, 'msg' => 'Not able to create or write "' . $bsgPermissionManagerGroupSettingsFile . '".');
     }
 }
 /**
  * Delete a given namespace.
  */
 public function deleteNamespace($iNS, $iDoArticle)
 {
     if (wfReadOnly()) {
         global $wgReadOnly;
         return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-readonly', $wgReadOnly)->plain()));
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         return true;
     }
     $iNS = BsCore::sanitize($iNS, '', BsPARAMTYPE::INT);
     if (!$iNS) {
         return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-namespacemanager-invalid-id')->plain()));
     }
     global $wgContLang;
     $aUserNamespaces = self::getUserNamespaces(true);
     $aNamespacesToRemove = array(array($iNS, 0));
     $sNamespace = $aUserNamespaces[$iNS]['name'];
     if (!strstr($sNamespace, '_' . $wgContLang->getNsText(NS_TALK))) {
         if (isset($aUserNamespaces[$iNS + 1]) && strstr($aUserNamespaces[$iNS + 1]['name'], '_' . $wgContLang->getNsText(NS_TALK))) {
             $aNamespacesToRemove[] = array($iNS + 1, 1);
             $sNamespace = $aUserNamespaces[$iNS + 1]['name'];
         }
     }
     $bErrors = false;
     if (empty($iDoArticle)) {
         $iDoArticle = 0;
     }
     switch ($iDoArticle) {
         case 0:
             foreach ($aNamespacesToRemove as $aNamespace) {
                 $iNs = $aNamespace[0];
                 if (!NamespaceNuker::removeAllNamespacePages($iNs, $aUserNamespaces[$iNs]['name'])) {
                     $bErrors = true;
                 } else {
                     $aUserNamespaces[$aNamespace[0]] = false;
                 }
             }
             break;
         case 1:
             foreach ($aNamespacesToRemove as $aNamespace) {
                 $iNs = $aNamespace[0];
                 if (!NamespaceNuker::moveAllPagesIntoMain($iNs, $aUserNamespaces[$iNs]['name'])) {
                     $bErrors = true;
                 } else {
                     $aUserNamespaces[$aNamespace[0]] = false;
                 }
             }
             break;
         case 2:
         default:
             foreach ($aNamespacesToRemove as $aNamespace) {
                 $iNs = $aNamespace[0];
                 if (!NamespaceNuker::moveAllPagesIntoMain($iNs, $aUserNamespaces[$iNs]['name'], true)) {
                     $bErrors = true;
                 } else {
                     $aUserNamespaces[$aNamespace[0]] = false;
                 }
             }
             break;
     }
     if (!$bErrors) {
         $aResult = self::setUserNamespaces($aUserNamespaces);
         $aResult['message'] = wfMessage('bs-namespacemanager-nsremoved')->plain();
         return FormatJson::encode($aResult);
     } else {
         return FormatJson::encode(array('success' => false, 'message' => wfMessage('bs-namespacemanager-error_on_remove_namespace')->plain()));
     }
 }
 /**
  * Archivess a shout for the current page.
  * This function is called remotely via AJAX-Handler.
  * @param string $sOutput success state of database action
  * @return bool allow other hooked methods to be executed
  */
 public static function archiveShout($iShoutId, $iArticleId)
 {
     if (BsCore::checkAccessAdmission('readshoutbox') === false || BsCore::checkAccessAdmission('writeshoutbox') === false) {
         return true;
     }
     global $wgUser;
     $iUserId = $wgUser->getId();
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select('bs_shoutbox', 'sb_user_id', array('sb_id' => $iShoutId), __METHOD__, array('LIMIT' => '1'));
     $row = $dbw->fetchRow($res);
     // If we don't have archiveshoutbox rights, maybe we can delete our own shout?
     if (!BsCore::checkAccessAdmission('archiveshoutbox')) {
         //if setting for "allow own entries to be archived" is set + username != shoutbox-entry-username => exit
         if (BsConfig::get('MW::ShoutBox::AllowArchive') && $iUserId != $row['sb_user_id']) {
             $sOutput = wfMessage('bs-shoutbox-archive-failure-user')->plain();
             return true;
         }
     }
     $res = $dbw->update('bs_shoutbox', array('sb_archived' => '1'), array('sb_id' => $iShoutId));
     self::invalidateShoutBoxCache($iArticleId);
     $sResponse = $res == true ? 'bs-shoutbox-archive-success' : 'bs-shoutbox-archive-failure';
     $sOutput = wfMessage($sResponse)->plain();
     return $sOutput;
 }
 /**
  * Deletes a template
  * @return bool allow other hooked methods to be executed. Always true.
  */
 public static function doDeleteTemplate($iId)
 {
     if (wfReadOnly()) {
         global $wgReadOnly;
         return json_encode(array('success' => false, 'message' => array(wfMessage('bs-readonly', $wgReadOnly)->plain())));
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         return true;
     }
     $aAnswer = array('success' => true, 'errors' => array(), 'message' => array());
     if (empty($iId)) {
         $aAnswer['success'] = false;
         $aAnswer['errors'][] = wfMessage('bs-pagetemplates-no-id')->plain();
     }
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->delete('bs_pagetemplate', array('pt_id' => $iId));
     if ($res === false) {
         $aAnswer['success'] = false;
         $aAnswer['errors'][] = wfMessage('bs-pagetemplates-dberror')->plain();
     }
     if ($aAnswer['success']) {
         $aAnswer['message'][] = wfMessage('bs-pagetemplates-tpl-deleted')->plain();
     }
     return json_encode($aAnswer);
 }
 public static function disableFeedback()
 {
     $oResult = (object) array('success' => false, 'message' => '');
     if (BsCore::checkAccessAdmission('edit') === false) {
         //PW TODO: add error message
         return FormatJson::encode($oResult);
     }
     BsConfig::set('MW::BlueSpiceProjectFeedbackHelper::Active', false);
     BsConfig::saveSettings();
     $oResult->success = true;
     return FormatJson::encode($oResult);
 }
 /**
  * This method actually generates the output
  * @param array $aParams not used here
  * @return string HTML output
  */
 public function execute($aParams = false)
 {
     global $wgUser;
     $sUserName = $this->oUser->getName();
     $sUserRealName = $this->oUser->getRealName();
     //Fallback for old entries without user_id
     if ($this->oUser->isAnon()) {
         $sUserName = $this->sUsername;
     }
     $aOut = array();
     $aOut[] = '<li class="bs-sb-listitem clearfix" id="bs-sb-' . $this->iShoutID . '">';
     $aOut[] = '  <div class="bs-user-image">';
     if ($this->oMiniProfile instanceof ViewUserMiniProfile) {
         $aOut[] = $this->oMiniProfile->execute();
     }
     $aOut[] = '  </div>';
     $aOut[] = '  <div class="bs-sb-message">';
     $aOut[] = '    <div class="bs-sb-message-head">';
     $aOut[] = '      <strong>' . $sUserName . '</strong>';
     if (!empty($sUserRealName)) {
         $aOut[] = '      <span class="bs-sb-meassage-head-small">' . $sUserRealName . '</span>';
     }
     $aOut[] = '    </div>';
     if (isset($this->sDate)) {
         $aOut[] = '<div class="bs-sb-message-time">' . $this->sDate;
         $aOut[] = '</div> ';
     }
     $aOut[] = '    <div class="bs-sb-message-text">' . nl2br($this->sMessage);
     $aOut[] = '    </div> ';
     $aOut[] = '  </div>';
     $sArchiveButton = '';
     $sArchiveButtonEnabled = '  <div class="bs-sb-archive"></div>';
     //set button if user has the right to archive
     if (BsCore::checkAccessAdmission('archiveshoutbox')) {
         $sArchiveButton = $sArchiveButtonEnabled;
     }
     //if setting for "allow own entries to be archived" is set + username == shoutbox-entry-username => set button
     if (BsConfig::get('MW::ShoutBox::AllowArchive') && $wgUser->getName() == $sUserName) {
         $sArchiveButton = $sArchiveButtonEnabled;
     }
     $aOut[] = $sArchiveButton;
     $aOut[] = '</li>';
     return implode("\n", $aOut);
 }
 public static function setUserGroups($aUserIds, $aGroups)
 {
     $res = $resDelGroups = $resInsGroups = $resERealUser = false;
     $aAnswer = array('success' => true, 'errors' => array(), 'message' => array());
     if (wfReadOnly()) {
         global $wgReadOnly;
         $aAnswer['success'] = false;
         $aAnswer['message'][] = wfMessage('bs-readonly', $wgReadOnly)->plain();
     }
     if (BsCore::checkAccessAdmission('wikiadmin') === false) {
         $aAnswer['success'] = false;
         $aAnswer['message'][] = wfMessage('bs-wikiadmin-notallowed')->plain();
     }
     global $wgUser;
     if (in_array($wgUser->getId(), $aUserIds) && in_array('sysop', $wgUser->getEffectiveGroups()) && !in_array('sysop', $aGroups)) {
         $aAnswer['success'] = false;
         $aAnswer['errors'][] = array('id' => 'groups', 'message' => wfMessage('bs-usermanager-no-self-desysop')->plain());
     }
     if ($aAnswer['success']) {
         $dbw = wfGetDB(DB_MASTER);
         $resDelGroups = $dbw->delete('user_groups', array('ug_user' => $aUserIds));
         $resInsGroups = true;
         if (is_array($aGroups)) {
             foreach ($aGroups as $sGroup) {
                 if (in_array($sGroup, self::$excludegroups)) {
                     continue;
                 }
                 foreach ($aUserIds as $iUserId) {
                     $resInsGroups = $dbw->insert('user_groups', array('ug_user' => (int) $iUserId, 'ug_group' => addslashes($sGroup)));
                     if ($resInsGroups === false) {
                         break;
                     }
                 }
             }
         }
     }
     if ($resDelGroups === false || $resInsGroups === false) {
         $aAnswer['success'] = false;
         $aAnswer['message'][] = wfMessage('bs-usermanager-db-error')->plain();
     }
     if ($aAnswer['success']) {
         $aAnswer['message'][] = wfMessage('bs-usermanager-save-successful')->plain();
     }
     return FormatJson::encode($aAnswer);
 }
 /**
  *
  * @param string $sText
  * @param string $sUsername
  * @param Title $oTitle
  * @param integer $iSection
  * @return boolean
  */
 public static function saveUserEditing($sUsername, $oTitle, $iSection = -1)
 {
     if (BsCore::checkAccessAdmission('edit') === false) {
         return true;
     }
     $db = wfGetDB(DB_MASTER);
     $sTable = 'bs_saferedit';
     $aFields = array("se_timestamp" => wfTimestamp(TS_MW, time()));
     $aConditions = array("se_user_name" => $sUsername, "se_page_title" => $oTitle->getDBkey(), "se_page_namespace" => $oTitle->getNamespace(), "se_edit_section" => $iSection);
     $aOptions = array('ORDER BY' => 'se_id DESC', 'LIMIT' => 1);
     if ($oRow = $db->selectRow($sTable, array('se_id'), $aConditions, __METHOD__, $aOptions)) {
         $oTitle->invalidateCache();
         return $db->update($sTable, $aFields, array("se_id" => $oRow->se_id));
     }
     $oTitle->invalidateCache();
     return $db->insert($sTable, $aConditions + $aFields);
 }