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'];
|
2012-10-17 21:52:05 +00:00
|
|
|
$override = true;
|
|
|
|
if( isset( $params['nooverride'] ) ) {
|
|
|
|
$override = false;
|
|
|
|
}
|
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 ) {
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
|
|
|
}
|
|
|
|
|
2012-10-17 21:52:05 +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.
|
|
|
|
$result = array(
|
|
|
|
htmlspecialchars( $blacklisted->getRaw() ),
|
|
|
|
htmlspecialchars( $params['title'] ),
|
|
|
|
);
|
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() {
|
|
|
|
return array(
|
|
|
|
'title' => array(
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
|
|
|
),
|
|
|
|
'action' => array(
|
|
|
|
ApiBase::PARAM_DFLT => 'edit',
|
|
|
|
ApiBase::PARAM_ISMULTI => false,
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
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'
|
2011-07-21 22:08:44 +00:00
|
|
|
),
|
2012-10-17 21:52:05 +00:00
|
|
|
),
|
|
|
|
'nooverride' => array(
|
2011-07-21 22:08:44 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParamDescription() {
|
|
|
|
return array(
|
|
|
|
'title' => 'The string to validate against the blacklist',
|
2012-10-17 21:52:05 +00:00
|
|
|
'nooverride' => 'Don\'t try to override the titleblacklist',
|
2011-07-21 22:08:44 +00:00
|
|
|
'action' => 'The thing you\'re trying to do',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
return 'Validate an article title, filename, or username against the TitleBlacklist.';
|
|
|
|
}
|
|
|
|
|
2011-08-26 23:50:06 +00:00
|
|
|
public function getExamples() {
|
2011-07-21 22:08:44 +00:00
|
|
|
return array(
|
|
|
|
'api.php?action=titleblacklist&tbtitle=Foo',
|
2012-10-17 21:52:05 +00:00
|
|
|
'api.php?action=titleblacklist&tbtitle=Bar&tbaction=edit',
|
2011-07-21 22:08:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersion() {
|
2011-08-22 20:21:08 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2011-07-21 22:08:44 +00:00
|
|
|
}
|
|
|
|
}
|