public function execute() { # get the current user. $context = $this->createContext(); $user = $context->getUser(); $params = $this->extractRequestParams(); $action = $params['action']; // check the blacklist, the same way tbhooks does it. // // Some places check createpage, while others check create. // As it stands, upload does createpage, but normalize both // to the same action, to stop future similar bugs. if ($action === 'createpage' || $action === 'createtalk') { $action = 'create'; } $title = Title::newFromText($params['title']); if (!$title) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $blacklisted = TitleBlacklist::singleton()->userCannot($title, $user, $action); if ($blacklisted instanceof TitleBlacklistEntry) { // this title is blacklisted. $result = array(htmlspecialchars($blacklisted->getRaw()), htmlspecialchars($params['title'])); $res = $this->getResult(); $res->addValue('titleblacklist', 'result', 'blacklisted'); // this is hardcoded to 'edit' in Titleblacklist.hooks.php, duplicating that. $message = $blacklisted->getErrorMessage('edit'); $res->addValue('titleblacklist', 'reason', wfMessage($message, $result)->text()); $res->addValue('titleblacklist', 'message', $message); $res->addValue('titleblacklist', 'line', htmlspecialchars($blacklisted->getRaw())); } else { // not blacklisted $this->getResult()->addValue('titleblacklist', 'result', 'ok'); } }
public function execute() { $params = $this->extractRequestParams(); $action = $params['action']; $override = true; if (isset($params['nooverride'])) { $override = false; } // createtalk and createpage are useless as they're treated exactly like create if ($action === 'createpage' || $action === 'createtalk') { $action = 'create'; } $title = Title::newFromText($params['title']); if (!$title) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } $blacklisted = TitleBlacklist::singleton()->userCannot($title, $this->getUser(), $action, $override); if ($blacklisted instanceof TitleBlacklistEntry) { // this title is blacklisted. $result = array(htmlspecialchars($blacklisted->getRaw()), htmlspecialchars($params['title'])); $res = $this->getResult(); $res->addValue('titleblacklist', 'result', 'blacklisted'); // there aren't any messages for create(talk|page), using edit for those instead $message = $blacklisted->getErrorMessage($action !== 'create' ? $action : 'edit'); $res->addValue('titleblacklist', 'reason', wfMessage($message, $result)->text()); $res->addValue('titleblacklist', 'message', $message); $res->addValue('titleblacklist', 'line', htmlspecialchars($blacklisted->getRaw())); } else { // not blacklisted $this->getResult()->addValue('titleblacklist', 'result', 'ok'); } }
public function test($action = null, $title = null) { $this->checkType('mw.ext.TitleBlacklist.test', 1, $action, 'string'); $this->checkTypeOptional('mw.ext.TitleBlacklist.test', 2, $title, 'string', ''); $this->incrementExpensiveFunctionCount(); if ($title == '') { $title = $this->getParser()->mTitle->getPrefixedText(); } $entry = TitleBlacklist::singleton()->isBlacklisted($title, $action); if ($entry) { return array(array('params' => $entry->getParams(), 'regex' => $entry->getRegex(), 'raw' => $entry->getRaw(), 'version' => $entry->getFormatVersion(), 'message' => $entry->getErrorMessage($action), 'custommessage' => $entry->getCustomMessage())); } return array(null); }
/** * ArticleSaveComplete hook * * @param Article $article */ public static function clearBlacklist(&$article, &$user, $text, $summary, $isminor, $iswatch, $section) { $title = $article->getTitle(); if ($title->getNamespace() == NS_MEDIAWIKI && $title->getDBkey() == 'Titleblacklist') { TitleBlacklist::singleton()->invalidate(); } return true; }