2011-07-21 22:08:44 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TitleBlacklist extension API
|
|
|
|
*
|
|
|
|
* Copyright © 2011 Wikimedia Foundation and Ian Baker <ian@wikimedia.org>
|
|
|
|
* Based on code by Victor Vasiliev, Bryan Tong Minh, Roan Kattouw, and Alex Z.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query module check a title against the blacklist
|
|
|
|
*
|
|
|
|
* @ingroup API
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
2011-08-22 20:27:57 +00:00
|
|
|
class ApiQueryTitleBlacklist extends ApiBase {
|
2011-07-21 22:08:44 +00:00
|
|
|
|
|
|
|
public function __construct( $query, $moduleName ) {
|
|
|
|
parent::__construct( $query, $moduleName, 'tb' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
$action = $params['action'];
|
2016-11-15 13:53:25 +00:00
|
|
|
$override = !$params['nooverride'];
|
2011-07-21 22:08:44 +00:00
|
|
|
|
2012-10-17 21:52:05 +00:00
|
|
|
// createtalk and createpage are useless as they're treated exactly like create
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( $action === 'createpage' || $action === 'createtalk' ) {
|
2011-07-21 22:08:44 +00:00
|
|
|
$action = 'create';
|
|
|
|
}
|
|
|
|
|
2011-08-22 20:56:19 +00:00
|
|
|
$title = Title::newFromText( $params['title'] );
|
|
|
|
if ( !$title ) {
|
2016-11-03 19:16:57 +00:00
|
|
|
if ( is_callable( [ $this, 'dieWithError' ] ) ) {
|
2017-06-02 15:43:58 +00:00
|
|
|
$this->dieWithError(
|
2017-06-06 16:18:36 +00:00
|
|
|
[ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ]
|
2017-06-02 15:43:58 +00:00
|
|
|
);
|
2016-11-03 19:16:57 +00:00
|
|
|
} else {
|
2017-06-06 16:18:36 +00:00
|
|
|
$this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] );
|
2016-11-03 19:16:57 +00:00
|
|
|
}
|
2011-08-22 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
2017-06-02 15:43:58 +00:00
|
|
|
$blacklisted = TitleBlacklist::singleton()->userCannot(
|
|
|
|
$title, $this->getUser(), $action, $override
|
|
|
|
);
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( $blacklisted instanceof TitleBlacklistEntry ) {
|
2011-07-21 22:08:44 +00:00
|
|
|
// this title is blacklisted.
|
2017-06-06 16:18:36 +00:00
|
|
|
$result = [
|
2011-07-21 22:08:44 +00:00
|
|
|
htmlspecialchars( $blacklisted->getRaw() ),
|
|
|
|
htmlspecialchars( $params['title'] ),
|
2017-06-06 16:18:36 +00:00
|
|
|
];
|
2011-08-22 20:27:57 +00:00
|
|
|
|
2011-08-22 20:29:29 +00:00
|
|
|
$res = $this->getResult();
|
|
|
|
$res->addValue( 'titleblacklist', 'result', 'blacklisted' );
|
2012-10-17 21:52:05 +00:00
|
|
|
// there aren't any messages for create(talk|page), using edit for those instead
|
|
|
|
$message = $blacklisted->getErrorMessage( $action !== 'create' ? $action : 'edit' );
|
2011-08-22 20:29:29 +00:00
|
|
|
$res->addValue( 'titleblacklist', 'reason', wfMessage( $message, $result )->text() );
|
|
|
|
$res->addValue( 'titleblacklist', 'message', $message );
|
|
|
|
$res->addValue( 'titleblacklist', 'line', htmlspecialchars( $blacklisted->getRaw() ) );
|
2011-07-21 22:08:44 +00:00
|
|
|
} else {
|
|
|
|
// not blacklisted
|
|
|
|
$this->getResult()->addValue( 'titleblacklist', 'result', 'ok' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2017-06-06 16:18:36 +00:00
|
|
|
return [
|
|
|
|
'title' => [
|
2011-07-21 22:08:44 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2017-06-06 16:18:36 +00:00
|
|
|
],
|
|
|
|
'action' => [
|
2011-07-21 22:08:44 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'edit',
|
|
|
|
ApiBase::PARAM_ISMULTI => false,
|
2017-06-06 16:18:36 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2012-10-17 21:52:05 +00:00
|
|
|
// createtalk and createpage are useless as they're treated exactly like create
|
|
|
|
'create', 'edit', 'upload', 'createtalk', 'createpage', 'move', 'new-account'
|
2017-06-06 16:18:36 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'nooverride' => [
|
2016-11-15 13:53:25 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
2017-06-06 16:18:36 +00:00
|
|
|
]
|
|
|
|
];
|
2011-07-21 22:08:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 19:17:19 +00:00
|
|
|
/**
|
|
|
|
* @see ApiBase::getExamplesMessages()
|
|
|
|
*/
|
|
|
|
protected function getExamplesMessages() {
|
2017-06-06 16:18:36 +00:00
|
|
|
return [
|
2014-10-29 19:17:19 +00:00
|
|
|
'action=titleblacklist&tbtitle=Foo'
|
|
|
|
=> 'apihelp-titleblacklist-example-1',
|
|
|
|
'action=titleblacklist&tbtitle=Bar&tbaction=edit'
|
|
|
|
=> 'apihelp-titleblacklist-example-2',
|
2017-06-06 16:18:36 +00:00
|
|
|
];
|
2011-07-21 22:08:44 +00:00
|
|
|
}
|
|
|
|
}
|