2020-11-22 20:00:48 +00:00
< ? php
/**
* DynamicPageList3
* DPL Variables Class
*
2020-11-24 00:39:53 +00:00
* @ author IlyaHaykinson , Unendlich , Dangerville , Algorithmix , Theaitetos , Alexia E . Smith , Universal Omega
2020-11-22 20:00:48 +00:00
* @ license GPL - 2.0 - or - later
* @ package DynamicPageList3
*
2021-02-22 23:48:01 +00:00
*/
2020-11-22 20:00:48 +00:00
namespace DPL ;
2021-05-30 18:33:21 +00:00
use MediaWiki\MediaWikiServices ;
2020-11-22 20:00:48 +00:00
class Query {
/**
* Parameters Object
*
2021-02-22 23:48:01 +00:00
* @ var object
2020-11-22 20:00:48 +00:00
*/
private $parameters ;
/**
* Mediawiki DB Object
*
2021-02-22 23:48:01 +00:00
* @ var object
2020-11-22 20:00:48 +00:00
*/
private $DB ;
/**
* Array of prefixed and escaped table names .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $tableNames = [];
/**
* 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 = [];
/**
* Select Fields
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $select = [];
/**
* The generated SQL Query .
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:00:48 +00:00
*/
private $sqlQuery = '' ;
/**
* Selected Fields - An array to look up keys against for speed optimization .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $selectedFields = [];
/**
* Prefixed and escaped table names .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $tables = [];
/**
* Where Clauses
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $where = [];
/**
* Group By Clauses
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $groupBy = [];
/**
* Order By Clauses
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $orderBy = [];
/**
* Join Clauses
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:00:48 +00:00
*/
private $join = [];
/**
* Limit
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:00:48 +00:00
*/
private $limit = false ;
/**
* Offset
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:00:48 +00:00
*/
private $offset = false ;
/**
* Order By Direction
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:00:48 +00:00
*/
private $direction = 'ASC' ;
/**
* Distinct Results
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:00:48 +00:00
*/
private $distinct = true ;
/**
* Character Set Collation
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:00:48 +00:00
*/
private $collation = false ;
/**
* Number of Rows Found
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:00:48 +00:00
*/
private $foundRows = 0 ;
/**
* Was the revision auxiliary table select added for firstedit and lastedit ?
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:00:48 +00:00
*/
private $revisionAuxWhereAdded = false ;
/**
* Main Constructor
*
* @ access public
* @ param \DPL\Parameters $parameters
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function __construct ( Parameters $parameters ) {
2020-11-22 20:00:48 +00:00
$this -> parameters = $parameters ;
$this -> tableNames = self :: getTableNames ();
2021-02-22 23:48:01 +00:00
$this -> DB = wfGetDB ( DB_REPLICA , 'dpl' );
2020-11-22 20:00:48 +00:00
}
/**
* Start a query build .
*
* @ access public
* @ param boolean Calculate Found Rows
* @ return mixed Mediawiki Result Object or False
*/
2021-02-22 23:48:01 +00:00
public function buildAndSelect ( $calcRows = false ) {
2020-11-22 20:00:48 +00:00
global $wgNonincludableNamespaces ;
$options = [];
$parameters = $this -> parameters -> getAllParameters ();
2021-02-22 23:48:01 +00:00
foreach ( $parameters as $parameter => $option ) {
2020-11-22 20:00:48 +00:00
$function = " _ " . $parameter ;
//Some parameters do not modifiy the query so we check if the function to modify the query exists first.
$success = true ;
2021-02-22 23:48:01 +00:00
if ( method_exists ( $this , $function ) ) {
$success = $this -> $function ( $option );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $success === false ) {
throw new \MWException ( __METHOD__ . " : SQL Build Error returned from { $function } for " . serialize ( $option ) . " . " );
2020-11-22 20:00:48 +00:00
}
$this -> parametersProcessed [ $parameter ] = true ;
}
2021-02-22 23:48:01 +00:00
if ( ! $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
//Add things that are always part of the query.
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'page' , $this -> tableNames [ 'page' ] );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'page_namespace' => $this -> tableNames [ 'page' ] . '.page_namespace' ,
'page_id' => $this -> tableNames [ 'page' ] . '.page_id' ,
'page_title' => $this -> tableNames [ 'page' ] . '.page_title'
]
);
}
//Always add nonincludeable namespaces.
2021-02-22 23:48:01 +00:00
if ( is_array ( $wgNonincludableNamespaces ) && count ( $wgNonincludableNamespaces ) ) {
2020-11-22 20:00:48 +00:00
$this -> addNotWhere (
[
$this -> tableNames [ 'page' ] . '.page_namespace' => $wgNonincludableNamespaces
]
);
}
2021-02-22 23:48:01 +00:00
if ( $this -> offset !== false ) {
2020-11-22 20:00:48 +00:00
$options [ 'OFFSET' ] = $this -> offset ;
}
2021-02-22 23:48:01 +00:00
if ( $this -> limit !== false ) {
2020-11-22 20:00:48 +00:00
$options [ 'LIMIT' ] = $this -> limit ;
2021-02-22 23:48:01 +00:00
} elseif ( $this -> offset !== false && $this -> limit === false ) {
$options [ 'LIMIT' ] = $this -> parameters -> getData ( 'count' )[ 'default' ];
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
if ( count ( $this -> parameters -> getParameter ( 'imagecontainer' ) ) > 0 ) {
2020-11-22 20:00:48 +00:00
//$sSqlSelectFrom = $sSqlCl_to.'ic.il_to, '.$sSqlSelPage."ic.il_to AS sortkey".' FROM '.$this->tableNames['imagelinks'].' AS ic';
$tables = [
'ic' => 'imagelinks'
];
} else {
//$sSqlSelectFrom = "SELECT $sSqlCalcFoundRows $sSqlDistinct ".$sSqlCl_to.'pl_namespace, pl_title'.$sSqlSelPage.$sSqlSortkey.' FROM '.$this->tableNames['pagelinks'];
$this -> addSelect (
[
'pl_namespace' ,
'pl_title'
]
);
$tables = [
'pagelinks'
];
}
} else {
$tables = $this -> tables ;
2021-02-22 23:48:01 +00:00
if ( count ( $this -> groupBy ) ) {
2020-11-22 20:00:48 +00:00
$options [ 'GROUP BY' ] = $this -> groupBy ;
}
2021-02-22 23:48:01 +00:00
if ( count ( $this -> orderBy ) ) {
2020-11-22 20:00:48 +00:00
$options [ 'ORDER BY' ] = $this -> orderBy ;
2021-02-22 23:48:01 +00:00
foreach ( $options [ 'ORDER BY' ] as $key => $value ) {
2020-11-22 20:00:48 +00:00
$options [ 'ORDER BY' ][ $key ] .= " " . $this -> direction ;
}
}
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'goal' ) == 'categories' ) {
2020-11-22 20:00:48 +00:00
$categoriesGoal = true ;
$select = [
$this -> tableNames [ 'page' ] . '.page_id'
];
$options [] = 'DISTINCT' ;
} else {
2021-02-22 23:48:01 +00:00
if ( $calcRows ) {
2020-11-22 20:00:48 +00:00
$options [] = 'SQL_CALC_FOUND_ROWS' ;
}
2021-02-22 23:48:01 +00:00
if ( $this -> distinct ) {
2020-11-22 20:00:48 +00:00
$options [] = 'DISTINCT' ;
}
$categoriesGoal = false ;
$select = $this -> select ;
}
$queryError = false ;
try {
2021-02-22 23:48:01 +00:00
if ( $categoriesGoal ) {
2020-11-22 20:00:48 +00:00
$result = $this -> DB -> select (
$tables ,
$select ,
$this -> where ,
__METHOD__ ,
$options ,
$this -> join
);
2021-02-22 23:48:01 +00:00
while ( $row = $result -> fetchRow () ) {
2020-11-22 20:00:48 +00:00
$pageIds [] = $row [ 'page_id' ];
}
$sql = $this -> DB -> selectSQLText (
[
'clgoal' => 'categorylinks'
],
[
'clgoal.cl_to'
],
[
'clgoal.cl_from' => $pageIds
],
__METHOD__ ,
[
'ORDER BY' => 'clgoal.cl_to ' . $this -> direction
]
);
} else {
$sql = $this -> DB -> selectSQLText (
$tables ,
$select ,
$this -> where ,
__METHOD__ ,
$options ,
$this -> join
);
}
$this -> sqlQuery = $sql ;
2021-02-22 23:48:01 +00:00
$result = $this -> DB -> query ( $sql , __METHOD__ );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( $calcRows ) {
$calcRowsResult = $this -> DB -> query ( 'SELECT FOUND_ROWS() AS rowcount' , __METHOD__ );
$total = $this -> DB -> fetchRow ( $calcRowsResult );
$this -> foundRows = intval ( $total [ 'rowcount' ] );
$this -> DB -> freeResult ( $calcRowsResult );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
} catch ( Exception $e ) {
2020-11-22 20:00:48 +00:00
$queryError = true ;
}
2021-02-22 23:48:01 +00:00
if ( $queryError == true || $result === false ) {
throw new \MWException ( __METHOD__ . " : " . wfMessage ( 'dpl_query_error' , DPL_VERSION , $this -> DB -> lastError () ) -> text () );
2020-11-22 20:00:48 +00:00
}
return $result ;
}
/**
* Return the number of found rows .
*
* @ access public
* @ return integer Number of Found Rows
*/
public function getFoundRows () {
return $this -> foundRows ;
}
/**
* Returns the generated SQL Query
*
* @ access public
* @ return string SQL Query
*/
public function getSqlQuery () {
return $this -> sqlQuery ;
}
/**
* Return prefixed and quoted tables that are needed .
*
* @ access public
* @ return array Prepared table names .
*/
public static function getTableNames () {
2021-02-22 23:48:01 +00:00
$DB = wfGetDB ( DB_REPLICA , 'dpl' );
2020-11-22 20:00:48 +00:00
$tables = [
'categorylinks' ,
'dpl_clview' ,
'externallinks' ,
'flaggedpages' ,
'imagelinks' ,
'page' ,
'pagelinks' ,
'recentchanges' ,
'revision' ,
2020-11-23 03:50:40 +00:00
'revision_actor_temp' ,
2020-11-22 20:00:48 +00:00
'templatelinks'
];
$tableNames = [];
2021-02-22 23:48:01 +00:00
foreach ( $tables as $table ) {
$tableNames [ $table ] = $DB -> tableName ( $table );
2020-11-22 20:00:48 +00:00
}
return $tableNames ;
}
/**
* Add a table to the output .
*
* @ access public
* @ param string Raw Table Name - Will be ran through tableName () .
* @ param string Table Alias
* @ return boolean Success - Added , false if the table alias already exists .
*/
2021-02-22 23:48:01 +00:00
public function addTable ( $table , $alias ) {
if ( empty ( $table ) ) {
throw new \MWException ( __METHOD__ . ': An empty table name was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( empty ( $alias ) || is_numeric ( $alias ) ) {
throw new \MWException ( __METHOD__ . ': An empty or numeric table alias was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( ! isset ( $this -> tables [ $alias ] ) ) {
$this -> tables [ $alias ] = $this -> DB -> tableName ( $table );
2020-11-22 20:00:48 +00:00
return true ;
} else {
return false ;
}
}
/**
* Add a where clause to the output .
* Where clauses get imploded together with AND at the end . Any custom where clauses should be preformed before placed into here .
*
* @ access public
* @ param string Where clause
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addWhere ( $where ) {
if ( empty ( $where ) ) {
throw new \MWException ( __METHOD__ . ': An empty where clause was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( is_string ( $where ) ) {
2020-11-22 20:00:48 +00:00
$this -> where [] = $where ;
2021-02-22 23:48:01 +00:00
} elseif ( is_array ( $where ) ) {
$this -> where = array_merge ( $this -> where , $where );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
throw new \MWException ( __METHOD__ . ': An invalid where clause was passed.' );
2020-11-22 20:00:48 +00:00
return false ;
}
return true ;
}
/**
* Add a where clause to the output that uses NOT IN or !=.
*
* @ access public
* @ param array Field => Value ( s )
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addNotWhere ( $where ) {
if ( empty ( $where ) ) {
throw new \MWException ( __METHOD__ . ': An empty not where clause was passed.' );
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
if ( is_array ( $where ) ) {
foreach ( $where as $field => $values ) {
$this -> where [] = $field . ( count ( $values ) > 1 ? ' NOT IN(' . $this -> DB -> makeList ( $values ) . ')' : ' != ' . $this -> DB -> addQuotes ( current ( $values ) ) );
2020-11-22 20:00:48 +00:00
}
} else {
2021-02-22 23:48:01 +00:00
throw new \MWException ( __METHOD__ . ': An invalid not where clause was passed.' );
2020-11-22 20:00:48 +00:00
return false ;
}
return true ;
}
/**
* Add a field to select .
* Will ignore duplicate values if the exact same alias and exact same field are passed .
*
* @ access public
* @ param array Array of fields with the array key being the field alias . Leave the array key as a numeric index to not specify an alias .
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addSelect ( $fields ) {
if ( ! is_array ( $fields ) ) {
throw new \MWException ( __METHOD__ . ': A non-array was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
foreach ( $fields as $alias => $field ) {
if ( ! is_numeric ( $alias ) && array_key_exists ( $alias , $this -> select ) && $this -> select [ $alias ] != $field ) {
2020-11-22 20:00:48 +00:00
//In case of a code bug that is overwriting an existing field alias throw an exception.
2021-02-22 23:48:01 +00:00
throw new \MWException ( __METHOD__ . " : Attempted to overwrite existing field alias ` { $this -> select [ $alias ] } ` AS ` { $alias } ` with ` { $field } ` AS ` { $alias } `. " );
2020-11-22 20:00:48 +00:00
}
//String alias and does not exist already.
2021-02-22 23:48:01 +00:00
if ( ! is_numeric ( $alias ) && ! array_key_exists ( $alias , $this -> select ) ) {
2020-11-22 20:00:48 +00:00
$this -> select [ $alias ] = $field ;
}
//Speed up by not using in_array() or array_key_exists(). Toss the field names into their own array as keys => true to exploit a speedy look up with isset().
2021-02-22 23:48:01 +00:00
if ( is_numeric ( $alias ) && ! isset ( $this -> selectedFields [ $field ] ) ) {
2020-11-22 20:00:48 +00:00
$this -> select [] = $field ;
$this -> selectedFields [ $field ] = true ;
}
}
return true ;
}
/**
* Add a GROUP BY clause to the output .
*
* @ access public
* @ param string Group By Clause
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addGroupBy ( $groupBy ) {
if ( empty ( $groupBy ) ) {
throw new \MWException ( __METHOD__ . ': An empty group by clause was passed.' );
2020-11-22 20:00:48 +00:00
}
$this -> groupBy [] = $groupBy ;
return true ;
}
/**
* Add a ORDER BY clause to the output .
*
* @ access public
* @ param string Order By Clause
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addOrderBy ( $orderBy ) {
if ( empty ( $orderBy ) ) {
throw new \MWException ( __METHOD__ . ': An empty order by clause was passed.' );
2020-11-22 20:00:48 +00:00
}
$this -> orderBy [] = $orderBy ;
return true ;
}
/**
* Add a JOIN clause to the output .
*
* @ access public
* @ param string Table Alias
* @ param array Join Conditions in the format of the join type to the on where condition . Example : [ 'JOIN TYPE' => 'this = that' ]
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function addJoin ( $tableAlias , $joinConditions ) {
if ( empty ( $tableAlias ) || empty ( $joinConditions ) ) {
throw new \MWException ( __METHOD__ . ': An empty join clause was passed.' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( isset ( $this -> join [ $tableAlias ] ) ) {
throw new \MWException ( __METHOD__ . ': Attempted to overwrite existing join clause.' );
2020-11-22 20:00:48 +00:00
}
$this -> join [ $tableAlias ] = $joinConditions ;
return true ;
}
/**
* Set the limit .
*
* @ access public
* @ param mixed Integer limit or false to unset .
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function setLimit ( $limit ) {
if ( is_numeric ( $limit ) ) {
$this -> limit = intval ( $limit );
2020-11-22 20:00:48 +00:00
} else {
$this -> limit = false ;
}
return true ;
}
/**
* Set the offset .
*
* @ access public
* @ param mixed Integer offset or false to unset .
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function setOffset ( $offset ) {
if ( is_numeric ( $offset ) ) {
$this -> offset = intval ( $offset );
2020-11-22 20:00:48 +00:00
} else {
$this -> offset = false ;
}
return true ;
}
/**
* Set the ORDER BY direction
*
* @ access public
* @ param string SQL direction key word .
* @ return boolean Success
*/
2021-02-22 23:48:01 +00:00
public function setOrderDir ( $direction ) {
2020-11-22 20:00:48 +00:00
$this -> direction = $direction ;
return true ;
}
/**
* Set the character set collation .
*
* @ access public
* @ param string Collation
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setCollation ( $collation ) {
2020-11-22 20:00:48 +00:00
$this -> collation = $collation ;
}
/**
* Return SQL prefixed collation .
*
* @ access public
* @ return string SQL Collation
*/
public function getCollateSQL () {
2021-02-22 23:48:01 +00:00
return ( $this -> collation !== false ? 'COLLATE ' . $this -> collation : null );
2020-11-22 20:00:48 +00:00
}
/**
* Recursively get and return an array of subcategories .
*
* @ access public
* @ param string Category Name
* @ param integer [ Optional ] Maximum Depth
* @ return array Subcategories
*/
2021-02-22 23:48:01 +00:00
public static function getSubcategories ( $categoryName , $depth = 1 ) {
$DB = wfGetDB ( DB_REPLICA , 'dpl' );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( $depth > 2 ) {
2020-11-22 20:00:48 +00:00
//Hard constrain depth because lots of recursion is bad.
$depth = 2 ;
}
$categories = [];
$result = $DB -> select (
2021-02-22 23:48:01 +00:00
[ 'page' , 'categorylinks' ],
[ 'page_title' ],
2020-11-22 20:00:48 +00:00
[
2021-02-22 23:48:01 +00:00
'page_namespace' => intval ( NS_CATEGORY ),
'categorylinks.cl_to' => str_replace ( ' ' , '_' , $categoryName )
2020-11-22 20:00:48 +00:00
],
__METHOD__ ,
2021-02-22 23:48:01 +00:00
[ 'DISTINCT' ],
2020-11-22 20:00:48 +00:00
[
'categorylinks' => [
'INNER JOIN' ,
'page.page_id = categorylinks.cl_from'
]
]
);
2021-02-22 23:48:01 +00:00
while ( $row = $result -> fetchRow () ) {
2020-11-22 20:00:48 +00:00
$categories [] = $row [ 'page_title' ];
2021-02-22 23:48:01 +00:00
if ( $depth > 1 ) {
$categories = array_merge ( $categories , self :: getSubcategories ( $row [ 'page_title' ], $depth - 1 ) );
2020-11-22 20:00:48 +00:00
}
}
2021-02-22 23:48:01 +00:00
$categories = array_unique ( $categories );
$DB -> freeResult ( $result );
2020-11-22 20:00:48 +00:00
return $categories ;
}
/**
* Helper method to handle relative timestamps .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Integer or string
* @ return integer
*/
2021-02-22 23:48:01 +00:00
private function convertTimestamp ( $inputDate ) {
2020-11-22 20:00:48 +00:00
$timestamp = $inputDate ;
2021-02-22 23:48:01 +00:00
switch ( $inputDate ) {
2020-11-22 20:00:48 +00:00
case 'today' :
2021-02-22 23:48:01 +00:00
$timestamp = date ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
case 'last hour' :
$date = new \DateTime ();
2021-02-22 23:48:01 +00:00
$date -> sub ( new \DateInterval ( 'P1H' ) );
$timestamp = $date -> format ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
case 'last day' :
$date = new \DateTime ();
2021-02-22 23:48:01 +00:00
$date -> sub ( new \DateInterval ( 'P1D' ) );
$timestamp = $date -> format ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
case 'last week' :
$date = new \DateTime ();
2021-02-22 23:48:01 +00:00
$date -> sub ( new \DateInterval ( 'P7D' ) );
$timestamp = $date -> format ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
case 'last month' :
$date = new \DateTime ();
2021-02-22 23:48:01 +00:00
$date -> sub ( new \DateInterval ( 'P1M' ) );
$timestamp = $date -> format ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
case 'last year' :
$date = new \DateTime ();
2021-02-22 23:48:01 +00:00
$date -> sub ( new \DateInterval ( 'P1Y' ) );
$timestamp = $date -> format ( 'YmdHis' );
2020-11-22 20:00:48 +00:00
break ;
}
2021-02-22 23:48:01 +00:00
if ( is_numeric ( $timestamp ) ) {
return $this -> DB -> addQuotes ( $timestamp );
2020-11-22 20:00:48 +00:00
}
return 0 ;
}
/**
* Set SQL for 'addauthor' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addauthor ( $option ) {
2020-11-22 20:00:48 +00:00
//Addauthor can not be used with addlasteditor.
2021-02-22 23:48:01 +00:00
if ( ! isset ( $this -> parametersProcessed [ 'addlasteditor' ] ) || ! $this -> parametersProcessed [ 'addlasteditor' ] ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
'rev.revactor_timestamp = (SELECT MIN(rev_aux_min.revactor_timestamp) FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' AS rev_aux_min WHERE rev_aux_min.revactor_page = rev.revactor_page)'
2020-11-22 20:00:48 +00:00
]
);
2021-02-22 23:48:01 +00:00
$this -> _adduser ( null , 'rev' );
2020-11-22 20:00:48 +00:00
}
}
/**
* Set SQL for 'addcategories' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addcategories ( $option ) {
$this -> addTable ( 'categorylinks' , 'cl_gc' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'cats' => " GROUP_CONCAT(DISTINCT cl_gc.cl_to ORDER BY cl_gc.cl_to ASC SEPARATOR ' | ') "
]
);
$this -> addJoin (
'cl_gc' ,
[
'LEFT OUTER JOIN' ,
'page_id = cl_gc.cl_from'
]
);
2021-02-22 23:48:01 +00:00
$this -> addGroupBy ( $this -> tableNames [ 'page' ] . '.page_id' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'addcontribution' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addcontribution ( $option ) {
$this -> addTable ( 'recentchanges' , 'rc' );
2020-11-22 20:00:48 +00:00
$field = 'rc.rc_actor' ;
$this -> addSelect (
[
'contribution' => 'SUM(ABS(rc.rc_new_len - rc.rc_old_len))' ,
'contributor' => $field
]
);
$this -> addWhere (
[
$this -> tableNames [ 'page' ] . '.page_id = rc.rc_cur_id'
]
);
2021-02-22 23:48:01 +00:00
$this -> addGroupBy ( 'rc.rc_cur_id' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'addeditdate' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addeditdate ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
$this -> addSelect ( [ 'rev.revactor_timestamp' ] );
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'addfirstcategorydate' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addfirstcategorydate ( $option ) {
2020-11-22 20:00:48 +00:00
//@TODO: This should be programmatically determining which categorylink table to use instead of assuming the first one.
$this -> addSelect (
[
'cl_timestamp' => " DATE_FORMAT(cl1.cl_timestamp, '%Y%m%d%H%i%s') "
]
);
}
/**
* Set SQL for 'addlasteditor' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addlasteditor ( $option ) {
2020-11-22 20:00:48 +00:00
//Addlasteditor can not be used with addauthor.
2021-02-22 23:48:01 +00:00
if ( ! isset ( $this -> parametersProcessed [ 'addauthor' ] ) || ! $this -> parametersProcessed [ 'addauthor' ] ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
'rev.revactor_timestamp = (SELECT MAX(rev_aux_max.revactor_timestamp) FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' AS rev_aux_max WHERE rev_aux_max.revactor_page = rev.revactor_page)'
2020-11-22 20:00:48 +00:00
]
);
2021-02-22 23:48:01 +00:00
$this -> _adduser ( null , 'rev' );
2020-11-22 20:00:48 +00:00
}
}
/**
* Set SQL for 'addpagecounter' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addpagecounter ( $option ) {
if ( class_exists ( " \\ HitCounters \\ Hooks " ) ) {
$this -> addTable ( 'hit_counter' , 'hit_counter' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
" page_counter " => " hit_counter.page_counter "
]
);
2021-02-22 23:48:01 +00:00
if ( ! isset ( $this -> join [ 'hit_counter' ] ) ) {
2020-11-22 20:00:48 +00:00
$this -> addJoin (
'hit_counter' ,
[
" LEFT JOIN " ,
" hit_counter.page_id = " . $this -> tableNames [ 'page' ] . '.page_id'
]
);
}
}
}
/**
* Set SQL for 'addpagesize' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addpagesize ( $option ) {
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
" page_len " => " { $this -> tableNames [ 'page' ] } .page_len "
]
);
}
/**
* Set SQL for 'addpagetoucheddate' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _addpagetoucheddate ( $option ) {
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
" page_touched " => " { $this -> tableNames [ 'page' ] } .page_touched "
]
);
}
/**
* Set SQL for 'adduser' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ param string [ Optional ] Table Alias
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _adduser ( $option , $tableAlias = '' ) {
$tableAlias = ( ! empty ( $tableAlias ) ? $tableAlias . '.' : '' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
2020-11-23 03:50:40 +00:00
$tableAlias . 'revactor_actor' ,
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'allrevisionsbefore' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _allrevisionsbefore ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
2020-11-23 03:50:40 +00:00
'rev.revactor_rev' ,
'rev.revactor_timestamp'
2020-11-22 20:00:48 +00:00
]
);
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'rev.revactor_rev' );
$this -> setOrderDir ( 'DESC' );
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp < ' . $this -> convertTimestamp ( $option )
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'allrevisionssince' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _allrevisionssince ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
2021-02-01 18:13:01 +00:00
'rev.revactor_rev' ,
2020-11-23 03:50:40 +00:00
'rev.revactor_timestamp'
2020-11-22 20:00:48 +00:00
]
);
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'rev.revactor_rev' );
$this -> setOrderDir ( 'DESC' );
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp >= ' . $this -> convertTimestamp ( $option )
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'articlecategory' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _articlecategory ( $option ) {
$this -> addWhere ( " { $this -> tableNames [ 'page' ] } .page_title IN (SELECT p2.page_title FROM { $this -> tableNames [ 'page' ] } p2 INNER JOIN { $this -> tableNames [ 'categorylinks' ] } clstc ON (clstc.cl_from = p2.page_id AND clstc.cl_to = " . $this -> DB -> addQuotes ( $option ) . " ) WHERE p2.page_namespace = 0) " );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'categoriesminmax' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _categoriesminmax ( $option ) {
if ( is_numeric ( $option [ 0 ] ) ) {
$this -> addWhere ( intval ( $option [ 0 ] ) . ' <= (SELECT count(*) FROM ' . $this -> tableNames [ 'categorylinks' ] . ' WHERE ' . $this -> tableNames [ 'categorylinks' ] . '.cl_from=page_id)' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( is_numeric ( $option [ 1 ] ) ) {
$this -> addWhere ( intval ( $option [ 1 ] ) . ' >= (SELECT count(*) FROM ' . $this -> tableNames [ 'categorylinks' ] . ' WHERE ' . $this -> tableNames [ 'categorylinks' ] . '.cl_from=page_id)' );
2020-11-22 20:00:48 +00:00
}
}
/**
* Set SQL for 'category' parameter . This includes 'category' , 'categorymatch' , and 'categoryregexp' .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _category ( $option ) {
2020-11-22 20:00:48 +00:00
$i = 0 ;
2021-02-22 23:48:01 +00:00
foreach ( $option as $comparisonType => $operatorTypes ) {
foreach ( $operatorTypes as $operatorType => $categoryGroups ) {
foreach ( $categoryGroups as $categories ) {
if ( ! is_array ( $categories ) ) {
2020-11-22 20:00:48 +00:00
continue ;
}
2021-02-22 23:48:01 +00:00
$tableName = ( in_array ( '' , $categories ) ? 'dpl_clview' : 'categorylinks' );
if ( $operatorType == 'AND' ) {
foreach ( $categories as $category ) {
2020-11-22 20:00:48 +00:00
$i ++ ;
$tableAlias = " cl { $i } " ;
2021-02-22 23:48:01 +00:00
$this -> addTable ( $tableName , $tableAlias );
2020-11-22 20:00:48 +00:00
$this -> addJoin (
$tableAlias ,
[
'INNER JOIN' ,
2021-02-22 23:48:01 +00:00
" { $this -> tableNames [ 'page' ] } .page_id = { $tableAlias } .cl_from AND $tableAlias .cl_to { $comparisonType } " . $this -> DB -> addQuotes ( str_replace ( ' ' , '_' , $category ) )
2020-11-22 20:00:48 +00:00
]
);
}
2021-02-22 23:48:01 +00:00
} elseif ( $operatorType == 'OR' ) {
2020-11-22 20:00:48 +00:00
$i ++ ;
$tableAlias = " cl { $i } " ;
2021-02-22 23:48:01 +00:00
$this -> addTable ( $tableName , $tableAlias );
2020-11-22 20:00:48 +00:00
$joinOn = " { $this -> tableNames [ 'page' ] } .page_id = { $tableAlias } .cl_from AND ( " ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $categories as $category ) {
$ors [] = " { $tableAlias } .cl_to { $comparisonType } " . $this -> DB -> addQuotes ( str_replace ( ' ' , '_' , $category ) );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$joinOn .= implode ( " { $operatorType } " , $ors );
2020-11-22 20:00:48 +00:00
$joinOn .= ')' ;
$this -> addJoin (
$tableAlias ,
[
'INNER JOIN' ,
$joinOn
]
);
}
}
}
}
}
/**
* Set SQL for 'notcategory' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notcategory ( $option ) {
2020-11-22 20:00:48 +00:00
$i = 0 ;
2021-02-22 23:48:01 +00:00
foreach ( $option as $operatorType => $categories ) {
foreach ( $categories as $category ) {
2020-11-22 20:00:48 +00:00
$i ++ ;
$tableAlias = " ecl { $i } " ;
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'categorylinks' , $tableAlias );
2020-11-22 20:00:48 +00:00
$this -> addJoin (
$tableAlias ,
[
'LEFT OUTER JOIN' ,
2021-02-22 23:48:01 +00:00
" { $this -> tableNames [ 'page' ] } .page_id = { $tableAlias } .cl_from AND { $tableAlias } .cl_to { $operatorType } " . $this -> DB -> addQuotes ( str_replace ( ' ' , '_' , $category ) )
2020-11-22 20:00:48 +00:00
]
);
$this -> addWhere (
[
" { $tableAlias } .cl_to " => null
]
);
}
}
}
/**
* Set SQL for 'createdby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _createdby ( $option ) {
$this -> addTable ( 'revision' , 'creation_rev' );
$this -> addTable ( 'revision_actor_temp' , 'creation_rev_actor' );
$this -> _adduser ( null , 'creation_rev_actor' );
2020-11-23 00:16:25 +00:00
$user = new \User ;
2020-11-23 03:50:40 +00:00
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2021-02-22 23:48:01 +00:00
$this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' = creation_rev_actor.revactor_actor' ,
2020-11-23 03:50:40 +00:00
'creation_rev_actor.revactor_page = page_id' ,
2020-11-22 20:00:48 +00:00
'creation_rev.rev_parent_id = 0'
]
);
}
/**
* Set SQL for 'distinct' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _distinct ( $option ) {
if ( $option == 'strict' || $option === true ) {
2020-11-22 20:00:48 +00:00
$this -> distinct = true ;
} else {
$this -> distinct = false ;
}
}
/**
* Set SQL for 'firstrevisionsince' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _firstrevisionsince ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
2020-11-23 03:50:40 +00:00
'rev.revactor_rev' ,
'rev.revactor_timestamp'
2020-11-22 20:00:48 +00:00
]
);
// tell the query optimizer not to look at rows that the following subquery will filter out anyway
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp >= ' . $this -> DB -> addQuotes ( $option )
2020-11-22 20:00:48 +00:00
]
);
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp = (SELECT MIN(rev_aux_snc.revactor_timestamp) FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' AS rev_aux_snc WHERE rev_aux_snc.revactor_page=rev.revactor_page AND rev_aux_snc.revactor_timestamp >= ' . $this -> convertTimestamp ( $option ) . ')'
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'goal' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _goal ( $option ) {
if ( $option == 'categories' ) {
$this -> setLimit ( false );
$this -> setOffset ( false );
2020-11-22 20:00:48 +00:00
}
}
/**
* Set SQL for 'hiddencategories' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _hiddencategories ( $option ) {
2020-11-22 20:00:48 +00:00
//@TODO: Unfinished functionality! Never implemented by original author.
}
/**
* Set SQL for 'imagecontainer' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _imagecontainer ( $option ) {
$this -> addTable ( 'imagelinks' , 'ic' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'sortkey' => 'ic.il_to'
]
);
2021-02-22 23:48:01 +00:00
if ( ! $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$where = [
2021-02-22 23:48:01 +00:00
" { $this -> tableNames [ 'page' ] } .page_namespace = " . intval ( NS_FILE ),
2020-11-22 20:00:48 +00:00
" { $this -> tableNames [ 'page' ] } .page_title = ic.il_to "
];
}
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$ors [] = " LOWER(CAST(ic.il_from AS char) = LOWER( " . $this -> DB -> addQuotes ( $link -> getArticleID () ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$ors [] = " ic.il_from = " . $this -> DB -> addQuotes ( $link -> getArticleID () );
2020-11-22 20:00:48 +00:00
}
}
}
2021-02-22 23:48:01 +00:00
$where [] = '(' . implode ( ' OR ' , $ors ) . ')' ;
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'imageused' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _imageused ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'imagelinks' , 'il' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'image_sel_title' => 'il.il_to'
]
);
$where [] = $this -> tableNames [ 'page' ] . '.page_id = il.il_from' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$ors [] = " LOWER(CAST(il.il_to AS char))=LOWER( " . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$ors [] = " il.il_to= " . $this -> DB -> addQuotes ( $link -> getDbKey () );
2020-11-22 20:00:48 +00:00
}
}
}
2021-02-22 23:48:01 +00:00
$where [] = '(' . implode ( ' OR ' , $ors ) . ')' ;
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'lastmodifiedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _lastmodifiedby ( $option ) {
2020-11-23 03:50:40 +00:00
$user = new \User ;
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' = (SELECT revactor_actor FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' WHERE ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_page=page_id ORDER BY ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_timestamp DESC LIMIT 1)' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'lastrevisionbefore' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _lastrevisionbefore ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'rev' );
$this -> addSelect ( [ 'rev.revactor_rev' , 'rev.revactor_timestamp' ] );
2020-11-22 20:00:48 +00:00
// tell the query optimizer not to look at rows that the following subquery will filter out anyway
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp < ' . $this -> convertTimestamp ( $option )
2020-11-22 20:00:48 +00:00
]
);
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
$this -> tableNames [ 'page' ] . '.page_id = rev.revactor_page' ,
2021-02-22 23:48:01 +00:00
'rev.revactor_timestamp = (SELECT MAX(rev_aux_bef.revactor_timestamp) FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' AS rev_aux_bef WHERE rev_aux_bef.revactor_page=rev.revactor_page AND rev_aux_bef.revactor_timestamp < ' . $this -> convertTimestamp ( $option ) . ')'
2020-11-22 20:00:48 +00:00
]
);
}
/**
* Set SQL for 'linksfrom' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _linksfrom ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
2020-11-22 20:00:48 +00:00
$ors [] = '(pl_from = ' . $link -> getArticleID () . ')' ;
}
}
2021-02-22 23:48:01 +00:00
$where [] = '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'pagelinks' , 'plf' );
$this -> addTable ( 'page' , 'pagesrc' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'sel_title' => 'pagesrc.page_title' ,
'sel_ns' => 'pagesrc.page_namespace'
]
);
$where = [
$this -> tableNames [ 'page' ] . '.page_namespace = plf.pl_namespace' ,
$this -> tableNames [ 'page' ] . '.page_title = plf.pl_title' ,
'pagesrc.page_id = plf.pl_from'
];
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
2020-11-22 20:00:48 +00:00
$ors [] = 'plf.pl_from = ' . $link -> getArticleID ();
}
}
2021-02-22 23:48:01 +00:00
$where [] = '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'linksto' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _linksto ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( count ( $option ) > 0 ) {
$this -> addTable ( 'pagelinks' , 'pl' );
$this -> addSelect ( [ 'sel_title' => 'pl.pl_title' , 'sel_ns' => 'pl.pl_namespace' ] );
foreach ( $option as $index => $linkGroup ) {
if ( $index == 0 ) {
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_id=pl.pl_from AND ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $linkGroup as $link ) {
$_or = '(pl.pl_namespace=' . intval ( $link -> getNamespace () );
if ( strpos ( $link -> getDbKey (), '%' ) >= 0 ) {
2020-11-22 20:00:48 +00:00
$operator = 'LIKE' ;
} else {
$operator = '=' ;
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or .= ' AND LOWER(CAST(pl.pl_title AS char)) ' . $operator . ' LOWER(' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or .= ' AND pl.pl_title ' . $operator . ' ' . $this -> DB -> addQuotes ( $link -> getDbKey () );
2020-11-22 20:00:48 +00:00
}
$_or .= ')' ;
$ors [] = $_or ;
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
$where = 'EXISTS(select pl_from FROM ' . $this -> tableNames [ 'pagelinks' ] . ' WHERE (' . $this -> tableNames [ 'pagelinks' ] . '.pl_from=page_id AND ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $linkGroup as $link ) {
$_or = '(' . $this -> tableNames [ 'pagelinks' ] . '.pl_namespace=' . intval ( $link -> getNamespace () );
if ( strpos ( $link -> getDbKey (), '%' ) >= 0 ) {
2020-11-22 20:00:48 +00:00
$operator = 'LIKE' ;
} else {
$operator = '=' ;
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or .= ' AND LOWER(CAST(' . $this -> tableNames [ 'pagelinks' ] . '.pl_title AS char)) ' . $operator . ' LOWER(' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or .= ' AND ' . $this -> tableNames [ 'pagelinks' ] . '.pl_title ' . $operator . ' ' . $this -> DB -> addQuotes ( $link -> getDbKey () );
2020-11-22 20:00:48 +00:00
}
$_or .= ')' ;
$ors [] = $_or ;
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
$where .= '))' ;
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
}
}
/**
* Set SQL for 'notlinksfrom' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notlinksfrom ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$ands = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$ands [] = 'pl_from <> ' . intval ( $link -> getArticleID () ) . ' ' ;
2020-11-22 20:00:48 +00:00
}
}
2021-02-22 23:48:01 +00:00
$where = '(' . implode ( ' AND ' , $ands ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
$where = 'CONCAT(page_namespace,page_title) NOT IN (SELECT CONCAT(' . $this -> tableNames [ 'pagelinks' ] . '.pl_namespace,' . $this -> tableNames [ 'pagelinks' ] . '.pl_title) FROM ' . $this -> tableNames [ 'pagelinks' ] . ' WHERE ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$ors [] = $this -> tableNames [ 'pagelinks' ] . '.pl_from = ' . intval ( $link -> getArticleID () );
2020-11-22 20:00:48 +00:00
}
}
2021-02-22 23:48:01 +00:00
$where .= implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'notlinksto' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notlinksto ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( count ( $option ) ) {
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_id NOT IN (SELECT ' . $this -> tableNames [ 'pagelinks' ] . '.pl_from FROM ' . $this -> tableNames [ 'pagelinks' ] . ' WHERE ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$_or = '(' . $this -> tableNames [ 'pagelinks' ] . '.pl_namespace=' . intval ( $link -> getNamespace () );
if ( strpos ( $link -> getDbKey (), '%' ) >= 0 ) {
2020-11-22 20:00:48 +00:00
$operator = 'LIKE' ;
} else {
$operator = '=' ;
}
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or .= ' AND LOWER(CAST(' . $this -> tableNames [ 'pagelinks' ] . '.pl_title AS char)) ' . $operator . ' LOWER(' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . '))' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or .= ' AND ' . $this -> tableNames [ 'pagelinks' ] . '.pl_title ' . $operator . ' ' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
}
$ors [] = $_or ;
}
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . '))' ;
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'linkstoexternal' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _linkstoexternal ( $option ) {
if ( $this -> parameters -> getParameter ( 'distinct' ) == 'strict' ) {
$this -> addGroupBy ( 'page_title' );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
if ( count ( $option ) > 0 ) {
$this -> addTable ( 'externallinks' , 'el' );
$this -> addSelect ( [ 'el_to' => 'el.el_to' ] );
foreach ( $option as $index => $linkGroup ) {
if ( $index == 0 ) {
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_id=el.el_from AND ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $linkGroup as $link ) {
$ors [] = 'el.el_to LIKE ' . $this -> DB -> addQuotes ( $link );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
$where = 'EXISTS(SELECT el_from FROM ' . $this -> tableNames [ 'externallinks' ] . ' WHERE (' . $this -> tableNames [ 'externallinks' ] . '.el_from=page_id AND ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $linkGroup as $link ) {
$ors [] = $this -> tableNames [ 'externallinks' ] . '.el_to LIKE ' . $this -> DB -> addQuotes ( $link );
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
$where .= '))' ;
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
}
}
/**
* Set SQL for 'maxrevisions' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _maxrevisions ( $option ) {
$this -> addWhere ( " ((SELECT count(rev_aux3.revactor_page) FROM { $this -> tableNames [ 'revision_actor_temp' ] } AS rev_aux3 WHERE rev_aux3.revactor_page = { $this -> tableNames [ 'page' ] } .page_id) <= { $option } ) " );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'minoredits' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _minoredits ( $option ) {
if ( isset ( $option ) && $option == 'exclude' ) {
$this -> addTable ( 'revision' , 'revision' );
$this -> addWhere ( 'revision.rev_minor_edit = 0' );
2020-11-22 20:00:48 +00:00
}
}
/**
* Set SQL for 'minrevisions' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _minrevisions ( $option ) {
$this -> addWhere ( " ((SELECT count(rev_aux2.revactor_page) FROM { $this -> tableNames [ 'revision_actor_temp' ] } AS rev_aux2 WHERE rev_aux2.revactor_page = { $this -> tableNames [ 'page' ] } .page_id) >= { $option } ) " );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'modifiedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _modifiedby ( $option ) {
$this -> addTable ( 'revision_actor_temp' , 'change_rev' );
2020-11-23 00:16:25 +00:00
$user = new \User ;
2020-11-23 03:50:40 +00:00
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' = change_rev.revactor_actor AND change_rev.revactor_page = page_id' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'namespace' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _namespace ( $option ) {
$option === 0 ? ? $option = '0' ;
if ( is_array ( $option ) && count ( $option ) ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
" { $this -> tableNames [ 'pagelinks' ] } .pl_namespace " => $option
]
);
} else {
$this -> addWhere (
[
" { $this -> tableNames [ 'page' ] } .page_namespace " => $option
]
);
}
}
}
/**
* Set SQL for 'notcreatedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notcreatedby ( $option ) {
$this -> addTable ( 'revision' , 'no_creation_rev' );
$this -> addTable ( 'revision_actor_temp' , 'no_creation_rev_actor' );
2020-11-23 00:16:25 +00:00
$user = new \User ;
2020-11-23 03:50:40 +00:00
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' != no_creation_rev_actor.revactor_actor AND no_creation_rev_actor.revactor_page = page_id AND no_creation_rev.rev_parent_id = 0' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'notlastmodifiedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notlastmodifiedby ( $option ) {
$user = new \User ;
$this -> addWhere ( $this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' != (SELECT revactor_actor FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' WHERE ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_page=page_id ORDER BY ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_timestamp DESC LIMIT 1)' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'notmodifiedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notmodifiedby ( $option ) {
$user = new \User ;
$this -> addWhere ( 'NOT EXISTS (SELECT 1 FROM ' . $this -> tableNames [ 'revision_actor_temp' ] . ' WHERE ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_page=page_id AND ' . $this -> tableNames [ 'revision_actor_temp' ] . '.revactor_actor = ' . $this -> DB -> addQuotes ( $user -> newFromName ( $option ) -> getActorId () ) . ' LIMIT 1)' );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'notnamespace' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notnamespace ( $option ) {
if ( is_array ( $option ) && count ( $option ) ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$this -> addNotWhere (
[
" { $this -> tableNames [ 'pagelinks' ] } .pl_namespace " => $option
]
);
} else {
$this -> addNotWhere (
[
" { $this -> tableNames [ 'page' ] } .page_namespace " => $option
]
);
}
}
}
/**
* Set SQL for 'count' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _count ( $option ) {
$this -> setLimit ( $option );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'offset' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _offset ( $option ) {
$this -> setOffset ( $option );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'order' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _order ( $option ) {
$orderMethod = $this -> parameters -> getParameter ( 'ordermethod' );
if ( ! empty ( $orderMethod ) && is_array ( $orderMethod ) && $orderMethod [ 0 ] !== 'none' ) {
if ( $option === 'descending' || $option === 'desc' ) {
$this -> setOrderDir ( 'DESC' );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> setOrderDir ( 'ASC' );
2020-11-22 20:00:48 +00:00
}
}
}
/**
* Set SQL for 'ordercollation' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _ordercollation ( $option ) {
$option = mb_strtolower ( $option );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
$results = $this -> DB -> query ( 'SHOW CHARACTER SET' );
if ( ! $results ) {
2020-11-22 20:00:48 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
while ( $row = $results -> fetchRow () ) {
if ( $option == $row [ 'Default collation' ] ) {
$this -> setCollation ( $option );
2020-11-22 20:00:48 +00:00
break ;
}
}
return true ;
}
/**
* Set SQL for 'ordermethod' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _ordermethod ( $option ) {
2021-05-30 18:33:21 +00:00
$contLang = MediaWikiServices :: getInstance () -> getContentLanguage ();
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'goal' ) == 'categories' ) {
2020-11-22 20:00:48 +00:00
//No order methods for returning categories.
return true ;
}
2021-05-30 18:33:21 +00:00
$namespaces = $contLang -> getNamespaces ();
2020-11-22 20:00:48 +00:00
//$aStrictNs = array_slice((array) Config::getSetting('allowedNamespaces'), 1, count(Config::getSetting('allowedNamespaces')), true);
2021-02-22 23:48:01 +00:00
$namespaces = array_slice ( $namespaces , 3 , count ( $namespaces ), true );
2020-11-22 20:00:48 +00:00
$_namespaceIdToText = " CASE { $this -> tableNames [ 'page' ] } .page_namespace " ;
2021-02-22 23:48:01 +00:00
foreach ( $namespaces as $id => $name ) {
$_namespaceIdToText .= ' WHEN ' . intval ( $id ) . " THEN " . $this -> DB -> addQuotes ( $name . ':' );
2020-11-22 20:00:48 +00:00
}
$_namespaceIdToText .= ' END' ;
$option = ( array ) $option ;
2021-02-22 23:48:01 +00:00
foreach ( $option as $orderMethod ) {
switch ( $orderMethod ) {
2020-11-22 20:00:48 +00:00
case 'category' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'cl_head.cl_to' );
$this -> addSelect ( [ 'cl_head.cl_to' ] ); //Gives category headings in the result.
if ( ( is_array ( $this -> parameters -> getParameter ( 'catheadings' ) ) && in_array ( '' , $this -> parameters -> getParameter ( 'catheadings' ) ) ) || ( is_array ( $this -> parameters -> getParameter ( 'catnotheadings' ) ) && in_array ( '' , $this -> parameters -> getParameter ( 'catnotheadings' ) ) ) ) {
2020-11-22 20:00:48 +00:00
$_clTableName = 'dpl_clview' ;
$_clTableAlias = $_clTableName ;
} else {
$_clTableName = 'categorylinks' ;
$_clTableAlias = 'cl_head' ;
}
2021-02-22 23:48:01 +00:00
$this -> addTable ( $_clTableName , $_clTableAlias );
2020-11-22 20:00:48 +00:00
$this -> addJoin (
$_clTableAlias ,
[
" LEFT OUTER JOIN " ,
" page_id = cl_head.cl_from "
]
);
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> parameters -> getParameter ( 'catheadings' ) ) && count ( $this -> parameters -> getParameter ( 'catheadings' ) ) ) {
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2021-02-22 23:48:01 +00:00
" cl_head.cl_to " => $this -> parameters -> getParameter ( 'catheadings' )
2020-11-22 20:00:48 +00:00
]
);
}
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> parameters -> getParameter ( 'catnotheadings' ) ) && count ( $this -> parameters -> getParameter ( 'catnotheadings' ) ) ) {
2020-11-22 20:00:48 +00:00
$this -> addNotWhere (
[
2021-02-22 23:48:01 +00:00
'cl_head.cl_to' => $this -> parameters -> getParameter ( 'catnotheadings' )
2020-11-22 20:00:48 +00:00
]
);
}
break ;
case 'categoryadd' :
//@TODO: See TODO in __addfirstcategorydate().
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'cl1.cl_timestamp' );
2020-11-22 20:00:48 +00:00
break ;
case 'counter' :
2021-02-22 23:48:01 +00:00
if ( class_exists ( " \\ HitCounters \\ Hooks " ) ) {
2020-11-22 20:00:48 +00:00
//If the "addpagecounter" parameter was not used the table and join need to be added now.
2021-02-22 23:48:01 +00:00
if ( ! array_key_exists ( 'hit_counter' , $this -> tables ) ) {
$this -> addTable ( 'hit_counter' , 'hit_counter' );
2020-11-22 20:00:48 +00:00
2021-02-22 23:48:01 +00:00
if ( ! isset ( $this -> join [ 'hit_counter' ] ) ) {
2020-11-22 20:00:48 +00:00
$this -> addJoin (
'hit_counter' ,
[
" LEFT JOIN " ,
" hit_counter.page_id = " . $this -> tableNames [ 'page' ] . '.page_id'
]
);
}
}
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'hit_counter.page_counter' );
2020-11-22 20:00:48 +00:00
}
break ;
case 'firstedit' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'rev.revactor_timestamp' );
$this -> addTable ( 'revision_actor_temp' , 'rev' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
2020-11-23 03:50:40 +00:00
'rev.revactor_timestamp'
2020-11-22 20:00:48 +00:00
]
);
2021-02-22 23:48:01 +00:00
if ( ! $this -> revisionAuxWhereAdded ) {
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
" { $this -> tableNames [ 'page' ] } .page_id = rev.revactor_page " ,
" rev.revactor_timestamp = (SELECT MIN(rev_aux.revactor_timestamp) FROM { $this -> tableNames [ 'revision_actor_temp' ] } AS rev_aux WHERE rev_aux.revactor_page=rev.revactor_page) "
2020-11-22 20:00:48 +00:00
]
);
}
$this -> revisionAuxWhereAdded = true ;
break ;
case 'lastedit' :
2021-02-22 23:48:01 +00:00
if ( \DynamicPageListHooks :: isLikeIntersection () ) {
$this -> addOrderBy ( 'page_touched' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
" page_touched " => " { $this -> tableNames [ 'page' ] } .page_touched "
]
);
} else {
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'rev.revactor_timestamp' );
$this -> addTable ( 'revision_actor_temp' , 'rev' );
$this -> addSelect ( [ 'rev.revactor_timestamp' ] );
if ( ! $this -> revisionAuxWhereAdded ) {
2020-11-22 20:00:48 +00:00
$this -> addWhere (
[
2020-11-23 03:50:40 +00:00
" { $this -> tableNames [ 'page' ] } .page_id = rev.revactor_page " ,
" rev.revactor_timestamp = (SELECT MAX(rev_aux.revactor_timestamp) FROM { $this -> tableNames [ 'revision_actor_temp' ] } AS rev_aux WHERE rev_aux.revactor_page = rev.revactor_page) "
2020-11-22 20:00:48 +00:00
]
);
}
$this -> revisionAuxWhereAdded = true ;
}
break ;
case 'pagesel' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'sortkey' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'sortkey' => 'CONCAT(pl.pl_namespace, pl.pl_title) ' . $this -> getCollateSQL ()
]
);
break ;
case 'pagetouched' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'page_touched' );
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
" page_touched " => " { $this -> tableNames [ 'page' ] } .page_touched "
]
);
break ;
case 'size' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'page_len' );
2020-11-22 20:00:48 +00:00
break ;
case 'sortkey' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'sortkey' );
2020-11-22 20:00:48 +00:00
// If cl_sortkey is null (uncategorized page), generate a sortkey in the usual way (full page name, underscores replaced with spaces).
// UTF-8 created problems with non-utf-8 MySQL databases
$replaceConcat = " REPLACE(CONCAT( { $_namespaceIdToText } , " . $this -> tableNames [ 'page' ] . " .page_title), '_', ' ') " ;
2021-02-22 23:48:01 +00:00
$category = ( array ) $this -> parameters -> getParameter ( 'category' );
$notCategory = ( array ) $this -> parameters -> getParameter ( 'notcategory' );
if ( count ( $category ) + count ( $notCategory ) > 0 ) {
if ( in_array ( 'category' , $this -> parameters -> getParameter ( 'ordermethod' ) ) ) {
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'sortkey' => " IFNULL(cl_head.cl_sortkey, { $replaceConcat } ) " . $this -> getCollateSQL ()
]
);
} else {
//This runs on the assumption that at least one category parameter was used and that numbering starts at 1.
$this -> addSelect (
[
'sortkey' => " IFNULL(cl1.cl_sortkey, { $replaceConcat } ) " . $this -> getCollateSQL ()
]
);
}
} else {
$this -> addSelect (
[
'sortkey' => $replaceConcat . $this -> getCollateSQL ()
]
);
}
break ;
case 'titlewithoutnamespace' :
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
$this -> addOrderBy ( " pl_title " );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( " page_title " );
2020-11-22 20:00:48 +00:00
}
$this -> addSelect (
[
'sortkey' => " { $this -> tableNames [ 'page' ] } .page_title " . $this -> getCollateSQL ()
]
);
break ;
case 'title' :
2021-02-22 23:48:01 +00:00
$this -> addOrderBy ( 'sortkey' );
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$this -> addSelect (
[
'sortkey' => " REPLACE(CONCAT(IF(pl_namespace =0, '', CONCAT( " . $_namespaceIdToText . " , ':')), pl_title), '_', ' ') " . $this -> getCollateSQL ()
]
);
} else {
//Generate sortkey like for category links. UTF-8 created problems with non-utf-8 MySQL databases.
$this -> addSelect (
[
'sortkey' => " REPLACE(CONCAT(IF( " . $this -> tableNames [ 'page' ] . " .page_namespace = 0, '', CONCAT( " . $_namespaceIdToText . " , ':')), " . $this -> tableNames [ 'page' ] . " .page_title), '_', ' ') " . $this -> getCollateSQL ()
]
);
}
break ;
case 'user' :
2021-02-22 23:48:01 +00:00
$user = new \User ;
2020-11-23 03:50:40 +00:00
$this -> addOrderBy ( $user -> newFromName ( 'rev.revactor_actor' ) -> getActorId () );
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'revision_actor_temp' , 'rev' );
$this -> _adduser ( null , 'rev' );
2020-11-22 20:00:48 +00:00
break ;
case 'none' :
break ;
}
}
}
/**
* Set SQL for 'redirects' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _redirects ( $option ) {
if ( ! $this -> parameters -> getParameter ( 'openreferences' ) ) {
switch ( $option ) {
2020-11-22 20:00:48 +00:00
case 'only' :
$this -> addWhere (
[
$this -> tableNames [ 'page' ] . " .page_is_redirect " => 1
]
);
break ;
case 'exclude' :
$this -> addWhere (
[
$this -> tableNames [ 'page' ] . " .page_is_redirect " => 0
]
);
break ;
}
}
}
/**
* Set SQL for 'stablepages' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _stablepages ( $option ) {
if ( function_exists ( 'efLoadFlaggedRevs' ) ) {
2020-11-22 20:00:48 +00:00
//Do not add this again if 'qualitypages' has already added it.
2021-02-22 23:48:01 +00:00
if ( ! $this -> parametersProcessed [ 'qualitypages' ] ) {
2020-11-22 20:00:48 +00:00
$this -> addJoin (
'flaggedpages' ,
[
" LEFT JOIN " ,
" page_id = fp_page_id "
]
);
}
2021-02-22 23:48:01 +00:00
switch ( $option ) {
2020-11-22 20:00:48 +00:00
case 'only' :
$this -> addWhere (
[
'fp_stable IS NOT NULL'
]
);
break ;
case 'exclude' :
$this -> addWhere (
[
'fp_stable' => null
]
);
break ;
}
}
}
/**
* Set SQL for 'qualitypages' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _qualitypages ( $option ) {
if ( function_exists ( 'efLoadFlaggedRevs' ) ) {
2020-11-22 20:00:48 +00:00
//Do not add this again if 'stablepages' has already added it.
2021-02-22 23:48:01 +00:00
if ( ! $this -> parametersProcessed [ 'stablepages' ] ) {
2020-11-22 20:00:48 +00:00
$this -> addJoin (
'flaggedpages' ,
[
" LEFT JOIN " ,
" page_id = fp_page_id "
]
);
}
2021-02-22 23:48:01 +00:00
switch ( $option ) {
2020-11-22 20:00:48 +00:00
case 'only' :
2021-02-22 23:48:01 +00:00
$this -> addWhere ( 'fp_quality >= 1' );
2020-11-22 20:00:48 +00:00
break ;
case 'exclude' :
2021-02-22 23:48:01 +00:00
$this -> addWhere ( 'fp_quality = 0' );
2020-11-22 20:00:48 +00:00
break ;
}
}
}
/**
* Set SQL for 'title' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _title ( $option ) {
2020-11-22 20:00:48 +00:00
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $comparisonType => $titles ) {
foreach ( $titles as $title ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or = " LOWER(CAST(pl_title AS char)) { $comparisonType } " . strtolower ( $this -> DB -> addQuotes ( $title ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or = " pl_title { $comparisonType } " . $this -> DB -> addQuotes ( $title );
2020-11-22 20:00:48 +00:00
}
} else {
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or = " LOWER(CAST( { $this -> tableNames [ 'page' ] } .page_title AS char)) { $comparisonType } " . strtolower ( $this -> DB -> addQuotes ( $title ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or = " { $this -> tableNames [ 'page' ] } .page_title { $comparisonType } " . $this -> DB -> addQuotes ( $title );
2020-11-22 20:00:48 +00:00
}
}
$ors [] = $_or ;
}
}
2021-02-22 23:48:01 +00:00
$where = '(' . implode ( ' OR ' , $ors ) . ')' ;
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'nottitle' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _nottitle ( $option ) {
2020-11-22 20:00:48 +00:00
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $comparisonType => $titles ) {
foreach ( $titles as $title ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or = " LOWER(CAST(pl_title AS char)) { $comparisonType } " . strtolower ( $this -> DB -> addQuotes ( $title ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or = " pl_title { $comparisonType } " . $this -> DB -> addQuotes ( $title );
2020-11-22 20:00:48 +00:00
}
} else {
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or = " LOWER(CAST( { $this -> tableNames [ 'page' ] } .page_title AS char)) { $comparisonType } " . strtolower ( $this -> DB -> addQuotes ( $title ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or = " { $this -> tableNames [ 'page' ] } .page_title { $comparisonType } " . $this -> DB -> addQuotes ( $title );
2020-11-22 20:00:48 +00:00
}
}
$ors [] = $_or ;
}
}
2021-02-22 23:48:01 +00:00
$where = 'NOT (' . implode ( ' OR ' , $ors ) . ')' ;
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'titlegt' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _titlegt ( $option ) {
2020-11-22 20:00:48 +00:00
$where = '(' ;
2021-02-22 23:48:01 +00:00
if ( substr ( $option , 0 , 2 ) == '=_' ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
$where .= 'pl_title >= ' . $this -> DB -> addQuotes ( substr ( $sTitleGE , 2 ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$where .= $this -> tableNames [ 'page' ] . '.page_title >= ' . $this -> DB -> addQuotes ( substr ( $option , 2 ) );
2020-11-22 20:00:48 +00:00
}
} else {
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
$where .= 'pl_title > ' . $this -> DB -> addQuotes ( $option );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$where .= $this -> tableNames [ 'page' ] . '.page_title > ' . $this -> DB -> addQuotes ( $option );
2020-11-22 20:00:48 +00:00
}
}
$where .= ')' ;
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'titlelt' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _titlelt ( $option ) {
2020-11-22 20:00:48 +00:00
$where = '(' ;
2021-02-22 23:48:01 +00:00
if ( substr ( $option , 0 , 2 ) == '=_' ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
$where .= 'pl_title <= ' . $this -> DB -> addQuotes ( substr ( $option , 2 ) );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$where .= $this -> tableNames [ 'page' ] . '.page_title <= ' . $this -> DB -> addQuotes ( substr ( $option , 2 ) );
2020-11-22 20:00:48 +00:00
}
} else {
2021-02-22 23:48:01 +00:00
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
$where .= 'pl_title < ' . $this -> DB -> addQuotes ( $option );
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$where .= $this -> tableNames [ 'page' ] . '.page_title < ' . $this -> DB -> addQuotes ( $option );
2020-11-22 20:00:48 +00:00
}
}
$where .= ')' ;
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'usedby' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _usedby ( $option ) {
if ( $this -> parameters -> getParameter ( 'openreferences' ) ) {
2020-11-22 20:00:48 +00:00
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$ors [] = 'tpl_from = ' . intval ( $link -> getArticleID () );
2020-11-22 20:00:48 +00:00
}
}
2021-02-22 23:48:01 +00:00
$where = '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$this -> addTable ( 'templatelinks' , 'tpl' );
$this -> addTable ( 'page' , 'tplsrc' );
$this -> addSelect ( [ 'tpl_sel_title' => 'tplsrc.page_title' , 'tpl_sel_ns' => 'tplsrc.page_namespace' ] );
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_namespace = tpl.tl_namespace AND ' .
$this -> tableNames [ 'page' ] . '.page_title = tpl.tl_title AND tplsrc.page_id = tpl.tl_from AND ' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$ors [] = 'tpl.tl_from = ' . intval ( $link -> getArticleID () );
2020-11-22 20:00:48 +00:00
}
}
2021-02-22 23:48:01 +00:00
$where .= '(' . implode ( ' OR ' , $ors ) . ')' ;
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'uses' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _uses ( $option ) {
$this -> addTable ( 'templatelinks' , 'tl' );
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_id=tl.tl_from AND (' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$_or = '(tl.tl_namespace=' . intval ( $link -> getNamespace () );
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or .= " AND LOWER(CAST(tl.tl_title AS char))=LOWER( " . $this -> DB -> addQuotes ( $link -> getDbKey () ) . '))' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or .= " AND tl.tl_title= " . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
}
$ors [] = $_or ;
}
}
2021-02-22 23:48:01 +00:00
$where .= implode ( ' OR ' , $ors ) . ')' ;
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
/**
* Set SQL for 'notuses' parameter .
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:00:48 +00:00
* @ param mixed Parameter Option
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function _notuses ( $option ) {
if ( count ( $option ) > 0 ) {
2020-11-22 20:00:48 +00:00
$where = $this -> tableNames [ 'page' ] . '.page_id NOT IN (SELECT ' . $this -> tableNames [ 'templatelinks' ] . '.tl_from FROM ' . $this -> tableNames [ 'templatelinks' ] . ' WHERE (' ;
$ors = [];
2021-02-22 23:48:01 +00:00
foreach ( $option as $linkGroup ) {
foreach ( $linkGroup as $link ) {
$_or = '(' . $this -> tableNames [ 'templatelinks' ] . '.tl_namespace=' . intval ( $link -> getNamespace () );
if ( $this -> parameters -> getParameter ( 'ignorecase' ) ) {
$_or .= ' AND LOWER(CAST(' . $this -> tableNames [ 'templatelinks' ] . '.tl_title AS char))=LOWER(' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . '))' ;
2020-11-22 20:00:48 +00:00
} else {
2021-02-22 23:48:01 +00:00
$_or .= ' AND ' . $this -> tableNames [ 'templatelinks' ] . '.tl_title=' . $this -> DB -> addQuotes ( $link -> getDbKey () ) . ')' ;
2020-11-22 20:00:48 +00:00
}
$ors [] = $_or ;
}
}
2021-02-22 23:48:01 +00:00
$where .= implode ( ' OR ' , $ors ) . '))' ;
2020-11-22 20:00:48 +00:00
}
2021-02-22 23:48:01 +00:00
$this -> addWhere ( $where );
2020-11-22 20:00:48 +00:00
}
}