/** * Creates a Widget object * @return ViewWidget */ public function getWidget() { $sAction = $this->getRequest()->getVal('action', 'view'); if (!in_array($sAction, array('view', 'historysubmit'))) { return null; } $oCurrentTitle = $this->getTitle(); if ($oCurrentTitle->quickUserCan('universalexport-export') === false) { return null; } $aCurrentQueryParams = $this->getRequest()->getValues(); $sTitle = isset($aCurrentQueryParams['title']) ? $aCurrentQueryParams['title'] : ""; $sSpecialPageParameter = BsCore::sanitize($sTitle, '', BsPARAMTYPE::STRING); $oSpecialPage = SpecialPage::getTitleFor('UniversalExport', $sSpecialPageParameter); if (isset($aCurrentQueryParams['title'])) { unset($aCurrentQueryParams['title']); } $aModules = array(); wfRunHooks('BSUniversalExportGetWidget', array($this, &$aModules, $oSpecialPage, $oCurrentTitle, $aCurrentQueryParams)); if (empty($aModules)) { return null; } $sList = ''; foreach ($aModules as $oModuleView) { if ($oModuleView instanceof ViewBaseElement) { $sList .= $oModuleView->execute(); } else { wfDebugLog('BS::UniversalExport', 'getWidget: Invalid view.'); } } $oWidgetView = new ViewWidget(); $oWidgetView->setId('universalexport')->setTitle(wfMessage('bs-universalexport-widget-title')->plain())->setBody($sList)->setTooltip(wfMessage('bs-universalexport-widget-tooltip')->plain()); return $oWidgetView; }
/** * Builds the ContentAction Array fort the current page * @return Array The ContentAction Array */ private function buildContentAction() { $aCurrentQueryParams = $this->getRequest()->getValues(); if (isset($aCurrentQueryParams['title'])) { $sTitle = $aCurrentQueryParams['title']; } else { $sTitle = ''; } $sSpecialPageParameter = BsCore::sanitize($sTitle, '', BsPARAMTYPE::STRING); $oSpecialPage = SpecialPage::getTitleFor('UniversalExport', $sSpecialPageParameter); if (isset($aCurrentQueryParams['title'])) { unset($aCurrentQueryParams['title']); } $aCurrentQueryParams['ue[module]'] = 'pdf'; return array('id' => 'bs-ta-uemodulepdf', 'href' => $oSpecialPage->getLinkUrl($aCurrentQueryParams), 'title' => wfMessage('bs-uemodulepdf-widgetlink-single-no-attachments-title')->text(), 'text' => wfMessage('bs-uemodulepdf-widgetlink-single-no-attachments-text')->text(), 'class' => 'icon-file-pdf'); }
/** * Renders bs:whoisonline:popup output. * @param Parser $oParser MediaWiki parser object. * @param string $sLinkTitle Label of the link that is the anchor of the flyout * @return array Rendered HTML and flags. Used by magic word function hook as well as by onUsersLinkTag. */ public function onUsersLink($oParser, $sLinkTitle = '') { $oParser->disableCache(); wfProfileIn('BS::' . __METHOD__); $sLinkTitle = BsCore::sanitize($sLinkTitle, '', BsPARAMTYPE::STRING); if (empty($sLinkTitle)) { $sLinkTitle = wfMessage('bs-whoisonline-widget-title')->plain(); } $oWhoIsOnlineTagView = new ViewWhoIsOnlineTag(); $oWhoIsOnlineTagView->setOption('title', $sLinkTitle); $oWhoIsOnlineTagView->setPortlet($this->getPortlet()); $sOut = $oWhoIsOnlineTagView->execute(); wfProfileOut('BS::' . __METHOD__); return $oParser->insertStripItem($sOut, $oParser->mStripState); }
public static function getResponsibleEditorsPortletData($iCount, $iUserId) { $iCount = BsCore::sanitize($iCount, 10, BsPARAMTYPE::INT); $oDbr = wfGetDB(DB_SLAVE); $res = $oDbr->select('bs_responsible_editors', 're_page_id', array('re_user_id' => $iUserId)); $aResults = array(); if ($oDbr->numRows($res) > 0) { $aResults[] = Html::openElement('ul'); foreach ($res as $row) { $oTitle = Title::newFromID($row->re_page_id); if ($oTitle->exists()) { $aResults[] = Html::openElement('li') . BsLinkProvider::makeLink($oTitle, $oTitle->getPrefixedText()) . Html::closeElement('li'); } } $aResults[] = Html::closeElement('ul'); } else { $aResults[] = wfMessage('bs-responsibleeditors-no-own-responsibilities')->plain(); } return implode('', $aResults); }
/** * Creates a new review from JSON imput. * @param string $sJSON JSON input the review should be created from. * @param array $aErrors List of errors in case anything goes wrong. * @return mixed BsReviewProcess or false if anything goes wrong. */ static function newFromJSON($sJSON = '', &$aErrors) { $aErrors = array(); $oJsonReview = json_decode($sJSON); $oReviewProcess = new BsReviewProcess(); // rv_pid is stored in table hw_review as a smallint(5) unsigned $oReviewProcess->pid = BsCore::sanitize($oJsonReview->pid, -1, BsPARAMTYPE::NUMERIC); $oReviewProcess->editable = !!$oJsonReview->editable; $oReviewProcess->sequential = !!$oJsonReview->sequential; $oReviewProcess->abortable = !!$oJsonReview->abortable; if (!$oJsonReview->startdate) { $aErrors[] = 'startdate-missing'; } $oReviewProcess->startdate = date("YmdHis", strtotime(BsCore::sanitize($oJsonReview->startdate, '', BsPARAMTYPE::STRING))); if (!$oJsonReview->enddate) { $aErrors[] = 'enddate-missing'; } $oReviewProcess->enddate = date("YmdHis", strtotime(BsCore::sanitize($oJsonReview->enddate, '', BsPARAMTYPE::STRING))); if ($oReviewProcess->startdate > $oReviewProcess->enddate) { $aErrors[] = 'startdate-after-enddate'; } $paramRvSteps = $oJsonReview->steps; if (count($paramRvSteps) <= 0) { $aErrors[] = 'no-reviewers'; } // TODO an MRG: wir dieser block noch benötigt oder ist er inzwischen deprecated ?? // Fixed mit isset if (isset($oJsonReview->tmpl_save) && $oJsonReview->tmpl_save) { $oReviewProcess->tmpl_save = true; $oReviewProcess->tmpl_name = addslashes($oJsonReview->tmpl_name); $oReviewProcess->tmpl_choice = $oJsonReview->tmpl_choice; } foreach ($paramRvSteps as $oStep) { if ($oStep->status == '' || $oStep->status == 'unknown') { $oStep->status = '-1'; } if ($oStep->status == 'yes') { $oStep->status = '1'; } if ($oStep->status == 'no') { $oStep->status = '0'; } $sComment = BsCore::sanitize($oStep->comment, '', BsPARAMTYPE::STRING); if (strlen($sComment) > 255) { $aErrors[] = 'comment-too-long'; } if (!$oStep->userid || !is_numeric($oStep->userid)) { //TODO: make sure you get a valid id //PW: wont work with realname! $oStep->userid = User::idFromName($oStep->name); if (!$oStep->userid) { $aErrors[] = 'user-not-found'; } } else { $oTmpUser = User::newFromId($oStep->userid); if (!$oTmpUser) { $aErrors[] = 'user-not-found'; } } $oReviewProcess->steps[] = BsReviewProcessStep::newFromData(BsCore::sanitize($oStep->userid, '', BsPARAMTYPE::INT), $sComment, BsCore::sanitize($oStep->status, '-1', BsPARAMTYPE::STRING)); } if (is_array($aErrors) && count($aErrors) > 0) { return false; } else { return $oReviewProcess; } }
/** * Generates list of most edited pages * @return String list of pages or empty */ public function getActivePortlet($iCount, $iTime) { $oDbr = wfGetDB(DB_SLAVE); $iCount = BsCore::sanitize($iCount, 10, BsPARAMTYPE::INT); $iTime = BsCore::sanitize($iTime, 0, BsPARAMTYPE::INT); $aConditions = array(); if ($iTime !== 0) { $this->getTimestampForQuery($aConditions, $iTime); } $res = $oDbr->select('revision', array('COUNT(rev_user) as edit_count', 'rev_user'), $aConditions, __METHOD__, array('GROUP BY' => 'rev_user', 'ORDER BY' => 'edit_count DESC')); $aList = array(); if ($oDbr->numRows($res) > 0) { $aList[] = '<ol>'; $i = 1; foreach ($res as $row) { if ($i > $iCount) { break; } $oUser = User::newFromId($row->rev_user); if ($oUser->isIP($oUser->getName())) { continue; } $oTitle = Title::makeTitle(NS_USER, $oUser->getName()); $sLink = BsLinkProvider::makeLink($oTitle); $aList[] = '<li>' . $sLink . ' (' . $row->edit_count . ')</li>'; $i++; } $aList[] = '</ol>'; } $oDbr->freeResult($res); return implode("\n", $aList); }
/** * 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())); } }
/** * Writes a given search request to database log. * @param string $term Search term * @param int $iNumFound Number of hits * @param string $scope What was the scope of the search? * @param string $files Were files searched as well? * @return bool always false. */ public function logSearch($term, $iNumFound, $scope, $files) { if (!BsConfig::get('MW::ExtendedSearch::Logging')) { return false; } $oDbw = wfGetDB(DB_MASTER); $term = BsCore::sanitize($term, '', BsPARAMTYPE::SQL_STRING); $user = BsConfig::get('MW::ExtendedSearch::LogUsers') ? RequestContext::getMain()->getUser()->getId() : ''; $effectiveScope = $files ? $scope . '-files' : $scope; $data = array('stats_term' => $term, 'stats_ts' => wfTimestamp(TS_MW), 'stats_user' => $user, 'stats_hits' => $iNumFound, 'stats_scope' => $effectiveScope); $oDbw->insert('bs_searchstats', $data); return true; }
/** * Generates list of most searched terms * @return string list of most searched terms */ public static function getRecentSearchTerms($iCount, $iTime) { $oDbr = wfGetDB(DB_SLAVE); $iCount = BsCore::sanitize($iCount, 0, BsPARAMTYPE::INT); $iTime = BsCore::sanitize($iTime, 0, BsPARAMTYPE::INT); $aConditions = array(); if ($iTime !== 0) { $iTimeInSec = $iTime * 24 * 60 * 60; $iTimeStamp = wfTimestamp(TS_UNIX) - $iTimeInSec; $iTimeStamp = wfTimestamp(TS_MW, $iTimeStamp); $aConditions = array('stats_ts >= ' . $iTimeStamp); } $res = $oDbr->select('bs_searchstats', 'stats_term', $aConditions); $aResults = array(); if ($oDbr->numRows($res) > 0) { $aTerms = array(); foreach ($res as $row) { $sTerm = str_replace(array('*', '\\'), '', $row->stats_term); if (substr_count($sTerm, '~') > 0) { $aTermParts = explode('~', $sTerm); $sFuzzy = array_pop($aTermParts); $sTerm = implode('', $aTermParts); } $sTerm = mb_strtolower($sTerm); if (array_key_exists($sTerm, $aTerms)) { $aTerms[$sTerm] += 1; } else { $aTerms[$sTerm] = 1; } } arsort($aTerms); $aResults[] = '<ol>'; $i = 1; foreach ($aTerms as $key => $value) { if ($i > $iCount) { break; } $aResults[] = '<li>' . htmlspecialchars($key, ENT_QUOTES, 'UTF-8') . ' (' . $value . ')</li>'; $i++; } $aResults[] = '</ol>'; } return implode("\n", $aResults); }