public function getActiveFilterText() { $this->getActiveValues(); $aI18NValues = array(); foreach ($this->aActiveValues as $sValue) { $aI18NValues[] = BsNamespaceHelper::getNamespaceName($sValue); } return implode(", ", $aI18NValues); }
/** * Renders the pagetemplates form which is displayed when creating a new article * @param bool $bReturnHTML If set, the form is returned as HTML, otherwise as wiki code. * @return string The rendered output */ protected function renderPageTemplates() { global $wgDBtype; $oTitle = $this->getTitle(); // if we are not on a wiki page, return. This is important when calling import scripts that try to create nonexistent pages, e.g. importImages if (!is_object($oTitle)) { return true; } $aRes = array(); $aOutNs = array(); $dbr = wfGetDB(DB_SLAVE); $aConds = array(); if (BsConfig::get('MW::PageTemplates::HideIfNotInTargetNs')) { if ($wgDBtype == 'postgres') { $aConds[] = "pt_target_namespace IN ('" . $oTitle->getNamespace() . "', '-99')"; } else { $aConds[] = 'pt_target_namespace IN (' . $oTitle->getNamespace() . ', -99)'; } } if ($wgDBtype == 'postgres') { $aFields = array("pt_template_title, pt_template_namespace, pt_label, pt_desc, pt_target_namespace"); } else { $aFields = array('pt_template_title', 'pt_template_namespace', 'pt_label', 'pt_desc', 'pt_target_namespace'); } $res = $dbr->select(array('bs_pagetemplate'), $aFields, $aConds, __METHOD__, array('ORDER BY' => 'pt_label')); // There is always one template for empty page it is added some lines beneath that $iCount = $dbr->numRows($res) + 1; $sOut = wfMessage('bs-pagetemplates-choose-template', $iCount)->parse(); $sOutAll = ''; $oTargetNsTitle = null; $sOut .= '<br /><br /><ul><li>'; $sOut .= BsLinkProvider::makeLink($oTitle, wfMessage('bs-pagetemplates-empty-page')->plain(), array(), array('preload' => '')); $sOut .= '<br />' . wfMessage('bs-pagetemplates-empty-page-desc')->plain(); $sOut .= '</li></ul>'; $oSortingTitle = Title::makeTitle(NS_MEDIAWIKI, 'PageTemplatesSorting'); $vOrder = BsPageContentProvider::getInstance()->getContentFromTitle($oSortingTitle); $vOrder = explode('*', $vOrder); $vOrder = array_map('trim', $vOrder); if ($res && $dbr->numRows($res) > 0) { while ($row = $dbr->fetchObject($res)) { $aRes[] = $row; } } $dbr->freeResult($res); foreach ($aRes as $row) { $oNsTitle = Title::makeTitle($row->pt_template_namespace, $row->pt_template_title); // TODO MRG (06.09.11 12:53): -99 is "all namespaces". Pls use a more telling constant if (BsConfig::get('MW::PageTemplates::ForceNamespace') && $row->pt_target_namespace != "-99" || $row->pt_target_namespace == $oTitle->getNamespace() || BsConfig::get('MW::PageTemplates::HideIfNotInTargetNs') == false) { $sNamespaceName = BsNamespaceHelper::getNamespaceName($row->pt_target_namespace); if (!isset($aOutNs[$sNamespaceName])) { $aOutNs[$sNamespaceName] = array(); } if (BsConfig::get('MW::PageTemplates::ForceNamespace')) { $oTargetNsTitle = Title::makeTitle($row->pt_target_namespace, $oTitle->getText()); } else { $oTargetNsTitle = $oTitle; } $sLink = BsLinkProvider::makeLink($oTargetNsTitle, $row->pt_label, array(), array('preload' => $oNsTitle->getPrefixedText())); $sLink = '<li>' . $sLink; if ($row->pt_desc) { $sLink .= '<br/>' . $row->pt_desc; } $sLink .= '</li>'; $aOutNs[$sNamespaceName][] = array('link' => $sLink, 'id' => $row->pt_target_namespace); } elseif ($row->pt_target_namespace == "-99") { $sLink = BsLinkProvider::makeLink($oTitle, $row->pt_label, array(), array('preload' => $oNsTitle->getPrefixedText())); $sOutAll .= '<li>' . $sLink; if ($row->pt_desc) { $sOutAll .= '<br />' . $row->pt_desc; } $sOutAll .= '</li>'; } } if (!empty($vOrder)) { $aTmp = array(); foreach ($vOrder as $key => $value) { if (empty($value)) { continue; } if (array_key_exists($value, $aOutNs)) { $aTmp[$value] = $aOutNs[$value]; } } $aOutNs = $aTmp + array_diff_key($aOutNs, $aTmp); } $aLeftCol = array(); $aRightCol = array(); foreach ($aOutNs as $sNs => $aTmpOut) { foreach ($aTmpOut as $key => $aAttribs) { $sNamespaceName = BsNamespaceHelper::getNamespaceName($aAttribs['id']); if ($aAttribs['id'] == $oTitle->getNamespace() || $aAttribs['id'] == -99) { $aLeftCol[$sNamespaceName][] = '<ul>' . $aAttribs['link'] . '</ul>'; } else { $aRightCol[$sNamespaceName][] = '<ul>' . $aAttribs['link'] . '</ul>'; } } } if ($sOutAll !== '') { $sSectionGeneral = wfMessage('bs-pagetemplates-general-section')->plain(); $aLeftCol[$sSectionGeneral][] = '<ul>' . $sOutAll . '</ul>'; } $sOut .= '<br />'; if (!empty($aLeftCol) || !empty($aRightCol) && BsConfig::get('MW::PageTemplates::HideIfNotInTargetNs') == false) { $sOut .= '<table><tr>'; if (!empty($aLeftCol)) { $sOut .= '<td style="vertical-align:top;">'; foreach ($aLeftCol as $sNamespace => $aHtml) { if ($sNamespace == wfMessage('bs-ns_all')->plain()) { $sNamespace = wfMessage('bs-pagetemplates-general-section')->plain(); } $sOut .= '<br />'; $sOut .= '<h3>' . $sNamespace . '</h3>'; $sOut .= implode('', $aHtml); } $sOut .= '</td>'; } if (BsConfig::get('MW::PageTemplates::HideIfNotInTargetNs') == false) { if (!empty($aRightCol)) { $sOut .= '<td style="vertical-align:top;">'; foreach ($aRightCol as $sNamespace => $aHtml) { $sOut .= '<br />'; $sOut .= '<h3>' . $sNamespace . '</h3>'; $sOut .= implode('', $aHtml); } $sOut .= '</td>'; } } $sOut .= '</tr></table>'; } return $sOut; }
/** * Generate a link to a wiki page for a given result * @param object $oDocument Apache_Solr_Document * @param object $oTitle Title of wiki page * @param object $oParser Parser * @return string Anchor link to the wiki page */ private function getWikiLink($oDocument, $oTitle, $oParser) { $sHtml = null; if (isset($this->oResponse->highlighting->{$oDocument->uid}->titleWord)) { $sHtml = $this->oResponse->highlighting->{$oDocument->uid}->titleWord[0]; } elseif (isset($this->oResponse->highlighting->{$oDocument->uid}->titleReverse)) { $sHtml = $this->oResponse->highlighting->{$oDocument->uid}->titleReverse[0]; } if (!is_null($sHtml)) { if ($oDocument->namespace != '0' && $oDocument->namespace != '998' && $oDocument->namespace != '999') { $sHtml = BsNamespaceHelper::getNamespaceName($oDocument->namespace) . ':' . $sHtml; } $sHtml = str_replace('_', ' ', $sHtml); } $sSearchLink = Linker::link($oTitle, $sHtml, $aCustomAttribs = array('class' => 'bs-extendedsearch-result-headline'), array(), array('known')); if (isset($this->oResponse->highlighting->{$oDocument->uid}->sections)) { $sSection = strip_tags($this->oResponse->highlighting->{$oDocument->uid}->sections[0], '<em>'); $sSectionAnchor = $oParser->guessSectionNameFromWikiText($sSection); $sSectionLink = BsLinkProvider::makeLink($oTitle, $sSection, array(), array(), array('known')); $aMatches = array(); preg_match('#.*?href="(.*?)".*?#', $sSectionLink, $aMatches); if (isset($aMatches[1])) { $sAnchor = $aMatches[1] . $sSectionAnchor; $sSectionLink = str_replace($aMatches[1], $sAnchor, $sSectionLink); } $sSearchLink .= ' <span class="bs-extendedsearch-sectionresult">(' . wfMessage('bs-extendedsearch-section')->plain() . ' ' . $sSectionLink . ')</span>'; } return $sSearchLink; }
/** * Renders the blog. Called by parser function for bs:blog tag and also from Blog::onUnknownAction. * @param string $input Inner HTML of bs:blog tag. Not used. * @param array $args List of tag attributes. * @param Parser $parser MediaWiki parser object * @return string HTML output that is to be displayed. */ public function onBlog($input, $args, $parser) { $oTitle = null; if ($parser instanceof Parser) { $oTitle = $parser->getTitle(); $parser->disableCache(); } else { $oTitle = $this->getTitle(); } $sKey = BsCacheHelper::getCacheKey('BlueSpice', 'Blog', $oTitle->getArticleID()); $aData = BsCacheHelper::get($sKey); if ($aData !== false) { return $aData; } // initialize local variables $oErrorListView = new ViewTagErrorList($this); BsExtensionManager::setContext('MW::Blog::ShowBlog'); // get all config options $iShowLimit = BsConfig::get('MW::Blog::ShowLimit'); //$blogShowTrackback = BsConfig::get('MW::Blog::ShowTrackback'); // see comment below $bShowPermalink = BsConfig::get('MW::Blog::ShowPermalink'); $bShowInfo = BsConfig::get('MW::Blog::ShowInfo'); $sSortBy = BsConfig::get('MW::Blog::SortBy'); $bMoreInNewWindow = BsConfig::get('MW::Blog::MoreInNewWindow'); $bShowAll = BsConfig::get('MW::Blog::ShowAll'); $bMoreAtEndOfEntry = BsConfig::get('MW::Blog::MoreAtEndOfEntry'); $bShowNewEntryField = BsConfig::get('MW::Blog::ShowNewEntryField'); $bNewEntryFieldPosition = BsConfig::get('MW::Blog::NewEntryFieldPosition'); $sImageRenderMode = BsConfig::get('MW::Blog::ImageRenderMode'); $sImageFloatDirection = BsConfig::get('MW::Blog::ThumbFloatDirection'); $iMaxEntryCharacters = BsConfig::get('MW::Blog::MaxEntryCharacters'); // Trackbacks are not supported the way we intend it to be. From http://www.mediawiki.org/wiki/Manual:$wgUseTrackbacks // When MediaWiki receives a trackback ping, a box will show up at the bottom of the article containing a link to the originating page //if (!$wgUseTrackbacks) $bShowTrackback = false; // get tag attributes $argsIShowLimit = BsCore::sanitizeArrayEntry($args, 'count', $iShowLimit, BsPARAMTYPE::NUMERIC | BsPARAMOPTION::DEFAULT_ON_ERROR); $argsSCategory = BsCore::sanitizeArrayEntry($args, 'cat', false, BsPARAMTYPE::STRING); $argsINamespace = BsNamespaceHelper::getNamespaceIndex(BsCore::sanitizeArrayEntry($args, 'ns', NS_BLOG, BsPARAMTYPE::STRING)); $argsBNewEntryField = BsCore::sanitizeArrayEntry($args, 'newentryfield', $bShowNewEntryField, BsPARAMTYPE::BOOL); $argsSNewEntryFieldPosition = BsCore::sanitizeArrayEntry($args, 'newentryfieldposition', $bNewEntryFieldPosition, BsPARAMTYPE::STRING); $argsSImageRenderMode = BsCore::sanitizeArrayEntry($args, 'imagerendermode', $sImageRenderMode, BsPARAMTYPE::STRING); $argsSImageFloatDirection = BsCore::sanitizeArrayEntry($args, 'imagefloatdirection', $sImageFloatDirection, BsPARAMTYPE::STRING); $argsIMaxEntryCharacters = BsCore::sanitizeArrayEntry($args, 'maxchars', $iMaxEntryCharacters, BsPARAMTYPE::INT); $argsSSortBy = BsCore::sanitizeArrayEntry($args, 'sort', $sSortBy, BsPARAMTYPE::STRING); $argsBShowInfo = BsCore::sanitizeArrayEntry($args, 'showinfo', $bShowInfo, BsPARAMTYPE::BOOL); $argsBMoreInNewWindow = BsCore::sanitizeArrayEntry($args, 'moreinnewwindow', $bMoreInNewWindow, BsPARAMTYPE::BOOL); $argsBShowPermalink = BsCore::sanitizeArrayEntry($args, 'showpermalink', $bShowPermalink, BsPARAMTYPE::BOOL); $argsModeNamespace = BsCore::sanitizeArrayEntry($args, 'mode', null, BsPARAMTYPE::STRING); if ($argsModeNamespace === 'ns' && is_object($oTitle)) { $argsINamespace = $oTitle->getNamespace(); } // validate tag attributes $validateIShowLimit = BsValidator::isValid('ArgCount', $argsIShowLimit, array('fullResponse' => true)); if ($validateIShowLimit->getErrorCode()) { $oErrorListView->addItem(new ViewTagError($validateIShowLimit->getI18N())); } if ($argsSCategory) { $validateSCategory = BsValidator::isValid('Category', $argsSCategory, array('fullResponse' => true)); if ($validateSCategory->getErrorCode()) { $oErrorListView->addItem(new ViewTagError($validateSCategory->getI18N())); } } $oValidationResult = BsValidator::isValid('SetItem', $argsSImageRenderMode, array('fullResponse' => true, 'setname' => 'imagerendermode', 'set' => array('full', 'thumb', 'none'))); if ($oValidationResult->getErrorCode()) { $oErrorListView->addItem(new ViewTagError($oValidationResult->getI18N())); } $oValidationResult = BsValidator::isValid('SetItem', $argsSImageFloatDirection, array('fullResponse' => true, 'setname' => 'imagefloatdirection', 'set' => array('left', 'right', 'none'))); if ($oValidationResult->getErrorCode()) { $oErrorListView->addItem(new ViewTagError($oValidationResult->getI18N())); } $oValidationResult = BsValidator::isValid('SetItem', $argsSSortBy, array('fullResponse' => true, 'setname' => 'sort', 'set' => array('title', 'creation'))); if ($oValidationResult->getErrorCode()) { $oErrorListView->addItem(new ViewTagError($oValidationResult->getI18N())); } // if there are errors, abort with a message if ($oErrorListView->hasEntries()) { return $oErrorListView->execute(); } if (BsConfig::get('MW::Blog::ShowTagFormWhenNotLoggedIn') != true) { $oPermissionTest = Title::newFromText('PermissionTest', $argsINamespace); if (!$oPermissionTest->userCan('edit')) { $argsBNewEntryField = false; } } // get array of article ids from Blog/subpages $oBlogTitle = Title::makeTitleSafe($oTitle->getNamespace(), 'Blog'); $aSubpages = $oBlogTitle->getSubpages(); $iLimit = 0; // for later use $aArticleIds = array(); foreach ($aSubpages as $oSubpage) { $aArticleIds[] = $oSubpage->getArticleID(); $iLimit++; // for later use } if (count($aArticleIds) < 1) { $aArticleIds = 0; } $aTables = array('page'); $aFields = array('entry_page_id' => 'page_id'); $aConditions = array(); $aOptions = array(); $aJoins = array(); $dbr = wfGetDB(DB_SLAVE); // get blog entries if ($argsSSortBy == 'title') { $aOptions['ORDER BY'] = 'page_title ASC'; } else { //Creation: Also fetch possible custom timestamps from page_props table $aOptions['ORDER BY'] = 'entry_timestamp DESC'; $aOptions['GROUP BY'] = 'page_id'; global $wgDBtype; switch ($wgDBtype) { case 'oracle': $aFields['entry_timestamp'] = "NVL( pp_value, rev_timestamp )"; $aConditions[] = "NVL( pp_value, rev_timestamp ) < " . wfTimestampNow(); break; case 'mssql': $aFields['entry_timestamp'] = "ISNULL( pp_value, rev_timestamp )"; $aConditions[] = "ISNULL( pp_value, rev_timestamp ) < " . wfTimestampNow(); break; case 'postgres': $aFields['entry_timestamp'] = "NULLIF( pp_value, rev_timestamp )"; $aConditions[] = "NULLIF( pp_value, rev_timestamp ) < " . wfTimestampNow(); break; default: //MySQL, SQLite //use pp_value if exists $aFields['entry_timestamp'] = "IFNULL( pp_value, rev_timestamp )"; //also do not list future entries $aConditions[] = "IFNULL( pp_value, rev_timestamp ) < " . wfTimestampNow(); } $aTables[] = 'revision'; $aTables[] = 'page_props'; $aConditions[] = 'rev_page = page_id'; $aJoins['page_props'] = array('LEFT JOIN', "pp_page = rev_page AND pp_propname = 'blogtime'"); } if ($argsSCategory) { $aTables[] = 'categorylinks'; $aConditions['cl_to'] = $argsSCategory; $aConditions[] = 'cl_from = page_id'; } else { if ($argsModeNamespace === 'ns') { $aConditions['page_id'] = $aArticleIds; } $aConditions['page_namespace'] = $argsINamespace; } $res = $dbr->select($aTables, $aFields, $aConditions, __METHOD__, $aOptions, $aJoins); $iNumberOfEntries = $dbr->numRows($res); $iLimit = $iNumberOfEntries; //All // Sole importance is the existence of param 'showall' $paramBShowAll = $this->getRequest()->getFuzzyBool('showall', false); if ($paramBShowAll == false) { $iLimit = $argsIShowLimit; } // abort if there are no entries if ($iNumberOfEntries < 1) { $oBlogView = new ViewBlog(); $oBlogView->setOption('shownewentryfield', $argsBNewEntryField); $oBlogView->setOption('newentryfieldposition', $argsSNewEntryFieldPosition); $oBlogView->setOption('namespace', BsNamespaceHelper::getNamespaceName($argsINamespace)); if ($argsSCategory) { $oBlogView->setOption('blogcat', $argsSCategory); } // actually create blog output $sOut = $oBlogView->execute(); $sOut .= wfMessage('bs-blog-no-entries')->plain(); return $sOut; } $oBlogView = new ViewBlog(); // prepare views per blog item $iLoop = 0; foreach ($res as $row) { // prepare data for view class $oEntryTitle = Title::newFromID($row->entry_page_id); if (!$oEntryTitle->userCan('read')) { $iNumberOfEntries--; continue; } $bMore = false; $aContent = preg_split('#<(bs:blog:)?more */>#', BsPageContentProvider::getInstance()->getContentFromTitle($oEntryTitle)); if (sizeof($aContent) > 1) { $bMore = true; } $aContent = trim($aContent[0]); // Prevent recursive rendering of blog tag $aContent = preg_replace('/<(bs:)blog[^>]*?>/', '', $aContent); // Thumbnail images $sNamespaceRegEx = implode('|', BsNamespaceHelper::getNamespaceNamesAndAliases(NS_IMAGE)); switch ($argsSImageRenderMode) { case 'none': $aContent = preg_replace('/(\\[\\[(' . $sNamespaceRegEx . '):[^\\|\\]]*)(\\|)?(.*?)(\\]\\])/', '', $aContent); break; case 'full': // do nothing break; case 'thumb': default: $aContent = preg_replace('/(\\[\\[(' . $sNamespaceRegEx . '):[^\\|\\]]*)(\\|)?(.*?)(\\]\\])/', "\$1|thumb|{$argsSImageFloatDirection}\$3\$4|150px\$5", $aContent); break; } if (strlen($aContent) > $argsIMaxEntryCharacters) { $bMore = true; } $aContent = BsStringHelper::shorten($aContent, array('max-length' => $argsIMaxEntryCharacters, 'ignore-word-borders' => false, 'position' => 'end')); $resComment = $dbr->selectRow('revision', 'COUNT( rev_id ) AS cnt', array('rev_page' => $oEntryTitle->getTalkPage()->getArticleID())); $iCount = $resComment->cnt; // set data for view class $oBlogItemView = new ViewBlogItem(); // use magic set $oBlogItemView->setOption('showInfo', $argsBShowInfo); $oBlogItemView->setOption('showLimit', $argsIShowLimit); $oBlogItemView->setOption('showTrackback', $bShowTrackback); $oBlogItemView->setOption('showPermalink', $argsBShowPermalink); $oBlogItemView->setOption('moreInNewWindow', $argsBMoreInNewWindow); $oBlogItemView->setOption('showAll', $bShowAll); $oBlogItemView->setOption('moreAtEndOfEntry', $bMoreAtEndOfEntry); $oBlogItemView->setOption('more', $bMore); //TODO: magic_call? if ($argsModeNamespace === 'ns') { $sTitle = substr($oEntryTitle->getText(), 5); } else { $sTitle = $oEntryTitle->getText(); } $aTalkParams = array(); if (!$oEntryTitle->getTalkPage()->exists()) { $aTalkParams = array('action' => 'edit'); } $oRevision = Revision::newFromTitle($oEntryTitle); $oBlogItemView->setTitle($sTitle); $oBlogItemView->setRevId($oRevision->getId()); $oBlogItemView->setURL($oEntryTitle->getLocalURL()); $oBlogItemView->setTalkURL($oEntryTitle->getTalkPage()->getLocalURL($aTalkParams)); $oBlogItemView->setTalkCount($iCount); $oBlogItemView->setTrackbackUrl($oEntryTitle->getLocalURL()); if ($bShowInfo) { $oFirstRevision = $oEntryTitle->getFirstRevision(); $sTimestamp = $oFirstRevision->getTimestamp(); $sLocalDateTimeString = BsFormatConverter::timestampToAgeString(wfTimestamp(TS_UNIX, $sTimestamp)); $oBlogItemView->setEntryDate($sLocalDateTimeString); $iUserId = $oFirstRevision->getUser(); if ($iUserId != 0) { $oAuthorUser = User::newFromId($iUserId); $oBlogItemView->setAuthorPage($oAuthorUser->getUserPage()->getPrefixedText()); $oBlogItemView->setAuthorName($this->mCore->getUserDisplayName($oAuthorUser)); } else { $oBlogItemView->setAuthorName($oFirstRevision->getUserText()); } } $oBlogItemView->setContent($aContent); $oBlogView->addItem($oBlogItemView); $iLoop++; if ($iLoop >= $iLimit) { break; } } $dbr->freeResult($res); // prepare complete blog output if ($bShowAll && !$paramBShowAll && $iNumberOfEntries > $argsIShowLimit) { $oBlogView->setOption('showall', true); } $oBlogView->setOption('shownewentryfield', $argsBNewEntryField); $oBlogView->setOption('newentryfieldposition', $argsSNewEntryFieldPosition); $oBlogView->setOption('namespace', BsNamespaceHelper::getNamespaceName($argsINamespace, false)); $oBlogView->setOption('blogcat', $argsSCategory); if ($argsModeNamespace === 'ns') { $oBlogView->setOption('parentpage', 'Blog/'); } // actually create blog output $sOut = $oBlogView->execute(); //Use cache only in NS_BLOG - there is curently no functionality to //figure out in what type of blog tag a entry is showen and why //(coditions). Possible blog by categories or subpages... //Needs rework. if (in_array($oTitle->getNamespace(), array(NS_BLOG, NS_BLOG_TALK))) { $aKey = array($sKey); $sTagsKey = BsCacheHelper::getCacheKey('BlueSpice', 'Blog', 'Tags'); $aTagsData = BsCacheHelper::get($sTagsKey); if ($aTagsData !== false) { if (!in_array($sKey, $aTagsData)) { $aTagsData = array_merge($aTagsData, $aKey); } } else { $aTagsData = $aKey; } BsCacheHelper::set($sTagsKey, $aTagsData, 60 * 1440); // one day BsCacheHelper::set($sKey, $sOut, 60 * 1440); // one day } return $sOut; }
public static function ajaxGetActivatedNamespacesForCombobox() { if (BsCore::checkAccessAdmission('edit') === false) { return true; } $aNamespaces = array(); $aNamespaces[] = array('namespace_id' => -99, 'namespace_text' => BsNamespaceHelper::getNamespaceName(-99, true)); $aActivatedNamespaces = BsConfig::get('MW::ResponsibleEditors::ActivatedNamespaces'); foreach ($aActivatedNamespaces as $iNamespaceId) { $aNamespaces[] = array('namespace_id' => $iNamespaceId, 'namespace_text' => BsNamespaceHelper::getNamespaceName($iNamespaceId, true)); } return '{ namespaces: ' . json_encode($aNamespaces) . ' }'; }
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)); }
/** * Calculate the data for the NamespaceManager store and put them to the ajax output. * @param string $output the ajax output (have to be JSON) */ public static function getData() { if (BsCore::checkAccessAdmission('wikiadmin') === false) { return true; } global $wgContLang; $aResults = array(); $aNamespaces = $wgContLang->getNamespaces(); foreach ($aNamespaces as $iNs => $sNamespace) { if ($sNamespace === '') { $sNamespace = BsNamespaceHelper::getNamespaceName($iNs); } if ($iNs === -2 || $iNs === -1) { continue; } $aResults[] = array('id' => $iNs, 'name' => $sNamespace); } wfRunHooks('NamespaceManager::getNamespaceData', array(&$aResults)); $oRequest = RequestContext::getMain()->getRequest(); $iLimit = $oRequest->getInt('limit', 25); $iStart = $oRequest->getInt('start', 0); $sSort = $oRequest->getVal('sort', '[{"property":"id","direction":"DESC"}]'); self::$aSortConditions = FormatJson::decode($sSort); self::$aSortConditions = self::$aSortConditions[0]; usort($aResults, 'NamespaceManager::namespaceManagerRemoteSort'); $aLimitedResults = array(); $iResultCount = count($aResults); $iMax = $iStart + $iLimit > $iResultCount ? $iResultCount : $iStart + $iLimit; for ($i = $iStart; $i < $iMax; $i++) { $aLimitedResults[] = $aResults[$i]; } $aReturn = array('totalCount' => $iResultCount, 'success' => true, 'results' => $aLimitedResults); return FormatJson::encode($aReturn); }
/** * Generates result entires for autocomplete * @param array $aDocuments Array of Apache_solr_Documents * @param string $sSearchString Given search string * @param integer $iNum Number of Results * @param mixed $vNsSearch false or integer namespace id * @param array $aResults Reference to results array */ private static function generateAutocompleteResults($aDocuments, $sSearchString, $iNum, $vNsSearch, &$aResults) { $sLabelText = ''; foreach ($aDocuments as $oDoc) { if ($oDoc->namespace != '999') { $iNamespace = $oDoc->namespace == '1000' ? NS_SPECIAL : $oDoc->namespace; $oTitle = Title::makeTitle($iNamespace, $oDoc->title); } else { continue; } if (!$oTitle->userCan('read')) { continue; } $sLabelText = self::highlightTitle($oTitle, $sSearchString); // Adding namespace if ($oTitle->getNamespace() !== NS_MAIN) { $sLabelText = BsNamespaceHelper::getNamespaceName($oTitle->getNamespace()) . ':' . $sLabelText; } //If namespace is in searchstring remove it from display if ($vNsSearch !== false) { $sNamespace = BsNamespaceHelper::getNamespaceName($vNsSearch); $sLabelText = str_replace($sNamespace . ':', '', $sLabelText); } $oItem = new stdClass(); $oItem->id = ++$iNum; $oItem->value = $oTitle->getPrefixedText(); $oItem->label = $sLabelText; $oItem->type = $oDoc->type; $oItem->link = $oTitle->getFullURL(); $oItem->attr = ''; $aResults[] = $oItem; } }
/** * Returns a json encoded list of available templates * @return bool allow other hooked methods to be executed. Always true. */ public static function getTemplates() { if (BsCore::checkAccessAdmission('wikiadmin') === false) { return true; } global $wgRequest; $iLimit = $wgRequest->getInt('limit', 25); $iStart = $wgRequest->getInt('start', 0); $sSort = $wgRequest->getVal('sort', 'user_name'); $sDirection = $wgRequest->getVal('dir', 'ASC'); switch ($sSort) { case 'label': $sSortField = 'pt_label'; break; case 'desc': $sSortField = 'pt_desc'; break; case 'targetns': $sSortField = 'pt_target_namespace'; break; case 'template': $sSortField = 'pt_template_title'; break; default: $sSortField = 'pt_label'; break; } $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('bs_pagetemplate'), array('pt_id', 'pt_label', 'pt_desc', 'pt_target_namespace', 'pt_template_title', 'pt_template_namespace'), array(), __METHOD__, array('ORDER BY' => $sSortField . ' ' . $sDirection, 'LIMIT' => $iLimit, 'OFFSET' => $iStart)); $aData = array(); $aData['templates'] = array(); while ($row = $res->fetchObject()) { $tmp = array(); $tmp['id'] = $row->pt_id; $tmp['label'] = $row->pt_label; $tmp['desc'] = $row->pt_desc; $tmp['targetns'] = BsNamespaceHelper::getNamespaceName($row->pt_target_namespace, true); $tmp['targetnsid'] = $row->pt_target_namespace; $oTitle = Title::newFromText($row->pt_template_title, $row->pt_template_namespace); $tmp['template'] = '<a href="' . $oTitle->getFullURL() . '" target="_blank" ' . ($oTitle->exists() ? '' : 'class="new"') . '>' . $oTitle->getFullText() . '</a>'; $tmp['templatename'] = $row->pt_template_title; $tmp['templatens'] = $row->pt_template_namespace; $aData['templates'][] = $tmp; } $rescount = $dbr->selectRow('bs_pagetemplate', 'COUNT( pt_id ) AS cnt', array()); $aData['totalCount'] = $rescount->cnt; return json_encode($aData); }