[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * TitleBlacklist extension API 4 * 5 * Copyright © 2011 Wikimedia Foundation and Ian Baker <[email protected]> 6 * Based on code by Victor Vasiliev, Bryan Tong Minh, Roan Kattouw, and Alex Z. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along 19 * with this program; if not, write to the Free Software Foundation, Inc., 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * http://www.gnu.org/copyleft/gpl.html 22 */ 23 24 /** 25 * Query module check a title against the blacklist 26 * 27 * @ingroup API 28 * @ingroup Extensions 29 */ 30 class ApiQueryTitleBlacklist extends ApiBase { 31 32 public function __construct( $query, $moduleName ) { 33 parent::__construct( $query, $moduleName, 'tb' ); 34 } 35 36 public function execute() { 37 $params = $this->extractRequestParams(); 38 $action = $params['action']; 39 $override = true; 40 if( isset( $params['nooverride'] ) ) { 41 $override = false; 42 } 43 44 // createtalk and createpage are useless as they're treated exactly like create 45 if ( $action === 'createpage' || $action === 'createtalk' ) { 46 $action = 'create'; 47 } 48 49 $title = Title::newFromText( $params['title'] ); 50 if ( !$title ) { 51 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); 52 } 53 54 $blacklisted = TitleBlacklist::singleton()->userCannot( $title, $this->getUser(), $action, $override ); 55 if ( $blacklisted instanceof TitleBlacklistEntry ) { 56 // this title is blacklisted. 57 $result = array( 58 htmlspecialchars( $blacklisted->getRaw() ), 59 htmlspecialchars( $params['title'] ), 60 ); 61 62 $res = $this->getResult(); 63 $res->addValue( 'titleblacklist', 'result', 'blacklisted' ); 64 // there aren't any messages for create(talk|page), using edit for those instead 65 $message = $blacklisted->getErrorMessage( $action !== 'create' ? $action : 'edit' ); 66 $res->addValue( 'titleblacklist', 'reason', wfMessage( $message, $result )->text() ); 67 $res->addValue( 'titleblacklist', 'message', $message ); 68 $res->addValue( 'titleblacklist', 'line', htmlspecialchars( $blacklisted->getRaw() ) ); 69 } else { 70 // not blacklisted 71 $this->getResult()->addValue( 'titleblacklist', 'result', 'ok' ); 72 } 73 } 74 75 public function getAllowedParams() { 76 return array( 77 'title' => array( 78 ApiBase::PARAM_REQUIRED => true, 79 ), 80 'action' => array( 81 ApiBase::PARAM_DFLT => 'edit', 82 ApiBase::PARAM_ISMULTI => false, 83 ApiBase::PARAM_TYPE => array( 84 // createtalk and createpage are useless as they're treated exactly like create 85 'create', 'edit', 'upload', 'createtalk', 'createpage', 'move', 'new-account' 86 ), 87 ), 88 'nooverride' => array( 89 ) 90 ); 91 } 92 93 public function getParamDescription() { 94 return array( 95 'title' => 'The string to validate against the blacklist', 96 'nooverride' => 'Don\'t try to override the titleblacklist', 97 'action' => 'The thing you\'re trying to do', 98 ); 99 } 100 101 public function getDescription() { 102 return 'Validate an article title, filename, or username against the TitleBlacklist.'; 103 } 104 105 public function getExamples() { 106 return array( 107 'api.php?action=titleblacklist&tbtitle=Foo', 108 'api.php?action=titleblacklist&tbtitle=Bar&tbaction=edit', 109 ); 110 } 111 112 public function getVersion() { 113 return __CLASS__ . ': $Id$'; 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |