2020-11-22 19:56:23 +00:00
< ? php
/**
*
* @ file
* @ ingroup Extensions
2021-02-23 00:17:04 +00:00
* @ link http :// www . mediawiki . org / wiki / Extension : DynamicPageList3 Documentation
* @ author n : en : User : IlyaHaykinson
* @ author n : en : User : Amgine
* @ author w : de : Benutzer : Unendlich
* @ author m : User : Dangerman < cyril . dangerville @ gmail . com >
* @ author m : User : Algorithmix < gero . scholz @ gmx . de >
* @ license GPL - 2.0 - or - later
2020-11-22 19:56:23 +00:00
*
*/
class DynamicPageListHooks {
// FATAL
const FATAL_WRONGNS = 1001 ; // $1: 'namespace' or 'notnamespace'
// $2: wrong parameter given by user
// $3: list of possible titles of namespaces (except pseudo-namespaces: Media, Special)
const FATAL_WRONGLINKSTO = 1002 ; // $1: linksto'
// $2: the wrong parameter given by user
const FATAL_TOOMANYCATS = 1003 ; // $1: max number of categories that can be included
const FATAL_TOOFEWCATS = 1004 ; // $1: min number of categories that have to be included
const FATAL_NOSELECTION = 1005 ;
const FATAL_CATDATEBUTNOINCLUDEDCATS = 1006 ;
const FATAL_CATDATEBUTMORETHAN1CAT = 1007 ;
const FATAL_MORETHAN1TYPEOFDATE = 1008 ;
const FATAL_WRONGORDERMETHOD = 1009 ; // $1: param=val that is possible only with $1 as last 'ordermethod' parameter
// $2: last 'ordermethod' parameter required for $0
const FATAL_DOMINANTSECTIONRANGE = 1010 ; // $1: the number of arguments in includepage
const FATAL_OPENREFERENCES = 1012 ;
const FATAL_MISSINGPARAMFUNCTION = 1022 ;
const FATAL_NOTPROTECTED = 1023 ;
const FATAL_SQLBUILDERROR = 1024 ;
// ERROR
// WARN
const WARN_UNKNOWNPARAM = 2013 ; // $1: unknown parameter given by user
// $2: list of DPL available parameters separated by ', '
const WARN_PARAMNOOPTION = 2022 ; // $1: Parameter given by user
const WARN_WRONGPARAM = 2014 ; // $3: list of valid param values separated by ' | '
const WARN_WRONGPARAM_INT = 2015 ; // $1: param name
// $2: wrong param value given by user
// $3: default param value used instead by program
const WARN_NORESULTS = 2016 ;
const WARN_CATOUTPUTBUTWRONGPARAMS = 2017 ;
const WARN_HEADINGBUTSIMPLEORDERMETHOD = 2018 ; // $1: 'headingmode' value given by user
// $2: value used instead by program (which means no heading)
const WARN_DEBUGPARAMNOTFIRST = 2019 ; // $1: 'log' value
const WARN_TRANSCLUSIONLOOP = 2020 ; // $1: title of page that creates an infinite transclusion loop
// INFO
// DEBUG
const DEBUG_QUERY = 3021 ; // $1: SQL query executed to generate the dynamic page list
// TRACE
// Output formatting
// $1: number of articles
2021-02-22 23:48:01 +00:00
public static $fixedCategories = [];
2020-11-22 19:56:23 +00:00
public static $createdLinks ; // the links created by DPL are collected here;
// they can be removed during the final ouput
// phase of the MediaWiki parser
/**
* DPL acting like Extension : Intersection
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
private static $likeIntersection = false ;
2020-11-22 19:56:23 +00:00
/**
* Debugging Level
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
private static $debugLevel = 0 ;
2020-11-22 19:56:23 +00:00
/**
* Handle special on extension registration bits .
*
2021-02-23 00:17:04 +00:00
* @ return void
2020-11-22 19:56:23 +00:00
*/
public static function onRegistration () {
2021-02-22 23:48:01 +00:00
if ( ! defined ( 'DPL_VERSION' ) ) {
define ( 'DPL_VERSION' , '3.3.4' );
2020-11-22 19:56:23 +00:00
}
}
/**
* Sets up this extension ' s parser functions .
*
2021-02-23 00:17:04 +00:00
* @ param object Parser object passed as a reference .
* @ return bool true
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function onParserFirstCallInit ( Parser & $parser ) {
2020-11-22 19:56:23 +00:00
self :: init ();
//DPL offers the same functionality as Intersection. So we register the <DynamicPageList> tag in case LabeledSection Extension is not installed so that the section markers are removed.
2021-02-22 23:48:01 +00:00
if ( \DPL\Config :: getSetting ( 'handleSectionTag' ) ) {
$parser -> setHook ( 'section' , [ __CLASS__ , 'dplTag' ] );
2020-11-22 19:56:23 +00:00
}
2021-02-23 00:17:04 +00:00
2021-02-22 23:48:01 +00:00
$parser -> setHook ( 'DPL' , [ __CLASS__ , 'dplTag' ] );
$parser -> setHook ( 'DynamicPageList' , [ __CLASS__ , 'intersectionTag' ] );
2020-11-22 19:56:23 +00:00
2021-02-22 23:48:01 +00:00
$parser -> setFunctionHook ( 'dpl' , [ __CLASS__ , 'dplParserFunction' ] );
$parser -> setFunctionHook ( 'dplnum' , [ __CLASS__ , 'dplNumParserFunction' ] );
$parser -> setFunctionHook ( 'dplvar' , [ __CLASS__ , 'dplVarParserFunction' ] );
$parser -> setFunctionHook ( 'dplreplace' , [ __CLASS__ , 'dplReplaceParserFunction' ] );
$parser -> setFunctionHook ( 'dplchapter' , [ __CLASS__ , 'dplChapterParserFunction' ] );
$parser -> setFunctionHook ( 'dplmatrix' , [ __CLASS__ , 'dplMatrixParserFunction' ] );
2020-11-22 19:56:23 +00:00
return true ;
}
/**
* Sets up this extension ' s parser functions for migration from Intersection .
*
2021-02-23 00:17:04 +00:00
* @ param object Parser object passed as a reference .
* @ returnbool true
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function setupMigration ( Parser & $parser ) {
$parser -> setHook ( 'Intersection' , [ __CLASS__ , 'intersectionTag' ] );
$parser -> addTrackingCategory ( 'dpl-intersection-tracking-category' );
2020-11-22 19:56:23 +00:00
self :: init ();
return true ;
}
/**
* Common initializer for usage from parser entry points .
*
2021-02-22 23:48:01 +00:00
* @ private
2021-02-23 00:17:04 +00:00
* @ return void
2020-11-22 19:56:23 +00:00
*/
private static function init () {
\DPL\Config :: init ();
2021-02-22 23:48:01 +00:00
if ( ! isset ( self :: $createdLinks ) ) {
2020-11-22 19:56:23 +00:00
self :: $createdLinks = [
2021-02-18 21:47:20 +00:00
'resetLinks' => false ,
'resetTemplates' => false ,
'resetCategories' => false ,
'resetImages' => false ,
'resetdone' => false ,
'elimdone' => false
2020-11-22 19:56:23 +00:00
];
}
}
/**
* Set to behave like intersection .
*
2021-02-22 23:48:01 +00:00
* @ private
2021-02-23 00:17:04 +00:00
* @ param bool Behave Like Intersection
* @ return void
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
private static function setLikeIntersection ( $mode = false ) {
2020-11-22 19:56:23 +00:00
self :: $likeIntersection = $mode ;
}
/**
* Is like intersection ?
*
2021-02-23 00:17:04 +00:00
* @ return bool Behaving Like Intersection
2020-11-22 19:56:23 +00:00
*/
public static function isLikeIntersection () {
return ( bool ) self :: $likeIntersection ;
}
/**
* Tag < section > entry point .
*
2021-02-23 00:17:04 +00:00
* @ param string Raw User Input
* @ param array Arguments on the tag .
* @ param object Parser object .
* @ param object PPFrame object .
* @ return string HTML
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function intersectionTag ( $input , array $args , Parser $parser , PPFrame $frame ) {
self :: setLikeIntersection ( true );
return self :: executeTag ( $input , $args , $parser , $frame );
2020-11-22 19:56:23 +00:00
}
/**
* Tag < dpl > entry point .
*
2021-02-23 00:17:04 +00:00
* @ param string Raw User Input
* @ param array Arguments on the tag .
* @ param object Parser object .
* @ param object PPFrame object .
* @ return string HTML
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function dplTag ( $input , array $args , Parser $parser , PPFrame $frame ) {
self :: setLikeIntersection ( false );
$parser -> addTrackingCategory ( 'dpl-tag-tracking-category' );
return self :: executeTag ( $input , $args , $parser , $frame );
2020-11-22 19:56:23 +00:00
}
/**
* The callback function wrapper for converting the input text to HTML output
*
2021-02-23 00:17:04 +00:00
* @ param string Raw User Input
* @ param array Arguments on the tag . ( While not used , it is left here for future compatibility . )
* @ param object Parser object .
* @ param object PPFrame object .
* @ return string HTML
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
private static function executeTag ( $input , array $args , Parser $parser , PPFrame $frame ) {
2020-11-22 19:56:23 +00:00
// entry point for user tag <dpl> or <DynamicPageList>
// create list and do a recursive parse of the output
$parse = new \DPL\Parse ();
2021-02-22 23:48:01 +00:00
if ( \DPL\Config :: getSetting ( 'recursiveTagParse' ) ) {
$input = $parser -> recursiveTagParse ( $input , $frame );
2020-11-22 19:56:23 +00:00
}
2021-02-23 00:17:04 +00:00
2021-02-22 23:48:01 +00:00
$text = $parse -> parse ( $input , $parser , $reset , $eliminate , true );
2020-11-22 19:56:23 +00:00
2021-02-22 23:48:01 +00:00
if ( isset ( $reset [ 'templates' ] ) && $reset [ 'templates' ] ) { // we can remove the templates by save/restore
2020-11-22 19:56:23 +00:00
$saveTemplates = $parser -> mOutput -> mTemplates ;
}
2021-02-22 23:48:01 +00:00
if ( isset ( $reset [ 'categories' ] ) && $reset [ 'categories' ] ) { // we can remove the categories by save/restore
2020-11-22 19:56:23 +00:00
$saveCategories = $parser -> mOutput -> mCategories ;
}
2021-02-22 23:48:01 +00:00
if ( isset ( $reset [ 'images' ] ) && $reset [ 'images' ] ) { // we can remove the images by save/restore
2020-11-22 19:56:23 +00:00
$saveImages = $parser -> mOutput -> mImages ;
}
2021-02-22 23:48:01 +00:00
$parsedDPL = $parser -> recursiveTagParse ( $text );
if ( isset ( $reset [ 'templates' ] ) && $reset [ 'templates' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mTemplates = $saveTemplates ;
}
2021-02-22 23:48:01 +00:00
if ( isset ( $reset [ 'categories' ] ) && $reset [ 'categories' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mCategories = $saveCategories ;
}
2021-02-22 23:48:01 +00:00
if ( isset ( $reset [ 'images' ] ) && $reset [ 'images' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mImages = $saveImages ;
}
return $parsedDPL ;
}
/**
* The #dpl parser tag entry point.
*
2021-02-23 00:17:04 +00:00
* @ param object Parser object passed as a reference .
* @ return string Wiki Text
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function dplParserFunction ( & $parser ) {
self :: setLikeIntersection ( false );
2020-11-22 19:56:23 +00:00
2021-02-22 23:48:01 +00:00
$parser -> addTrackingCategory ( 'dpl-parserfunc-tracking-category' );
2020-11-22 19:56:23 +00:00
// callback for the parser function {{#dpl: or {{DynamicPageList::
$input = " " ;
$numargs = func_num_args ();
2021-02-22 23:48:01 +00:00
if ( $numargs < 2 ) {
2020-11-22 19:56:23 +00:00
$input = " #dpl: no arguments specified " ;
2021-02-22 23:48:01 +00:00
return str_replace ( '§' , '<' , '§pre>§nowiki>' . $input . '§/nowiki>§/pre>' );
2020-11-22 19:56:23 +00:00
}
// fetch all user-provided arguments (skipping $parser)
$arg_list = func_get_args ();
2021-02-22 23:48:01 +00:00
for ( $i = 1 ; $i < $numargs ; $i ++ ) {
2020-11-22 19:56:23 +00:00
$p1 = $arg_list [ $i ];
2021-02-22 23:48:01 +00:00
$input .= str_replace ( " \n " , " " , $p1 ) . " \n " ;
2020-11-22 19:56:23 +00:00
}
$parse = new \DPL\Parse ();
2021-02-22 23:48:01 +00:00
$dplresult = $parse -> parse ( $input , $parser , $reset , $eliminate , false );
2020-11-22 19:56:23 +00:00
return [ // parser needs to be coaxed to do further recursive processing
2021-02-22 23:48:01 +00:00
$parser -> getPreprocessor () -> preprocessToObj ( $dplresult , Parser :: PTD_FOR_INCLUSION ),
2020-11-22 19:56:23 +00:00
'isLocalObj' => true ,
'title' => $parser -> getTitle ()
];
}
/**
* The #dplnum parser tag entry point.
* From the old documentation : " Tries to guess a number that is buried in the text. Uses a set of heuristic rules which may work or not. The idea is to extract the number so that it can be used as a sorting value in the column of a DPL table output. "
*
2021-02-23 00:17:04 +00:00
* @ param object Parser object passed as a reference .
* @ return string Wiki Text
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function dplNumParserFunction ( & $parser , $text = '' ) {
$parser -> addTrackingCategory ( 'dplnum-parserfunc-tracking-category' );
$num = str_replace ( ' ' , ' ' , $text );
$num = str_replace ( ' ' , ' ' , $text );
$num = preg_replace ( '/([0-9])([.])([0-9][0-9]?[^0-9,])/' , '\1,\3' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9][0-9][0-9])\s*Mrd/' , '\1\2 000000 ' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9][0-9])\s*Mrd/' , '\1\2 0000000 ' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9])\s*Mrd/' , '\1\2 00000000 ' , $num );
$num = preg_replace ( '/\s*Mrd/' , '000000000 ' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9][0-9][0-9])\s*Mio/' , '\1\2 000 ' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9][0-9])\s*Mio/' , '\1\2 0000 ' , $num );
$num = preg_replace ( '/([0-9.]+),([0-9])\s*Mio/' , '\1\2 00000 ' , $num );
$num = preg_replace ( '/\s*Mio/' , '000000 ' , $num );
$num = preg_replace ( '/[. ]/' , '' , $num );
$num = preg_replace ( '/^[^0-9]+/' , '' , $num );
$num = preg_replace ( '/[^0-9].*/' , '' , $num );
2020-11-22 19:56:23 +00:00
return $num ;
}
2021-02-22 23:48:01 +00:00
public static function dplVarParserFunction ( & $parser , $cmd ) {
$parser -> addTrackingCategory ( 'dplvar-parserfunc-tracking-category' );
2020-11-22 19:56:23 +00:00
$args = func_get_args ();
2021-02-22 23:48:01 +00:00
if ( $cmd == 'set' ) {
return \DPL\Variables :: setVar ( $args );
} elseif ( $cmd == 'default' ) {
return \DPL\Variables :: setVarDefault ( $args );
2020-11-22 19:56:23 +00:00
}
2021-02-22 23:48:01 +00:00
return \DPL\Variables :: getVar ( $cmd );
2020-11-22 19:56:23 +00:00
}
2021-02-22 23:48:01 +00:00
private static function isRegexp ( $needle ) {
if ( strlen ( $needle ) < 3 ) {
2020-11-22 19:56:23 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
if ( ctype_alnum ( $needle [ 0 ] ) ) {
2020-11-22 19:56:23 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
$nettoNeedle = preg_replace ( '/[ismu]*$/' , '' , $needle );
if ( strlen ( $nettoNeedle ) < 2 ) {
2020-11-22 19:56:23 +00:00
return false ;
}
2021-02-22 23:48:01 +00:00
if ( $needle [ 0 ] == $nettoNeedle [ strlen ( $nettoNeedle ) - 1 ] ) {
2020-11-22 19:56:23 +00:00
return true ;
}
return false ;
}
2021-02-22 23:48:01 +00:00
public static function dplReplaceParserFunction ( & $parser , $text , $pat = '' , $repl = '' ) {
$parser -> addTrackingCategory ( 'dplreplace-parserfunc-tracking-category' );
if ( $text == '' || $pat == '' ) {
2020-11-22 19:56:23 +00:00
return '' ;
}
# convert \n to a real newline character
2021-02-22 23:48:01 +00:00
$repl = str_replace ( '\n' , " \n " , $repl );
2020-11-22 19:56:23 +00:00
# replace
2021-02-22 23:48:01 +00:00
if ( ! self :: isRegexp ( $pat ) ) {
$pat = '`' . str_replace ( '`' , '\`' , $pat ) . '`' ;
2020-11-22 19:56:23 +00:00
}
2021-02-22 23:48:01 +00:00
return @ preg_replace ( $pat , $repl , $text );
2020-11-22 19:56:23 +00:00
}
2021-02-22 23:48:01 +00:00
public static function dplChapterParserFunction ( & $parser , $text = '' , $heading = ' ' , $maxLength = - 1 , $page = '?page?' , $link = 'default' , $trim = false ) {
$parser -> addTrackingCategory ( 'dplchapter-parserfunc-tracking-category' );
$output = \DPL\LST :: extractHeadingFromText ( $parser , $page , '?title?' , $text , $heading , '' , $sectionHeading , true , $maxLength , $link , $trim );
2020-11-22 19:56:23 +00:00
return $output [ 0 ];
}
2021-02-22 23:48:01 +00:00
public static function dplMatrixParserFunction ( & $parser , $name = '' , $yes = '' , $no = '' , $flip = '' , $matrix = '' ) {
$parser -> addTrackingCategory ( 'dplmatrix-parserfunc-tracking-category' );
$lines = explode ( " \n " , $matrix );
2020-11-22 19:56:23 +00:00
$m = [];
$sources = [];
$targets = [];
$from = '' ;
$to = '' ;
2021-02-22 23:48:01 +00:00
if ( $flip == '' | $flip == 'normal' ) {
2020-11-22 19:56:23 +00:00
$flip = false ;
} else {
$flip = true ;
}
2021-02-22 23:48:01 +00:00
if ( $name == '' ) {
2020-11-22 19:56:23 +00:00
$name = ' ' ;
}
2021-02-22 23:48:01 +00:00
if ( $yes == '' ) {
2020-11-22 19:56:23 +00:00
$yes = ' x ' ;
}
2021-02-22 23:48:01 +00:00
if ( $no == '' ) {
2020-11-22 19:56:23 +00:00
$no = ' ' ;
}
2021-02-22 23:48:01 +00:00
if ( $no [ 0 ] == '-' ) {
2020-11-22 19:56:23 +00:00
$no = " $no " ;
}
2021-02-22 23:48:01 +00:00
foreach ( $lines as $line ) {
if ( strlen ( $line ) <= 0 ) {
2020-11-22 19:56:23 +00:00
continue ;
}
2021-02-23 00:17:04 +00:00
2021-02-22 23:48:01 +00:00
if ( $line [ 0 ] != ' ' ) {
$from = preg_split ( ' *\~\~ *' , trim ( $line ), 2 );
if ( ! array_key_exists ( $from [ 0 ], $sources ) ) {
if ( count ( $from ) < 2 || $from [ 1 ] == '' ) {
2020-11-22 19:56:23 +00:00
$sources [ $from [ 0 ]] = $from [ 0 ];
} else {
$sources [ $from [ 0 ]] = $from [ 1 ];
}
$m [ $from [ 0 ]] = [];
}
2021-02-22 23:48:01 +00:00
} elseif ( trim ( $line ) != '' ) {
$to = preg_split ( ' *\~\~ *' , trim ( $line ), 2 );
if ( count ( $to ) < 2 || $to [ 1 ] == '' ) {
2020-11-22 19:56:23 +00:00
$targets [ $to [ 0 ]] = $to [ 0 ];
} else {
$targets [ $to [ 0 ]] = $to [ 1 ];
}
$m [ $from [ 0 ]][ $to [ 0 ]] = true ;
}
}
2021-02-22 23:48:01 +00:00
ksort ( $targets );
2020-11-22 19:56:23 +00:00
$header = " \n " ;
2021-02-22 23:48:01 +00:00
if ( $flip ) {
foreach ( $sources as $from => $fromName ) {
2020-11-22 19:56:23 +00:00
$header .= " ![[ $from | " . $fromName . " ]] \n " ;
}
2021-02-22 23:48:01 +00:00
foreach ( $targets as $to => $toName ) {
2020-11-22 19:56:23 +00:00
$targets [ $to ] = " [[ $to | $toName ]] " ;
2021-02-22 23:48:01 +00:00
foreach ( $sources as $from => $fromName ) {
if ( array_key_exists ( $to , $m [ $from ] ) ) {
2020-11-22 19:56:23 +00:00
$targets [ $to ] .= " \n | $yes " ;
} else {
$targets [ $to ] .= " \n | $no " ;
}
}
$targets [ $to ] .= " \n |-- \n " ;
}
2021-02-22 23:48:01 +00:00
return " { |class=dplmatrix \n | $name " . " \n " . $header . " |-- \n ! " . implode ( " \n ! " , $targets ) . " \n |} " ;
2020-11-22 19:56:23 +00:00
} else {
2021-02-22 23:48:01 +00:00
foreach ( $targets as $to => $toName ) {
2020-11-22 19:56:23 +00:00
$header .= " ![[ $to | " . $toName . " ]] \n " ;
}
2021-02-22 23:48:01 +00:00
foreach ( $sources as $from => $fromName ) {
2020-11-22 19:56:23 +00:00
$sources [ $from ] = " [[ $from | $fromName ]] " ;
2021-02-22 23:48:01 +00:00
foreach ( $targets as $to => $toName ) {
if ( array_key_exists ( $to , $m [ $from ] ) ) {
2020-11-22 19:56:23 +00:00
$sources [ $from ] .= " \n | $yes " ;
} else {
$sources [ $from ] .= " \n | $no " ;
}
}
$sources [ $from ] .= " \n |-- \n " ;
}
2021-02-22 23:48:01 +00:00
return " { |class=dplmatrix \n | $name " . " \n " . $header . " |-- \n ! " . implode ( " \n ! " , $sources ) . " \n |} " ;
2020-11-22 19:56:23 +00:00
}
}
2021-02-22 23:48:01 +00:00
private static function dumpParsedRefs ( $parser , $label ) {
2021-02-23 00:17:04 +00:00
// if (!preg_match("/Query Q/",$parser->mTitle->getText())) return '';
2020-11-22 19:56:23 +00:00
echo '<pre>parser mLinks: ' ;
ob_start ();
2021-02-22 23:48:01 +00:00
var_dump ( $parser -> mOutput -> mLinks );
2020-11-22 19:56:23 +00:00
$a = ob_get_contents ();
ob_end_clean ();
2021-02-22 23:48:01 +00:00
echo htmlspecialchars ( $a , ENT_QUOTES );
2020-11-22 19:56:23 +00:00
echo '</pre>' ;
echo '<pre>parser mTemplates: ' ;
ob_start ();
2021-02-22 23:48:01 +00:00
var_dump ( $parser -> mOutput -> mTemplates );
2020-11-22 19:56:23 +00:00
$a = ob_get_contents ();
ob_end_clean ();
2021-02-22 23:48:01 +00:00
echo htmlspecialchars ( $a , ENT_QUOTES );
2020-11-22 19:56:23 +00:00
echo '</pre>' ;
}
2021-02-23 00:17:04 +00:00
// remove section markers in case the LabeledSectionTransclusion extension is not installed.
2021-02-22 23:48:01 +00:00
public static function removeSectionMarkers ( $in , $assocArgs = [], $parser = null ) {
2020-11-22 19:56:23 +00:00
return '' ;
}
2021-02-22 23:48:01 +00:00
public static function fixCategory ( $cat ) {
if ( $cat != '' ) {
2020-11-22 19:56:23 +00:00
self :: $fixedCategories [ $cat ] = 1 ;
}
}
/**
* Set Debugging Level
*
* @ access public
* @ param integer Debug Level
* @ return void
*/
2021-02-22 23:48:01 +00:00
public static function setDebugLevel ( $level ) {
self :: $debugLevel = intval ( $level );
2020-11-22 19:56:23 +00:00
}
/**
* Return Debugging Level
*
* @ access public
* @ return void
*/
public static function getDebugLevel () {
return self :: $debugLevel ;
}
// reset everything; some categories may have been fixed, however via fixcategory=
2021-02-22 23:48:01 +00:00
public static function endReset ( & $parser , $text ) {
if ( ! self :: $createdLinks [ 'resetdone' ] ) {
2020-11-22 19:56:23 +00:00
self :: $createdLinks [ 'resetdone' ] = true ;
2021-02-22 23:48:01 +00:00
foreach ( $parser -> mOutput -> mCategories as $key => $val ) {
if ( array_key_exists ( $key , self :: $fixedCategories ) ) {
2020-11-22 19:56:23 +00:00
self :: $fixedCategories [ $key ] = $val ;
}
}
// $text .= self::dumpParsedRefs($parser,"before final reset");
2021-02-22 23:48:01 +00:00
if ( self :: $createdLinks [ 'resetLinks' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mLinks = [];
}
2021-02-22 23:48:01 +00:00
if ( self :: $createdLinks [ 'resetCategories' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mCategories = self :: $fixedCategories ;
}
2021-02-22 23:48:01 +00:00
if ( self :: $createdLinks [ 'resetTemplates' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mTemplates = [];
}
2021-02-22 23:48:01 +00:00
if ( self :: $createdLinks [ 'resetImages' ] ) {
2020-11-22 19:56:23 +00:00
$parser -> mOutput -> mImages = [];
}
2021-02-23 00:17:04 +00:00
// $text .= self::dumpParsedRefs( $parser, 'after final reset' );
2020-11-22 19:56:23 +00:00
self :: $fixedCategories = [];
}
return true ;
}
2021-02-22 23:48:01 +00:00
public static function endEliminate ( & $parser , & $text ) {
2020-11-22 19:56:23 +00:00
// called during the final output phase; removes links created by DPL
2021-02-22 23:48:01 +00:00
if ( isset ( self :: $createdLinks ) ) {
2020-11-22 19:56:23 +00:00
// self::dumpParsedRefs($parser,"before final eliminate");
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( 0 , self :: $createdLinks ) ) {
foreach ( $parser -> mOutput -> getLinks () as $nsp => $link ) {
if ( ! array_key_exists ( $nsp , self :: $createdLinks [ 0 ] ) ) {
2020-11-22 19:56:23 +00:00
continue ;
}
// echo ("<pre> elim: created Links [$nsp] = ". count(DynamicPageListHooks::$createdLinks[0][$nsp])."</pre>\n");
// echo ("<pre> elim: parser Links [$nsp] = ". count($parser->mOutput->mLinks[$nsp]) ."</pre>\n");
2021-02-22 23:48:01 +00:00
$parser -> mOutput -> mLinks [ $nsp ] = array_diff_assoc ( $parser -> mOutput -> mLinks [ $nsp ], self :: $createdLinks [ 0 ][ $nsp ] );
2020-11-22 19:56:23 +00:00
// echo ("<pre> elim: parser Links [$nsp] nachher = ". count($parser->mOutput->mLinks[$nsp]) ."</pre>\n");
2021-02-22 23:48:01 +00:00
if ( count ( $parser -> mOutput -> mLinks [ $nsp ] ) == 0 ) {
unset ( $parser -> mOutput -> mLinks [ $nsp ] );
2020-11-22 19:56:23 +00:00
}
}
}
2021-02-22 23:48:01 +00:00
if ( isset ( self :: $createdLinks ) && array_key_exists ( 1 , self :: $createdLinks ) ) {
foreach ( $parser -> mOutput -> mTemplates as $nsp => $tpl ) {
if ( ! array_key_exists ( $nsp , self :: $createdLinks [ 1 ] ) ) {
2020-11-22 19:56:23 +00:00
continue ;
}
// echo ("<pre> elim: created Tpls [$nsp] = ". count(DynamicPageListHooks::$createdLinks[1][$nsp])."</pre>\n");
// echo ("<pre> elim: parser Tpls [$nsp] = ". count($parser->mOutput->mTemplates[$nsp]) ."</pre>\n");
2021-02-22 23:48:01 +00:00
$parser -> mOutput -> mTemplates [ $nsp ] = array_diff_assoc ( $parser -> mOutput -> mTemplates [ $nsp ], self :: $createdLinks [ 1 ][ $nsp ] );
2020-11-22 19:56:23 +00:00
// echo ("<pre> elim: parser Tpls [$nsp] nachher = ". count($parser->mOutput->mTemplates[$nsp]) ."</pre>\n");
2021-02-22 23:48:01 +00:00
if ( count ( $parser -> mOutput -> mTemplates [ $nsp ] ) == 0 ) {
unset ( $parser -> mOutput -> mTemplates [ $nsp ] );
2020-11-22 19:56:23 +00:00
}
}
}
2021-02-22 23:48:01 +00:00
if ( isset ( self :: $createdLinks ) && array_key_exists ( 2 , self :: $createdLinks ) ) {
$parser -> mOutput -> mCategories = array_diff_assoc ( $parser -> mOutput -> mCategories , self :: $createdLinks [ 2 ] );
2020-11-22 19:56:23 +00:00
}
2021-02-22 23:48:01 +00:00
if ( isset ( self :: $createdLinks ) && array_key_exists ( 3 , self :: $createdLinks ) ) {
$parser -> mOutput -> mImages = array_diff_assoc ( $parser -> mOutput -> mImages , self :: $createdLinks [ 3 ] );
2020-11-22 19:56:23 +00:00
}
// $text .= self::dumpParsedRefs($parser,"after final eliminate".$parser->mTitle->getText());
}
2021-02-23 00:17:04 +00:00
/* self :: $createdLinks = [
'resetLinks' => false , 'resetTemplates' => false ,
'resetCategories' => false , 'resetImages' => false , 'resetdone' => false
]; */
2020-11-22 19:56:23 +00:00
return true ;
}
/**
* Setups and Modifies Database Information
*
2021-02-23 00:17:04 +00:00
* @ param DatabaseUpdater $updater
2020-11-22 19:56:23 +00:00
*/
2021-02-22 23:48:01 +00:00
public static function onLoadExtensionSchemaUpdates ( DatabaseUpdater $updater ) {
2020-11-22 19:56:23 +00:00
$extDir = __DIR__ ;
2021-03-23 18:38:25 +00:00
$updater -> addPostDatabaseUpdateMaintenance ( 'DPL\\Maintenance\\CreateTemplate' );
2020-11-22 19:56:23 +00:00
$db = $updater -> getDB ();
2021-02-22 23:48:01 +00:00
if ( ! $db -> tableExists ( 'dpl_clview' ) ) {
2020-11-22 19:56:23 +00:00
// PostgreSQL doesn't have IFNULL, so use COALESCE instead
2021-02-22 23:48:01 +00:00
$sqlNullMethod = ( $db -> getType () === 'postgres' ? 'COALESCE' : 'IFNULL' );
$db -> query ( " CREATE VIEW { $db -> tablePrefix () } dpl_clview AS SELECT $sqlNullMethod (cl_from, page_id) AS cl_from, $sqlNullMethod (cl_to, '') AS cl_to, cl_sortkey FROM { $db -> tablePrefix () } page LEFT OUTER JOIN { $db -> tablePrefix () } categorylinks ON { $db -> tablePrefix () } page.page_id=cl_from; " );
2020-11-22 19:56:23 +00:00
}
}
}