2020-11-22 20:00:48 +00:00
< ? php
2021-05-30 18:33:21 +00:00
2020-11-22 20:00:48 +00:00
namespace DPL ;
2021-05-30 18:33:21 +00:00
use MediaWiki\MediaWikiServices ;
2021-10-01 22:52:30 +00:00
use MWException ;
use PermissionsError ;
use RequestContext ;
use Title ;
2021-05-30 18:33:21 +00:00
2020-11-22 20:00:48 +00:00
class Parameters extends ParametersData {
/**
* Set parameter options .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $parameterOptions = [];
/**
* Selection Criteria Found
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:00:48 +00:00
*/
private $selectionCriteriaFound = false ;
/**
* Open References Conflict
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:00:48 +00:00
*/
private $openReferencesConflict = false ;
/**
* Parameters that have already been processed .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $parametersProcessed = [];
public function __construct () {
parent :: __construct ();
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$this -> setDefaults ();
}
/**
* Handle simple parameter functions .
*
2021-10-01 22:52:30 +00:00
* @ param string $parameter
* @ param mixed $arguments
2021-02-23 00:06:29 +00:00
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function __call ( $parameter , $arguments ) {
$parameterData = $this -> getData ( $parameter );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( $parameterData === false ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-23 00:06:29 +00:00
// Check permission to use this parameter.
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'permission' , $parameterData ) ) {
2021-10-01 22:52:30 +00:00
$user = RequestContext :: getMain () -> getUser ();
if ( ! $user -> isAllowed ( $parameterData [ 'permission' ] ) ) {
throw new PermissionsError ( $parameterData [ 'permission' ] );
2020-11-22 20:00:48 +00:00
}
}
2021-10-01 22:52:30 +00:00
// Subvert to the real function if it exists. This keeps code elsewhere clean from needed to check if it exists first.
$function = '_' . $parameter ;
2020-11-22 20:00:48 +00:00
$this -> parametersProcessed [ $parameter ] = true ;
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( method_exists ( $this , $function ) ) {
return call_user_func_array ( [ $this , $function ], $arguments );
2020-11-22 20:00:48 +00:00
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
$option = $arguments [ 0 ];
2021-02-22 23:48:01 +00:00
$parameter = strtolower ( $parameter );
2020-11-22 20:00:48 +00:00
2021-02-23 00:06:29 +00:00
// Assume by default that these simple parameter options should not failed, but if they do we will set $success to false below.
2020-11-22 20:00:48 +00:00
$success = true ;
2021-02-22 23:48:01 +00:00
if ( $parameterData !== false ) {
2021-02-23 00:06:29 +00:00
// If a parameter specifies options then enforce them.
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'values' , $parameterData ) && is_array ( $parameterData [ 'values' ] ) === true && ! in_array ( strtolower ( $option ), $parameterData [ 'values' ] ) ) {
2020-11-22 20:00:48 +00:00
$success = false ;
} else {
2021-02-22 23:48:01 +00:00
if ( ( array_key_exists ( 'preserve_case' , $parameterData ) && ! $parameterData [ 'preserve_case' ] ) && ( array_key_exists ( 'page_name_list' , $parameterData ) && $parameterData [ 'page_name_list' ] !== true ) ) {
$option = strtolower ( $option );
2020-11-22 20:00:48 +00:00
}
}
2021-02-23 00:06:29 +00:00
// Strip <html> tag.
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'strip_html' , $parameterData ) && $parameterData [ 'strip_html' ] === true ) {
$option = $this -> stripHtmlTags ( $option );
2020-11-22 20:00:48 +00:00
}
2021-02-23 00:06:29 +00:00
// Simple integer intval().
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'integer' , $parameterData ) && $parameterData [ 'integer' ] === true ) {
if ( ! is_numeric ( $option ) ) {
if ( $parameterData [ 'default' ] !== null ) {
$option = intval ( $parameterData [ 'default' ] );
2020-11-22 20:00:48 +00:00
} else {
$success = false ;
}
} else {
2021-02-22 23:48:01 +00:00
$option = intval ( $option );
2020-11-22 20:00:48 +00:00
}
}
2021-02-23 00:06:29 +00:00
// Booleans
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'boolean' , $parameterData ) && $parameterData [ 'boolean' ] === true ) {
$option = $this -> filterBoolean ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $option === null ) {
2020-11-22 20:00:48 +00:00
$success = false ;
}
}
2021-02-23 00:06:29 +00:00
// Timestamps
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'timestamp' , $parameterData ) && $parameterData [ 'timestamp' ] === true ) {
$option = strtolower ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
switch ( $option ) {
2020-11-22 20:00:48 +00:00
case 'today' :
case 'last hour' :
case 'last day' :
case 'last week' :
case 'last month' :
case 'last year' :
break ;
default :
2021-02-22 23:48:01 +00:00
$option = str_pad ( preg_replace ( '#[^0-9]#' , '' , $option ), 14 , '0' );
$option = wfTimestamp ( TS_MW , $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( $option === false ) {
2020-11-22 20:00:48 +00:00
$success = false ;
}
break ;
}
}
2021-02-23 00:06:29 +00:00
// List of Pages
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'page_name_list' , $parameterData ) && $parameterData [ 'page_name_list' ] === true ) {
$pageGroups = $this -> getParameter ( $parameter );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! is_array ( $pageGroups ) ) {
2020-11-22 20:00:48 +00:00
$pageGroups = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$pages = $this -> getPageNameList ( $option , ( bool ) $parameterData [ 'page_name_must_exist' ] );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $pages === false ) {
2020-11-22 20:00:48 +00:00
$success = false ;
} else {
$pageGroups [] = $pages ;
$option = $pageGroups ;
}
}
2021-02-23 00:06:29 +00:00
// Regex Pattern Matching
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'pattern' , $parameterData ) ) {
if ( preg_match ( $parameterData [ 'pattern' ], $option , $matches ) ) {
2021-10-01 22:52:30 +00:00
// Nuke the total pattern match off the beginning of the array.
2021-02-22 23:48:01 +00:00
array_shift ( $matches );
2020-11-22 20:00:48 +00:00
$option = $matches ;
} else {
$success = false ;
}
}
2021-02-23 00:06:29 +00:00
// Database Key Formatting
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'db_format' , $parameterData ) && $parameterData [ 'db_format' ] === true ) {
$option = str_replace ( ' ' , '_' , $option );
2020-11-22 20:00:48 +00:00
}
2021-02-23 00:06:29 +00:00
// If none of the above checks marked this as a failure then set it.
2021-10-01 22:52:30 +00:00
if ( $success ) {
2021-02-22 23:48:01 +00:00
$this -> setParameter ( $parameter , $option );
2020-11-22 20:00:48 +00:00
2021-10-01 22:52:30 +00:00
// Set that criteria was found for a selection.
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'set_criteria_found' , $parameterData ) && $parameterData [ 'set_criteria_found' ] === true ) {
$this -> setSelectionCriteriaFound ( true );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
// Set open references conflict possibility.
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 'open_ref_conflict' , $parameterData ) && $parameterData [ 'open_ref_conflict' ] === true ) {
$this -> setOpenReferencesConflict ( true );
2020-11-22 20:00:48 +00:00
}
}
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
return $success ;
}
/**
* Sort cleaned parameter arrays by priority .
2021-10-01 22:52:30 +00:00
* Users can not be told to put the parameters into a specific order each time . Some parameters are dependent on each other coming in a certain order due to some procedural legacy issues .
2020-11-22 20:00:48 +00:00
*
2021-02-23 00:06:29 +00:00
* @ param array $parameters
* @ return array
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function sortByPriority ( $parameters ) {
if ( ! is_array ( $parameters ) ) {
2021-10-01 22:52:30 +00:00
throw new MWException ( __METHOD__ . ': A non-array was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
// 'category' to get category headings first for ordermethod.
// 'include'/'includepage' to make sure section labels are ready for 'table'.
2020-11-22 20:00:48 +00:00
$priority = [
2021-10-01 22:52:30 +00:00
'distinct' => 1 ,
'openreferences' => 2 ,
'ignorecase' => 3 ,
'category' => 4 ,
'title' => 5 ,
'goal' => 6 ,
'ordercollation' => 7 ,
'ordermethod' => 8 ,
'includepage' => 9 ,
'include' => 10
2020-11-22 20:00:48 +00:00
];
$_first = [];
2021-02-22 23:48:01 +00:00
foreach ( $priority as $parameter => $order ) {
if ( isset ( $parameters [ $parameter ] ) ) {
2020-11-22 20:00:48 +00:00
$_first [ $parameter ] = $parameters [ $parameter ];
2021-02-22 23:48:01 +00:00
unset ( $parameters [ $parameter ] );
2020-11-22 20:00:48 +00:00
}
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
$parameters = $_first + $parameters ;
return $parameters ;
}
/**
* Set Selection Criteria Found
*
2021-10-01 22:52:30 +00:00
* @ param bool $found
2021-02-23 00:06:29 +00:00
* @ return void
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
private function setSelectionCriteriaFound ( $found = true ) {
if ( ! is_bool ( $found ) ) {
throw new MWException ( __METHOD__ . ': A non-boolean was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
$this -> selectionCriteriaFound = $found ;
}
/**
* Get Selection Criteria Found
*
2021-02-23 00:06:29 +00:00
* @ return bool
2020-11-22 20:00:48 +00:00
*/
public function isSelectionCriteriaFound () {
return $this -> selectionCriteriaFound ;
}
/**
* Set Open References Conflict - See 'openreferences' parameter .
*
2021-02-23 00:06:29 +00:00
* @ param bool $conflict
* @ return void
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
private function setOpenReferencesConflict ( $conflict = true ) {
if ( ! is_bool ( $conflict ) ) {
throw new MWException ( __METHOD__ . ': A non-boolean was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
$this -> openReferencesConflict = $conflict ;
}
/**
* Get Open References Conflict - See 'openreferences' parameter .
*
2021-02-23 00:06:29 +00:00
* @ return bool
2020-11-22 20:00:48 +00:00
*/
public function isOpenReferencesConflict () {
return $this -> openReferencesConflict ;
}
/**
* Set default parameters based on ParametersData .
*/
private function setDefaults () {
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'defaulttemplatesuffix' , '.default' );
2020-11-22 20:00:48 +00:00
$parameters = $this -> getParametersForRichness ();
2021-02-22 23:48:01 +00:00
foreach ( $parameters as $parameter ) {
if ( $this -> getData ( $parameter )[ 'default' ] !== null && ! ( $this -> getData ( $parameter )[ 'default' ] === false && $this -> getData ( $parameter )[ 'boolean' ] === true ) ) {
if ( $parameter == 'debug' ) {
2021-10-01 22:52:30 +00:00
DynamicPageListHooks :: setDebugLevel ( $this -> getData ( $parameter )[ 'default' ] );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( $parameter , $this -> getData ( $parameter )[ 'default' ] );
2020-11-22 20:00:48 +00:00
}
}
}
/**
* Set a parameter ' s option .
*
2021-02-23 00:06:29 +00:00
* @ param string $parameter
* @ param mixed $option
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function setParameter ( $parameter , $option ) {
2020-11-22 20:00:48 +00:00
$this -> parameterOptions [ $parameter ] = $option ;
}
/**
* Get a parameter ' s option .
*
2021-02-23 00:06:29 +00:00
* @ param string $parameter
* @ return mixed Option for specified parameter .
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function getParameter ( $parameter ) {
return array_key_exists ( $parameter , $this -> parameterOptions ) ? $this -> parameterOptions [ $parameter ] : null ;
2020-11-22 20:00:48 +00:00
}
/**
* Get all parameters .
*
2021-10-01 22:52:30 +00:00
* @ return array
2020-11-22 20:00:48 +00:00
*/
public function getAllParameters () {
2021-02-22 23:48:01 +00:00
return self :: sortByPriority ( $this -> parameterOptions );
2020-11-22 20:00:48 +00:00
}
/**
* Filter a standard boolean like value into an actual boolean .
*
2021-10-01 22:52:30 +00:00
* @ param int | string | bool $boolean
2021-02-23 00:06:29 +00:00
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function filterBoolean ( $boolean ) {
return filter_var ( $boolean , FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE );
2020-11-22 20:00:48 +00:00
}
/**
* Strip < html > tags .
*
2021-10-01 22:52:30 +00:00
* @ param string $text
* @ return string
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
private function stripHtmlTags ( $text ) {
$text = preg_replace ( " #<.*?html.*?>#is " , " " , $text );
2020-11-22 20:00:48 +00:00
return $text ;
}
/**
* Get a list of valid page names .
*
2021-10-01 22:52:30 +00:00
* @ param string $text
* @ param bool $mustExist
* @ return array | bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
private function getPageNameList ( $text , $mustExist = true ) {
2020-11-22 20:00:48 +00:00
$list = [];
2021-02-22 23:48:01 +00:00
$pages = explode ( '|' , trim ( $text ) );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $pages as $page ) {
$page = trim ( $page );
2021-10-01 22:52:30 +00:00
$page = rtrim ( $page , '\\' );
2021-02-22 23:48:01 +00:00
if ( empty ( $page ) ) {
2020-11-22 20:00:48 +00:00
continue ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $mustExist === true ) {
2021-10-01 22:52:30 +00:00
$title = Title :: newFromText ( $page );
2021-02-22 23:48:01 +00:00
if ( ! $title ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$list [] = $title ;
} else {
$list [] = $page ;
}
}
return $list ;
}
/**
* Check if a regular expression is valid .
*
2021-10-01 22:52:30 +00:00
* @ param array | string $regexes
* @ param bool $forDb
2021-02-23 00:06:29 +00:00
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
private function isRegexValid ( $regexes , $forDb = false ) {
if ( ! is_array ( $regexes ) ) {
$regexes = [ $regexes ];
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
foreach ( $regexes as $regex ) {
if ( empty ( trim ( $regex ) ) ) {
2020-11-22 20:00:48 +00:00
continue ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $forDb ) {
$regex = '#' . str_replace ( '#' , '\#' , $regex ) . '#' ;
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
// Purposely silencing the errors here since we are testing if preg_match
// would throw an error due to a bad regex from user input.
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
2021-02-22 23:48:01 +00:00
if ( @ preg_match ( $regex , null ) === false ) {
2021-10-01 22:52:30 +00:00
// @phan-suppress-previous-line PhanParamSuspiciousOrder, PhanTypeMismatchArgumentInternalProbablyReal
2020-11-22 20:00:48 +00:00
return false ;
}
}
return true ;
}
/**
* Clean and test 'category' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _category ( $option ) {
$option = trim ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( empty ( $option ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-23 00:06:29 +00:00
2020-11-22 20:00:48 +00:00
// Init array of categories to include
$categories = [];
2021-10-01 22:52:30 +00:00
$heading = false ;
2020-11-22 20:00:48 +00:00
$notHeading = false ;
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( substr ( $option , 0 , 1 ) == '+' ) { // categories are headings
2020-11-22 20:00:48 +00:00
$heading = true ;
2021-02-22 23:48:01 +00:00
$option = ltrim ( $option , '+' );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( substr ( $option , 0 , 1 ) == '-' ) { // categories are NOT headings
2020-11-22 20:00:48 +00:00
$notHeading = true ;
2021-02-22 23:48:01 +00:00
$option = ltrim ( $option , '-' );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
// We expand html entities because they contain an '& 'which would be interpreted as an AND condition
2021-02-22 23:48:01 +00:00
$option = html_entity_decode ( $option , ENT_QUOTES );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( strpos ( $option , '|' ) !== false ) {
$parameters = explode ( '|' , $option );
2020-11-22 20:00:48 +00:00
$operator = 'OR' ;
} else {
2021-02-22 23:48:01 +00:00
$parameters = explode ( '&' , $option );
2020-11-22 20:00:48 +00:00
$operator = 'AND' ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $parameters as $parameter ) {
$parameter = trim ( $parameter );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $parameter === '_none_' || $parameter === '' ) {
$this -> setParameter ( 'includeuncat' , true );
2020-11-22 20:00:48 +00:00
$categories [] = '' ;
2021-02-22 23:48:01 +00:00
} elseif ( ! empty ( $parameter ) ) {
if ( strpos ( $parameter , '*' ) === 0 && strlen ( $parameter ) >= 2 ) {
if ( strpos ( $parameter , '*' , 1 ) === 1 ) {
$parameter = substr ( $parameter , 2 );
$subCategories = Query :: getSubcategories ( $parameter , 2 );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$parameter = substr ( $parameter , 1 );
$subCategories = Query :: getSubcategories ( $parameter , 1 );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$subCategories [] = $parameter ;
2021-02-22 23:48:01 +00:00
foreach ( $subCategories as $subCategory ) {
2021-10-01 22:52:30 +00:00
$title = Title :: newFromText ( $subCategory );
2021-02-22 23:48:01 +00:00
if ( $title !== null ) {
2021-10-01 22:52:30 +00:00
// The * helper is just like listing "Category1|SubCategory1". This gets hard coded here for this purpose.
2020-11-22 20:00:48 +00:00
$categories [ 'OR' ][] = $title -> getDbKey ();
}
}
} else {
2021-10-01 22:52:30 +00:00
$title = Title :: newFromText ( $parameter );
2021-02-22 23:48:01 +00:00
if ( $title !== null ) {
2020-11-22 20:00:48 +00:00
$categories [ $operator ][] = $title -> getDbKey ();
}
}
}
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! empty ( $categories ) ) {
$data = $this -> getParameter ( 'category' );
2021-10-01 22:52:30 +00:00
// Do a bunch of data integrity checks to avoid E_NOTICE.
2021-02-22 23:48:01 +00:00
if ( ! is_array ( $data ) ) {
2020-11-22 20:00:48 +00:00
$data = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! array_key_exists ( '=' , $data ) || ! is_array ( $data [ '=' ] ) ) {
2020-11-22 20:00:48 +00:00
$data [ '=' ] = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $categories as $_operator => $_categories ) {
if ( ! array_key_exists ( $_operator , $data [ '=' ] ) || ! is_array ( $data [ '=' ][ $_operator ] ) ) {
2020-11-22 20:00:48 +00:00
$data [ '=' ][ $_operator ] = [];
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$data [ '=' ][ $_operator ][] = $_categories ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'category' , $data );
if ( $heading ) {
$this -> setParameter ( 'catheadings' , array_unique ( array_merge ( ( is_array ( $this -> getParameter ( 'catheadings' ) ) ? $this -> getParameter ( 'catheadings' ) : [] ), $categories ) ) );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $notHeading ) {
$this -> setParameter ( 'catnotheadings' , array_unique ( array_merge ( ( is_array ( $this -> getParameter ( 'catnotheadings' ) ) ? $this -> getParameter ( 'catnotheadings' ) : [] ), $categories ) ) );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return false ;
}
/**
* Clean and test 'categoryregexp' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _categoryregexp ( $option ) {
if ( ! $this -> isRegexValid ( $option , true ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'category' );
2021-10-01 22:52:30 +00:00
// REGEXP input only supports AND operator.
$data [ 'REGEXP' ][ 'AND' ][] = [ $option ];
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'category' , $data );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'categorymatch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _categorymatch ( $option ) {
if ( strpos ( $option , '|' ) !== false ) {
$newMatches = explode ( '|' , $option );
2020-11-22 20:00:48 +00:00
$operator = 'OR' ;
} else {
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '&' , $option );
2020-11-22 20:00:48 +00:00
$operator = 'AND' ;
}
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'category' );
if ( isset ( $data [ 'LIKE' ] ) && ! is_array ( $data [ 'LIKE' ][ $operator ] ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'LIKE' ][ $operator ] = [];
}
$data [ 'LIKE' ][ $operator ][] = $newMatches ;
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'category' , $data );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'notcategory' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _notcategory ( $option ) {
2021-10-01 22:52:30 +00:00
$title = Title :: newFromText ( $option );
2021-02-22 23:48:01 +00:00
if ( $title !== null ) {
$data = $this -> getParameter ( 'notcategory' );
2020-11-22 20:00:48 +00:00
$data [ '=' ][] = $title -> getDbKey ();
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'notcategory' , $data );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return false ;
}
/**
* Clean and test 'notcategoryregexp' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _notcategoryregexp ( $option ) {
if ( ! $this -> isRegexValid ( $option , true ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'notcategory' );
2020-11-22 20:00:48 +00:00
$data [ 'regexp' ][] = $option ;
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'notcategory' , $data );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'notcategorymatch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _notcategorymatch ( $option ) {
$data = $this -> getParameter ( 'notcategory' );
2021-10-01 22:52:30 +00:00
if ( ! is_array ( $data [ 'like' ] ? ? false ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'like' ] = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '|' , $option );
$data [ 'like' ] = array_merge ( $data [ 'like' ], $newMatches );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'notcategory' , $data );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'count' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string | int $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _count ( $option ) {
if ( ! Config :: getSetting ( 'allowUnlimitedResults' ) && $option <= Config :: getSetting ( 'maxResultCount' ) && $option > 0 ) {
$this -> setParameter ( 'count' , intval ( $option ) );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return false ;
}
/**
* Clean and test 'namespace' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _namespace ( $option ) {
2021-05-30 18:33:21 +00:00
$contLang = MediaWikiServices :: getInstance () -> getContentLanguage ();
2021-02-22 23:48:01 +00:00
$extraParams = explode ( '|' , $option );
foreach ( $extraParams as $parameter ) {
$parameter = trim ( $parameter );
2021-05-30 18:33:21 +00:00
$namespaceId = $contLang -> getNsIndex ( $parameter );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $namespaceId === false || ( is_array ( Config :: getSetting ( 'allowedNamespaces' ) ) && ! in_array ( $parameter , Config :: getSetting ( 'allowedNamespaces' ) ) ) ) {
2021-10-01 22:52:30 +00:00
// Let the user know this namespace is not allowed or does not exist.
2020-11-22 20:00:48 +00:00
return false ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'namespace' );
2020-11-22 20:00:48 +00:00
$data [] = $namespaceId ;
2021-02-22 23:48:01 +00:00
$data = array_unique ( $data );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'namespace' , $data );
$this -> setSelectionCriteriaFound ( true );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'notnamespace' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _notnamespace ( $option ) {
2021-05-30 18:33:21 +00:00
$contLang = MediaWikiServices :: getInstance () -> getContentLanguage ();
2021-02-22 23:48:01 +00:00
$extraParams = explode ( '|' , $option );
foreach ( $extraParams as $parameter ) {
$parameter = trim ( $parameter );
2021-05-30 18:33:21 +00:00
$namespaceId = $contLang -> getNsIndex ( $parameter );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $namespaceId === false ) {
2021-10-01 22:52:30 +00:00
// Let the user know this namespace is not allowed or does not exist.
2020-11-22 20:00:48 +00:00
return false ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'notnamespace' );
2020-11-22 20:00:48 +00:00
$data [] = $namespaceId ;
2021-02-22 23:48:01 +00:00
$data = array_unique ( $data );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'notnamespace' , $data );
$this -> setSelectionCriteriaFound ( true );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'openreferences' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _openreferences ( $option ) {
$option = $this -> filterBoolean ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $option === null ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-10-01 22:52:30 +00:00
// Force 'ordermethod' back to none.
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'ordermethod' , [ 'none' ] );
$this -> setParameter ( 'openreferences' , $option );
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'ordermethod' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _ordermethod ( $option ) {
$methods = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
$success = true ;
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $methods as $method ) {
if ( ! in_array ( $method , $this -> getData ( 'ordermethod' )[ 'values' ] ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'ordermethod' , $methods );
if ( $methods [ 0 ] !== 'none' ) {
$this -> setOpenReferencesConflict ( true );
2020-11-22 20:00:48 +00:00
}
return true ;
}
/**
* Clean and test 'mode' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _mode ( $option ) {
if ( in_array ( $option , $this -> getData ( 'mode' )[ 'values' ] ) ) {
2021-10-01 22:52:30 +00:00
// 'none' mode is implemented as a specific submode of 'inline' with <br/> as inline text
2021-02-22 23:48:01 +00:00
if ( $option == 'none' ) {
$this -> setParameter ( 'mode' , 'inline' );
$this -> setParameter ( 'inlinetext' , '<br/>' );
} elseif ( $option == 'userformat' ) {
2020-11-22 20:00:48 +00:00
// userformat resets inline text to empty string
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'inlinetext' , '' );
$this -> setParameter ( 'mode' , $option );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'mode' , $option );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
} else {
return false ;
}
}
/**
* Clean and test 'distinct' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _distinct ( $option ) {
$boolean = $this -> filterBoolean ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $option == 'strict' ) {
$this -> setParameter ( 'distinctresultset' , 'strict' );
} elseif ( $boolean !== null ) {
$this -> setParameter ( 'distinctresultset' , $boolean );
2020-11-22 20:00:48 +00:00
} else {
return false ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'ordercollation' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _ordercollation ( $option ) {
if ( $option == 'bridge' ) {
$this -> setParameter ( 'ordersuitsymbols' , true );
} elseif ( ! empty ( $option ) ) {
$this -> setParameter ( 'ordercollation' , $option );
2020-11-22 20:00:48 +00:00
} else {
return false ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Short cut to _format ();
*
2021-02-23 00:06:29 +00:00
* @ return mixed
2020-11-22 20:00:48 +00:00
*/
public function _listseparators () {
2021-02-22 23:48:01 +00:00
return call_user_func_array ( [ $this , '_format' ], func_get_args () );
2020-11-22 20:00:48 +00:00
}
/**
* Clean and test 'format' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _format ( $option ) {
2021-10-01 22:52:30 +00:00
// Parsing of wikitext will happen at the end of the output phase. Replace '\n' in the input by linefeed because wiki syntax depends on linefeeds.
2021-02-22 23:48:01 +00:00
$option = $this -> stripHtmlTags ( $option );
$option = Parse :: replaceNewLines ( $option );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'listseparators' , explode ( ',' , $option , 4 ) );
2021-10-01 22:52:30 +00:00
// Set the 'mode' parameter to userformat automatically.
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'mode' , 'userformat' );
$this -> setParameter ( 'inlinetext' , '' );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'title' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _title ( $option ) {
2021-10-01 22:52:30 +00:00
$title = Title :: newFromText ( $option );
2021-02-22 23:48:01 +00:00
if ( $title ) {
$data = $this -> getParameter ( 'title' );
$data [ '=' ][] = str_replace ( ' ' , '_' , $title -> getText () );
$this -> setParameter ( 'title' , $data );
$data = $this -> getParameter ( 'namespace' );
2020-11-22 20:00:48 +00:00
$data [] = $title -> getNamespace ();
2021-02-22 23:48:01 +00:00
$data = array_unique ( $data );
2020-11-22 20:00:48 +00:00
2021-10-01 22:52:30 +00:00
$this -> setParameter ( 'namespace' , $data );
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'mode' , 'userformat' );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setSelectionCriteriaFound ( true );
$this -> setOpenReferencesConflict ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return false ;
}
/**
* Clean and test 'titleregexp' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _titleregexp ( $option ) {
$data = $this -> getParameter ( 'title' );
2021-10-01 22:52:30 +00:00
if ( ! is_array ( $data [ 'regexp' ] ? ? false ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'regexp' ] = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '|' , str_replace ( ' ' , '\_' , $option ) );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $newMatches , true ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$data [ 'regexp' ] = array_merge ( $data [ 'regexp' ], $newMatches );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'title' , $data );
$this -> setSelectionCriteriaFound ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'titlematch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _titlematch ( $option ) {
$data = $this -> getParameter ( 'title' );
2021-03-23 23:47:30 +00:00
2021-10-01 22:52:30 +00:00
if ( ! is_array ( $data [ 'like' ] ? ? false ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'like' ] = [];
}
2021-03-23 23:47:30 +00:00
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '|' , str_replace ( ' ' , '\_' , $option ) );
$data [ 'like' ] = array_merge ( $data [ 'like' ], $newMatches );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'title' , $data );
$this -> setSelectionCriteriaFound ( true );
2021-03-23 23:47:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'nottitleregexp' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _nottitleregexp ( $option ) {
$data = $this -> getParameter ( 'nottitle' );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! is_array ( $data [ 'regexp' ] ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'regexp' ] = [];
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '|' , str_replace ( ' ' , '\_' , $option ) );
$data [ 'regexp' ] = array_merge ( $data [ 'regexp' ], $newMatches );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $newMatches , true ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'nottitle' , $data );
$this -> setSelectionCriteriaFound ( true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'nottitlematch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _nottitlematch ( $option ) {
$data = $this -> getParameter ( 'nottitle' );
2021-05-30 18:44:40 +00:00
2021-10-01 22:52:30 +00:00
if ( ! is_array ( $data [ 'like' ] ? ? false ) ) {
2020-11-22 20:00:48 +00:00
$data [ 'like' ] = [];
}
2021-05-30 18:44:40 +00:00
2021-02-22 23:48:01 +00:00
$newMatches = explode ( '|' , str_replace ( ' ' , '\_' , $option ) );
$data [ 'like' ] = array_merge ( $data [ 'like' ], $newMatches );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'nottitle' , $data );
$this -> setSelectionCriteriaFound ( true );
2021-05-30 18:44:40 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'scroll' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _scroll ( $option ) {
$option = $this -> filterBoolean ( $option );
$this -> setParameter ( 'scroll' , $option );
2021-10-01 22:52:30 +00:00
// If scrolling is active we adjust the values for certain other parameters based on URL arguments
2021-02-22 23:48:01 +00:00
if ( $option === true ) {
2020-11-22 20:00:48 +00:00
global $wgRequest ;
2021-10-01 22:52:30 +00:00
// The 'findTitle' option has argument over the 'fromTitle' argument.
2021-02-22 23:48:01 +00:00
$titlegt = $wgRequest -> getVal ( 'DPL_findTitle' , '' );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! empty ( $titlegt ) ) {
$titlegt = '=_' . ucfirst ( $titlegt );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$titlegt = $wgRequest -> getVal ( 'DPL_fromTitle' , '' );
$titlegt = ucfirst ( $titlegt );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'titlegt' , str_replace ( ' ' , '_' , $titlegt ) );
2020-11-22 20:00:48 +00:00
2021-10-01 22:52:30 +00:00
// Lets get the 'toTitle' argument.
2021-02-22 23:48:01 +00:00
$titlelt = $wgRequest -> getVal ( 'DPL_toTitle' , '' );
$titlelt = ucfirst ( $titlelt );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'titlelt' , str_replace ( ' ' , '_' , $titlelt ) );
2020-11-22 20:00:48 +00:00
2021-10-01 22:52:30 +00:00
// Make sure the 'scrollDir' arugment is captured. This is mainly used for the Variables extension and in the header/footer replacements.
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'scrolldir' , $wgRequest -> getVal ( 'DPL_scrollDir' , '' ) );
2020-11-22 20:00:48 +00:00
2021-10-01 22:52:30 +00:00
// Also set count limit from URL if not otherwise set.
2021-02-22 23:48:01 +00:00
$this -> _count ( $wgRequest -> getInt ( 'DPL_count' ) );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
// We do not return false since they could have just left it out. Who knows why they put the parameter in the list in the first place.
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'replaceintitle' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _replaceintitle ( $option ) {
2021-10-01 22:52:30 +00:00
// We offer a possibility to replace some part of the title
2021-02-22 23:48:01 +00:00
$replaceInTitle = explode ( ',' , $option , 2 );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( isset ( $replaceInTitle [ 1 ] ) ) {
$replaceInTitle [ 1 ] = $this -> stripHtmlTags ( $replaceInTitle [ 1 ] );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'replaceintitle' , $replaceInTitle );
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'debug' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _debug ( $option ) {
if ( in_array ( $option , $this -> getData ( 'debug' )[ 'values' ] ) ) {
2021-10-01 22:52:30 +00:00
DynamicPageListHooks :: setDebugLevel ( $option );
2020-11-22 20:00:48 +00:00
} else {
return false ;
}
return true ;
}
/**
* Short cut to _include ();
*
2021-02-23 00:06:29 +00:00
* @ return mixed
2020-11-22 20:00:48 +00:00
*/
public function _includepage () {
2021-02-22 23:48:01 +00:00
return call_user_func_array ( [ $this , '_include' ], func_get_args () );
2020-11-22 20:00:48 +00:00
}
/**
* Clean and test 'include' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _include ( $option ) {
if ( ! empty ( $option ) ) {
$this -> setParameter ( 'incpage' , true );
$this -> setParameter ( 'seclabels' , explode ( ',' , $option ) );
2020-11-22 20:00:48 +00:00
} else {
return false ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'includematch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _includematch ( $option ) {
$regexes = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $regexes ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'seclabelsmatch' , $regexes );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'includematchparsed' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _includematchparsed ( $option ) {
$regexes = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $regexes ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'incparsed' , true );
$this -> setParameter ( 'seclabelsmatch' , $regexes );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'includenotmatch' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _includenotmatch ( $option ) {
$regexes = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $regexes ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'seclabelsnotmatch' , $regexes );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'includenotmatchparsed' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _includenotmatchparsed ( $option ) {
$regexes = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! $this -> isRegexValid ( $regexes ) ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'incparsed' , true );
$this -> setParameter ( 'seclabelsnotmatch' , $regexes );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'secseparators' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _secseparators ( $option ) {
2021-10-01 22:52:30 +00:00
// We replace '\n' by newline to support wiki syntax within the section separators
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'secseparators' , explode ( ',' , Parse :: replaceNewLines ( $option ) ) );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'multisecseparators' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _multisecseparators ( $option ) {
2021-10-01 22:52:30 +00:00
// We replace '\n' by newline to support wiki syntax within the section separators
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'multisecseparators' , explode ( ',' , Parse :: replaceNewLines ( $option ) ) );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'table' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _table ( $option ) {
$this -> setParameter ( 'defaulttemplatesuffix' , '' );
$this -> setParameter ( 'mode' , 'userformat' );
$this -> setParameter ( 'inlinetext' , '' );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$withHLink = " [[%PAGE%|%TITLE%]] \n | " ;
2021-10-01 22:52:30 +00:00
$listSeparators = [];
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
foreach ( explode ( ',' , $option ) as $tabnr => $tab ) {
if ( $tabnr == 0 ) {
if ( $tab == '' ) {
2020-11-22 20:00:48 +00:00
$tab = 'class=wikitable' ;
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$listSeparators [ 0 ] = '{|' . $tab ;
} else {
2021-02-22 23:48:01 +00:00
if ( $tabnr == 1 && $tab == '-' ) {
2020-11-22 20:00:48 +00:00
$withHLink = '' ;
continue ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( $tabnr == 1 && $tab == '' ) {
$tab = wfMessage ( 'article' ) -> text ();
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$listSeparators [ 0 ] .= " \n ! { $tab } " ;
}
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
$listSeparators [ 1 ] = '' ;
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
// the user may have specified the third parameter of 'format' to add meta attributes of articles to the table
2021-10-01 22:52:30 +00:00
$listSeparators [ 2 ] = '' ;
2020-11-22 20:00:48 +00:00
$listSeparators [ 3 ] = " \n |} " ;
2021-10-01 22:52:30 +00:00
// Overwrite 'listseparators'.
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'listseparators' , $listSeparators );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
$sectionLabels = ( array ) $this -> getParameter ( 'seclabels' );
$sectionSeparators = $this -> getParameter ( 'secseparators' );
$multiSectionSeparators = $this -> getParameter ( 'multisecseparators' );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
for ( $i = 0 ; $i < count ( $sectionLabels ); $i ++ ) {
if ( $i == 0 ) {
2021-10-01 22:52:30 +00:00
$sectionSeparators [ 0 ] = " \n |- \n | " . $withHLink ; // ."\n";
$sectionSeparators [ 1 ] = '' ;
$multiSectionSeparators [ 0 ] = " \n |- \n | " . $withHLink ; // ."\n";
2020-11-22 20:00:48 +00:00
} else {
2021-10-01 22:52:30 +00:00
$sectionSeparators [ 2 * $i ] = " \n | " ; // ."\n";
$sectionSeparators [ 2 * $i + 1 ] = '' ;
2021-02-22 23:48:01 +00:00
if ( is_array ( $sectionLabels [ $i ] ) && $sectionLabels [ $i ][ 0 ] == '#' ) {
2020-11-22 20:00:48 +00:00
$multiSectionSeparators [ $i ] = " \n ---- \n " ;
} else {
$multiSectionSeparators [ $i ] = " <br/> \n " ;
}
}
}
2021-10-01 22:52:30 +00:00
// Overwrite 'secseparators' and 'multisecseparators'.
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'secseparators' , $sectionSeparators );
$this -> setParameter ( 'multisecseparators' , $multiSectionSeparators );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'table' , Parse :: replaceNewLines ( $option ) );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'tablerow' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _tablerow ( $option ) {
$option = Parse :: replaceNewLines ( trim ( $option ) );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( empty ( $option ) ) {
$this -> setParameter ( 'tablerow' , [] );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'tablerow' , explode ( ',' , $option ) );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'allowcachedresults' parameter .
* This function is necessary for the custom 'yes+warn' option that sets 'warncachedresults' .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool | int | string
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _allowcachedresults ( $option ) {
2021-10-01 22:52:30 +00:00
// If execAndExit was previously set (i.e. if it is not empty) we will ignore all cache settings which are placed AFTER the execandexit statement thus we make sure that the cache will only become invalid if the query is really executed.
2021-02-22 23:48:01 +00:00
if ( $this -> getParameter ( 'execandexit' ) === null ) {
if ( $option === 'yes+warn' ) {
$this -> setParameter ( 'allowcachedresults' , true );
$this -> setParameter ( 'warncachedresults' , true );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$option = $this -> filterBoolean ( $option );
if ( $option !== null ) {
$this -> setParameter ( 'allowcachedresults' , $this -> filterBoolean ( $option ) );
2020-11-22 20:00:48 +00:00
} else {
return false ;
}
} else {
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'allowcachedresults' , false );
2020-11-22 20:00:48 +00:00
}
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'fixcategory' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _fixcategory ( $option ) {
2021-10-01 22:52:30 +00:00
DynamicPageListHooks :: fixCategory ( $option );
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'reset' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _reset ( $option ) {
$arguments = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
$reset = [];
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $arguments as $argument ) {
$argument = trim ( $argument );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( empty ( $argument ) ) {
2020-11-22 20:00:48 +00:00
continue ;
}
2021-02-22 23:48:01 +00:00
$values = $this -> getData ( 'reset' )[ 'values' ];
if ( ! in_array ( $argument , $values ) ) {
2020-11-22 20:00:48 +00:00
return false ;
} else {
2021-02-22 23:48:01 +00:00
if ( $argument == 'all' || $argument == 'none' ) {
2021-10-01 22:52:30 +00:00
$boolean = ( $argument == 'all' );
2021-02-22 23:48:01 +00:00
$values = array_diff ( $values , [ 'all' , 'none' ] );
$reset = array_flip ( $values );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $reset as $value => $key ) {
2020-11-22 20:00:48 +00:00
$reset [ $value ] = $boolean ;
}
} else {
$reset [ $argument ] = true ;
}
}
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'reset' );
$data = array_merge ( $data , $reset );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$this -> setParameter ( 'reset' , $data );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
/**
* Clean and test 'eliminate' parameter .
*
2021-10-01 22:52:30 +00:00
* @ param string $option
* @ return bool
2020-11-22 20:00:48 +00:00
*/
2021-02-22 23:48:01 +00:00
public function _eliminate ( $option ) {
$arguments = explode ( ',' , $option );
2020-11-22 20:00:48 +00:00
$eliminate = [];
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $arguments as $argument ) {
$argument = trim ( $argument );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( empty ( $argument ) ) {
2020-11-22 20:00:48 +00:00
continue ;
}
2021-02-22 23:48:01 +00:00
$values = $this -> getData ( 'eliminate' )[ 'values' ];
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
if ( ! in_array ( $argument , $values ) ) {
2020-11-22 20:00:48 +00:00
return false ;
} else {
2021-02-22 23:48:01 +00:00
if ( $argument == 'all' || $argument == 'none' ) {
2021-10-01 22:52:30 +00:00
$boolean = ( $argument == 'all' );
2021-02-22 23:48:01 +00:00
$values = array_diff ( $values , [ 'all' , 'none' ] );
$eliminate = array_flip ( $values );
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
foreach ( $eliminate as $value => $key ) {
2020-11-22 20:00:48 +00:00
$eliminate [ $value ] = $boolean ;
}
} else {
$eliminate [ $argument ] = true ;
}
}
}
2021-10-01 22:52:30 +00:00
2021-02-22 23:48:01 +00:00
$data = $this -> getParameter ( 'eliminate' );
$data = array_merge ( $data , $eliminate );
$this -> setParameter ( 'eliminate' , $data );
2021-10-01 22:52:30 +00:00
2020-11-22 20:00:48 +00:00
return true ;
}
}