/** * This method actually generates the output * @return string HTML output */ public function execute($aParam = false) { $sSearch = str_replace(BsCore::getForbiddenCharsInArticleTitle(), '', $this->getOption('search')); $oTitle = Title::newFromText($sSearch); $sSearchUrlencoded = urlencode($sSearch); $sSearchHtmlEntities = htmlentities($sSearch, ENT_QUOTES, 'UTF-8'); $sCreatesuggest = '<ul>'; wfRunHooks('BSExtendedSearchAdditionalActions', array(&$sCreatesuggest, &$sSearchUrlencoded, &$sSearchHtmlEntities, &$oTitle)); $sCreatesuggest .= '</ul>'; $sCreatesuggest .= '<br />'; return $sCreatesuggest; }
/** * For a given SearchInput (by the user) the Existence of an article with exactly this title is evaluated. * @param String $sParamSearchInput * @return boolean */ public static function titleExists($sParamSearchInput, &$aOptions) { $sParamSearchInput = trim($sParamSearchInput); if (empty($sParamSearchInput)) { return false; } /* Normalize $sParamSearchInput first: * - get rid of leading or trailing whitespace * - get rid of characters that are not permitted in the title (by mediawiki) * - get rid of more than one space at a time */ $thisTitleMightExist = trim(str_replace(BsCore::getForbiddenCharsInArticleTitle(), ' ', $sParamSearchInput)); do { $beforeStrReplace = $thisTitleMightExist; $thisTitleMightExist = str_replace(' ', ' ', $thisTitleMightExist); } while ($beforeStrReplace != $thisTitleMightExist); $oTitle = Title::newFromText($thisTitleMightExist); if ($oTitle !== null && $oTitle->exists()) { $aOptions['existingTitleObject'] = $oTitle; return true; } // If first attempt to create a Title-Object without success... // ... remove leading and trailing '"'-characters (solves Ticket#2010062310000113) $oTitle = Title::newFromText(trim($thisTitleMightExist, '"')); if ($oTitle !== null && $oTitle->exists()) { $aOptions['existingTitleObject'] = $oTitle; return true; } return false; }
/** * Handles the suggestion ajax request. * A new title is entered into the list. Depending on configuration, already existing articles are deleted. * @return bool true on correct processing. JSON answer is in $sOut parameter. */ public static function ajaxAddWantedArticle($sSuggestedArticleWikiLink) { if (BsCore::checkAccessAdmission('wantedarticle-suggest') === false) { return json_encode(array('success' => false, 'message' => wfMessage('bs-permissionerror')->plain())); } if (empty($sSuggestedArticleWikiLink)) { $sErrorMsg = wfMessage('bs-wantedarticle-ajax-error-no-parameter')->plain(); return json_encode(array('success' => false, 'message' => $sErrorMsg)); // TODO RBV (01.07.11 09:07): XHRRequest object. } //Check suggestion for invalid characters (clientside validation is not enough) $aFoundChars = array(); foreach (BsCore::getForbiddenCharsInArticleTitle() as $sChar) { if (strpos($sSuggestedArticleWikiLink, $sChar)) { $aFoundChars[] = '"' . $sChar . '"'; } } if (count($aFoundChars) > 0) { $sChars = implode(', ', $aFoundChars); $sErrorMsg = wfMessage('bs-wantedarticle-title-invalid-chars', count($aFoundChars), $sChars)->plain(); return json_encode(array('success' => false, 'message' => $sErrorMsg)); } //Check if suggested page already exists $oSuggestedTitle = Title::newFromText($sSuggestedArticleWikiLink); $sSuggestedTitle = $oSuggestedTitle->getPrefixedText(); if ($oSuggestedTitle->exists()) { $sErrorMsg = wfMessage('bs-wantedarticle-ajax-error-suggested-page-already-exists', $sSuggestedTitle)->plain(); return json_encode(array('success' => false, 'message' => $sErrorMsg)); } $oWantedArticle = BsExtensionManager::getExtension('WantedArticle'); $oDataSourceArticle = $oWantedArticle->getDataSourceTemplateArticle(); $aWishList = $oWantedArticle->getTitleListFromTitle($oDataSourceArticle->getTitle()); $bDeleteExisting = BsConfig::get('MW::WantedArticle::DeleteExisting'); foreach ($aWishList as $key => $aWish) { if ($oSuggestedTitle->equals($aWish['title'])) { $sErrorMsg = wfMessage('bs-wantedarticle-ajax-error-suggested-page-already-on-list', $oSuggestedTitle->getPrefixedText())->plain(); return json_encode(array('success' => true, 'message' => $sErrorMsg)); } if ($bDeleteExisting && $aWish['title']->exists() === true) { unset($aWishList[$key]); continue; } } array_unshift($aWishList, array('title' => $oSuggestedTitle, 'signature' => '--~~~~')); // Write new content $oEditStatus = $oWantedArticle->saveTitleListToTitle($aWishList, $oDataSourceArticle->getTitle(), wfMessage('bs-wantedarticle-edit-comment-suggestion-added', $sSuggestedTitle)->plain()); if ($oEditStatus->isGood()) { return json_encode(array('success' => true, 'message' => wfMessage('bs-wantedarticle-success-suggestion-entered', $sSuggestedTitle)->plain())); } else { $sErrorMsg = $oWantedArticle->mCore->parseWikiText($oEditStatus->getWikiText(), $this->getTitle()); return json_encode(array('success' => false, 'message' => $sErrorMsg)); } }