/** * Concatenate categories on EditPage POST * * @param EditPage $editPage * @param WebRequest $request * * @return Boolean because it's a hook */ public static function onEditPageImportFormData($editPage, $request) { $app = F::app(); if ($request->wasPosted()) { $categories = $editPage->safeUnicodeInput($request, 'categories'); $categories = CategoryHelper::changeFormat($categories, 'json', 'array'); // Concatenate categories to article wikitext (if there are any). if (!empty($categories)) { if (!empty($app->wg->EnableAnswers)) { // don't add categories if the page is a redirect $magicWords = $app->wg->ContLang->getMagicWords(); $redirects = $magicWords['redirect']; // first element doesn't interest us array_shift($redirects); // check for localized versions of #REDIRECT foreach ($redirects as $alias) { if (stripos($editPage->textbox1, $alias) === 0) { return true; } } } // Extract categories from the article, merge them with those passed in, weed out // duplicates and finally append them back to the article (BugId:99348). $data = CategoryHelper::extractCategoriesFromWikitext($editPage->textbox1, true); $categories = CategoryHelper::getUniqueCategories($data['categories'], $categories); $categories = CategoryHelper::changeFormat($categories, 'array', 'wikitext'); // Remove trailing whitespace (BugId:11238) $editPage->textbox1 = $data['wikitext'] . rtrim($categories); } } return true; }
/** * Concatenate categories on EditPage POST * * @param EditPage $editPage * @param WebRequest $request * * @author Maciej Błaszkowski <marooned at wikia-inc.com> * @author Lucas Garczewski <*****@*****.**> */ function CategorySelectImportFormData($editPage, $request) { global $wgCategorySelectCategoriesInWikitext, $wgContLang, $wgEnableAnswers; if ($request->wasPosted()) { $sourceType = $request->getVal('wpCategorySelectSourceType'); if ($sourceType == 'wiki') { $categories = "\n" . trim($editPage->safeUnicodeInput($request, 'csWikitext')); } else { //json $categories = $editPage->safeUnicodeInput($request, 'wpCategorySelectWikitext'); $categories = CategorySelectChangeFormat($categories, 'json', 'wiki'); if (trim($categories) == '') { $categories = ''; } } if ($editPage->preview || $editPage->diff) { $data = CategorySelect::SelectCategoryAPIgetData($editPage->textbox1 . $categories); $editPage->textbox1 = $data['wikitext']; $categories = CategorySelectChangeFormat($data['categories'], 'array', 'wiki'); } else { //saving article if (!empty($wgEnableAnswers)) { // don't add categories if the page is a redirect $magicWords = $wgContLang->getMagicWords(); $redirects = $magicWords['redirect']; array_shift($redirects); // first element doesn't interest us // check for localized versions of #REDIRECT foreach ($redirects as $alias) { if (stripos($editPage->textbox1, $alias) === 0) { return true; } } } // rtrim needed because of BugId:11238 $editPage->textbox1 .= rtrim($categories); } $wgCategorySelectCategoriesInWikitext = $categories; } return true; }