r51054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51053‎ | r51054 | r51055 >
Date:09:12, 27 May 2009
Author:shinjiman
Status:deferred
Tags:
Comment:
Update the DPL codebase to 1.7.9, fixes bug 18924, thanks Gero for the patch.
Modified paths:
  • /trunk/extensions/DynamicPageList/DynamicPageList2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicPageList/DynamicPageList2.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Main include file for the DynamicPageList2 extension of MediaWiki.
56 * This code is released under the GNU General Public License.
@@ -291,7 +292,13 @@
292293 * Bugfix: labeled section inclusion did not work because content was automatically truncated to a length of zero
293294 * added minrevisions & maxrevisions
294295 * @version 1.7.9
295 - * ...
 296+ * Bugfix in errorhandling: parameter substitution within error message did not work.
 297+ * Bugfix in ordermethod=lastedit, firstedit -- led to the effect that too few pages/revisions were shown
 298+ * new feature: dplcache
 299+ * bugfix: with include=* a php warning could arise (Call-time pass-by-reference has been deprecated ..)
 300+ * new variable %IMAGE% contains image path
 301+ * new variable: %PAGEID%
 302+ * DPL command line argument: DPL_offset
296303 * ! when making changes here you must update the VERSION constant at the beginning of class ExtDynamicPageList2 !
297304 */
298305
@@ -330,8 +337,9 @@
331338
332339 class ExtDynamicPageList2
333340 {
334 - const VERSION = '1.7.8'; // current version
335341
 342+ const VERSION = '1.7.9'; // current version
 343+
336344 /**
337345 * Extension options
338346 */
@@ -406,6 +414,10 @@
407415 * shall the result set be distinct (=default) or not?
408416 */
409417 'distinct' => array('default' => 'true', 'strict', 'false', 'no', 'yes', '0', '1', 'off', 'on'),
 418+
 419+ 'dplcache' => array('default' => ''),
 420+ 'dplcacheperiod' => array('default' => '86400', 'pattern' => '/^\d+$/'), // 86400 = # seconds for one day
 421+
410422 /**
411423 * number of columns for output, default is 1
412424 */
@@ -1106,7 +1118,7 @@
11071119 return '';
11081120 }
11091121
1110 - // The real callback function for converting the input text to HTML output
 1122+ // The real callback function for converting the input text to wiki text output
11111123 private static function dynamicPageList( $input, $params, &$parser, &$bReset, $calledInMode ) {
11121124
11131125 error_reporting(E_ALL);
@@ -1162,6 +1174,10 @@
11631175
11641176 // Options
11651177
 1178+ $DPLCache = '';
 1179+ $buildDPLCache=false;
 1180+ $iDPLCachePeriod = 24* 60 * 60;
 1181+
11661182 $sGoal = self::$options['goal']['default'];
11671183
11681184 $bSelectionCriteriaFound=false;
@@ -1235,6 +1251,8 @@
12361252 $bAddLastEditor = self::argBoolean(self::$options['addlasteditor']['default']);
12371253
12381254 $bAllowCachedResults = self::argBoolean(self::$options['allowcachedresults']['default']);
 1255+ // disable parser cache if desired
 1256+ $parser->disableCache(!$bAllowCachedResults);
12391257 $bWarnCachedResults = false;
12401258
12411259 $sUserDateFormat = self::$options['userdateformat']['default'];
@@ -1260,8 +1278,9 @@
12611279 $aSecSeparators = explode(',', self::$options['secseparators']['default']);
12621280 $aMultiSecSeparators = explode(',', self::$options['multisecseparators']['default']);
12631281 $iDominantSection = self::$options['dominantsection']['default'];
1264 -
1265 - $_sOffset = self::$options['offset']['default'];
 1282+
 1283+ global $wgRequest;
 1284+ $_sOffset=$wgRequest->getVal('DPL_offset',self::$options['offset']['default']);
12661285 $iOffset = ($_sOffset == '') ? 0: intval($_sOffset);
12671286
12681287 $_sCount = self::$options['count']['default'];
@@ -1349,17 +1368,20 @@
13501369 // ###### PARSE PARAMETERS ######
13511370
13521371 // we replace double angle brackets by < > ; thus we avoid premature tag expansion in the input
1353 - $input = str_replace('»','>',$input);
1354 - $input = str_replace('«','<',$input);
 1372+ $input = str_replace('»','>',$input);
 1373+ $input = str_replace('«','<',$input);
13551374
13561375 // use the ¦ as a general alias for |
1357 - $input = str_replace('¦','|',$input); // the symbol is utf8-escaped
 1376+ $input = str_replace('¦','|',$input); // the symbol is utf8-escaped
13581377
13591378 // the combination '²{' and '}²'will be translated to double curly braces; this allows postponed template execution
13601379 // which is crucial for DPL queries which call other DPL queries
1361 - $input = str_replace('²{','{{',$input);
1362 - $input = str_replace('}²','}}',$input);
1363 -
 1380+ $input = str_replace('²{','{{',$input);
 1381+ $input = str_replace('}²','}}',$input);
 1382+
 1383+ // commandline parameters like %DPL_offset% are replaced
 1384+ $input = str_replace('%DPL_offset%',$iOffset,$input);
 1385+
13641386 $aParams = explode("\n", $input);
13651387 $bIncludeUncat = false; // to check if pseudo-category of Uncategorized pages is included
13661388
@@ -1395,10 +1417,59 @@
13961418 $output .= $logger->escapeMsg(DPL2_i18n::WARN_UNKNOWNPARAM, $sType, implode(', ', array_keys(self::$options)));
13971419 continue;
13981420 }
1399 -
 1421+
14001422 switch ($sType) {
1401 -
 1423+
14021424 /**
 1425+ * CACHE
 1426+ */
 1427+ case 'dplcache':
 1428+ if ($sArg!='') {
 1429+ global $wgUploadDirectory, $wgRequest, $wgArticle;
 1430+ $DPLCache = $wgArticle->getID().'_'.$sArg.'.txt';
 1431+ $cacheFile= "$wgUploadDirectory/dplcache/$DPLCache";
 1432+ if ($wgRequest->getVal('action','view')=='submit') {
 1433+ // when the page containing the DPL statement is changed we must recreate the cache
 1434+ // as the DPL statement may have changed
 1435+ $buildDPLCache=true;
 1436+ } else if ($wgRequest->getVal('dplrefresh','')=='yes') {
 1437+ // when the page containing the DPL statement is changed we must recreate the cache
 1438+ // as the DPL statement may have changed
 1439+ $buildDPLCache=true;
 1440+ } else if (file_exists($cacheFile)) {
 1441+ // find out if cache is acceptable or too old
 1442+ $diff = time() - filemtime($cacheFile);
 1443+ $cacheTimeStamp = date('YmdHis',filemtime($cacheFile));
 1444+ $buildDPLCache = ($diff > $iDPLCachePeriod);
 1445+ $cacheTimeStamp = ExtDynamicPageList2::prettyTimeStamp($cacheTimeStamp);
 1446+ $cachePeriod = ExtDynamicPageList2::durationTime($iDPLCachePeriod);
 1447+ $diffTime = ExtDynamicPageList2::durationTime($diff);
 1448+ }
 1449+ else {
 1450+ $buildDPLCache=true;
 1451+ }
 1452+ if (!$buildDPLCache) {
 1453+ // take result from cache article
 1454+ if ($logger->iDebugLevel>=2) $output .= "{{Extension DPL cache|mode=get|pos=top|page={{FULLPAGENAME}}|cache=$DPLCache|date=$cacheTimeStamp|age=$diffTime|period=$cachePeriod}}";
 1455+ $output .= file_get_contents($cacheFile);
 1456+ if ($logger->iDebugLevel>=2) $output .= "{{Extension DPL cache|mode=get|pos=bottom|page={{FULLPAGENAME}}|cache=$DPLCache|date=$cacheTimeStamp|age=$diffTime|period=$cachePeriod}}";
 1457+ // ignore further parameters, stop processing, return cache content
 1458+ return $output;
 1459+ }
 1460+ }
 1461+ else {
 1462+ $output .= $logger->msgWrongParam('dplcache', $sArg);
 1463+ }
 1464+ break;
 1465+
 1466+ case 'dplcacheperiod':
 1467+ if( preg_match(self::$options['dplcacheperiod']['pattern'], $sArg) )
 1468+ $iDPLCachePeriod = ($sArg == '') ? self::$options['dplcacheperiod']['default']: intval($sArg);
 1469+ else
 1470+ $output .= $logger->msgWrongParam('dplcacheperiod', $sArg);
 1471+ break;
 1472+
 1473+ /**
14031474 * GOAL
14041475 */
14051476 case 'goal':
@@ -1680,6 +1751,7 @@
16811752 $bSelectionCriteriaFound=true;
16821753 $bConflictsWithOpenReferences=true;
16831754 $bAllowCachedResults = true;
 1755+ $parser->disableCache(false);
16841756 }
16851757 break;
16861758
@@ -2077,7 +2149,7 @@
20782150 // parsing of wikitext will happen at the end of the output phase
20792151 // we replace '\n' in the input by linefeed because wiki syntax depends on linefeeds
20802152 $sArg = str_replace( '\n', "\n", $sArg );
2081 - $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
 2153+ $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
20822154 $aListSeparators = explode (',', $sArg, 4);
20832155 // mode=userformat will be automatically assumed
20842156 $sPageListMode='userformat';
@@ -2087,25 +2159,25 @@
20882160 case 'secseparators':
20892161 // we replace '\n' by newline to support wiki syntax within the section separators
20902162 $sArg = str_replace( '\n', "\n", $sArg );
2091 - $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
 2163+ $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
20922164 $aSecSeparators = explode (',',$sArg);
20932165 break;
20942166
20952167 case 'multisecseparators':
20962168 // we replace '\n' by newline to support wiki syntax within the section separators
20972169 $sArg = str_replace( '\n', "\n", $sArg );
2098 - $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
 2170+ $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
20992171 $aMultiSecSeparators = explode (',',$sArg);
21002172 break;
21012173
21022174 case 'table':
21032175 $sArg = str_replace( '\n', "\n", $sArg );
2104 - $sTable = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
 2176+ $sTable = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
21052177 break;
21062178
21072179 case 'tablerow':
21082180 $sArg = str_replace( '\n', "\n", $sArg );
2109 - $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
 2181+ $sArg = str_replace( "¶", "\n", $sArg ); // the paragraph delimiter is utf8-escaped
21102182 if (trim($sArg)=='') $aTableRow = array();
21112183 else $aTableRow = explode (',',$sArg);
21122184 break;
@@ -2220,6 +2292,7 @@
22212293 $bAllowCachedResults = true;
22222294 $bWarnCachedResults = true;
22232295 }
 2296+ $parser->disableCache(!$bAllowCachedResults);
22242297 }
22252298 else
22262299 $output .= $logger->msgWrongParam('allowcachedresults', $sArg);
@@ -2275,6 +2348,7 @@
22762349 default:
22772350 $output .= $logger->escapeMsg(DPL2_i18n::WARN_UNKNOWNPARAM, $sType, implode(', ', array_keys(self::$options)));
22782351 }
 2352+
22792353 }
22802354
22812355 // debug level 5 puts nowiki tags around the output
@@ -2294,9 +2368,6 @@
22952369 $iExcludeCatCount = count($aExcludeCategories);
22962370 $iTotalCatCount = $iTotalIncludeCatCount + $iExcludeCatCount;
22972371
2298 - // disable parser cache
2299 - if ( !$bAllowCachedResults) $parser->disableCache();
2300 -
23012372 // place cache warning in resultsheader
23022373 if ($bWarnCachedResults) $sResultsHeader = '{{DPL Cache Warning}}' . $sResultsHeader;
23032374
@@ -2335,8 +2406,8 @@
23362407
23372408 // no selection criteria!! Warn only if no debug level is set
23382409 if ($iTotalCatCount == 0 && $bSelectionCriteriaFound==false) {
2339 - if ($logger->iDebugLevel >= 1) return $output;
2340 - else return $output . $logger->escapeMsg(DPL2_i18n::FATAL_NOSELECTION);
 2410+ if ($logger->iDebugLevel <= 1) return $output;
 2411+ return $output . $logger->escapeMsg(DPL2_i18n::FATAL_NOSELECTION);
23412412 }
23422413
23432414 // ordermethod=sortkey requires ordermethod=category
@@ -2466,6 +2537,8 @@
24672538 }
24682539 }
24692540
 2541+ $output.='{{Extension DPL}}';
 2542+
24702543 // ###### BUILD SQL QUERY ######
24712544 $sSqlPage_counter = '';
24722545 $sSqlPage_size = '';
@@ -2525,12 +2598,14 @@
25262599 case 'firstedit':
25272600 $sSqlRevisionTable = $sRevisionTable . ' AS rev, ';
25282601 $sSqlRev_timestamp = ', rev_timestamp';
2529 - $sSqlCond_page_rev = ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MIN(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
 2602+ // deleted because of conflict with revsion-parameters
 2603+ // $sSqlCond_page_rev = ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MIN(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
25302604 break;
25312605 case 'lastedit':
25322606 $sSqlRevisionTable = $sRevisionTable . ' AS rev, ';
25332607 $sSqlRev_timestamp = ', rev_timestamp';
2534 - $sSqlCond_page_rev = ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
 2608+ // deleted because of conflict with revsion-parameters
 2609+ // $sSqlCond_page_rev = ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
25352610 break;
25362611 case 'sortkey':
25372612 // We need the namespaces with strictly positive indices (DPL2 allowed namespaces, except the first one: Main).
@@ -2544,14 +2619,14 @@
25452620 // UTF-8 created problems with non-utf-8 MySQL databases
25462621 //see line 2011 (order method sortkey requires category
25472622 if (in_array('category',$aOrderMethods)) {
2548 - $sSqlSortkey = ", IFNULL(cl_head.cl_sortkey, REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣')) ".$sOrderCollation." as sortkey";
 2623+ $sSqlSortkey = ", IFNULL(cl_head.cl_sortkey, REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣')) ".$sOrderCollation." as sortkey";
25492624 }
25502625 else {
2551 - $sSqlSortkey = ", IFNULL(cl0.cl_sortkey, REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣')) ".$sOrderCollation." as sortkey";
 2626+ $sSqlSortkey = ", IFNULL(cl0.cl_sortkey, REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣')) ".$sOrderCollation." as sortkey";
25522627 }
25532628 break;
25542629 case 'titlewithoutnamespace':
2555 - $sSqlSortkey = ", REPLACE(page_title,'♣','⣣') ".$sOrderCollation." as sortkey";
 2630+ $sSqlSortkey = ", REPLACE(page_title,'♣','⣣') ".$sOrderCollation." as sortkey";
25562631 break;
25572632 case 'pagesel':
25582633 $sSqlSortkey = ", CONCAT(pl.pl_namespace,pl.pl_title) ".$sOrderCollation." as sortkey";
@@ -2564,7 +2639,7 @@
25652640 foreach($aStrictNs as $iNs => $sNs)
25662641 $sSqlNsIdToText .= ' WHEN ' . intval( $iNs ) . " THEN " . $dbr->addQuotes( $sNs ) ;
25672642 $sSqlNsIdToText .= ' END';
2568 - $sSqlSortkey = ", REPLACE(REPLACE(CONCAT( IF(pl_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), pl_title), '_', ' '),'♣','⣣') ".$sOrderCollation." as sortkey";
 2643+ $sSqlSortkey = ", REPLACE(REPLACE(CONCAT( IF(pl_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), pl_title), '_', ' '),'♣','⣣') ".$sOrderCollation." as sortkey";
25692644 }
25702645 else {
25712646 $sSqlNsIdToText = 'CASE '.$sPageTable.'.page_namespace';
@@ -2572,7 +2647,7 @@
25732648 $sSqlNsIdToText .= ' WHEN ' . intval( $iNs ) . " THEN " . $dbr->addQuotes( $sNs ) ;
25742649 $sSqlNsIdToText .= ' END';
25752650 // Generate sortkey like for category links. UTF-8 created problems with non-utf-8 MySQL databases
2576 - $sSqlSortkey = ", REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣') ".$sOrderCollation." as sortkey";
 2651+ $sSqlSortkey = ", REPLACE(REPLACE(CONCAT( IF(".$sPageTable.".page_namespace=0, '', CONCAT(" . $sSqlNsIdToText . ", ':')), ".$sPageTable.".page_title), '_', ' '),'♣','⣣') ".$sOrderCollation." as sortkey";
25772652 }
25782653 break;
25792654 case 'user':
@@ -2790,11 +2865,11 @@
27912866
27922867 if ($bAddAuthor && $sSqlRevisionTable =='') {
27932868 $sSqlRevisionTable = $sRevisionTable . ' AS rev, ';
2794 - $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MIN(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
 2869+ $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MIN(rev_aux_min.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux_min WHERE rev_aux_min.rev_page=rev.rev_page )';
27952870 }
27962871 if ($bAddLastEditor && $sSqlRevisionTable =='') {
27972872 $sSqlRevisionTable = $sRevisionTable . ' AS rev, ';
2798 - $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page )';
 2873+ $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux_max.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux_max WHERE rev_aux_max.rev_page=rev.rev_page )';
27992874 }
28002875
28012876 if ($sLastRevisionBefore.$sAllRevisionsBefore.$sFirstRevisionSince.$sAllRevisionsSince != '') {
@@ -2808,13 +2883,13 @@
28092884 $sSqlRev_timestamp = ', rev_timestamp';
28102885 $sSqlRev_id = ', rev_id';
28112886 if ($sLastRevisionBefore!='') {
2812 - $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page AND rev_aux.rev_timestamp < '.$sLastRevisionBefore.')';
 2887+ $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux_bef.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux_bef WHERE rev_aux_bef.rev_page=rev.rev_page AND rev_aux_bef.rev_timestamp < '.$sLastRevisionBefore.')';
28132888 }
28142889 if ($sAllRevisionsBefore!='') {
28152890 $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp < '.$sAllRevisionsBefore;
28162891 }
28172892 if ($sFirstRevisionSince!='') {
2818 - $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MIN(rev_aux.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux WHERE rev_aux.rev_page=rev.rev_page AND rev_aux.rev_timestamp >= '.$sFirstRevisionSince.')';
 2893+ $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp=( SELECT MAX(rev_aux_snc.rev_timestamp) FROM ' . $sRevisionTable . ' AS rev_aux_snc WHERE rev_aux_snc.rev_page=rev.rev_page AND rev_aux_snc.rev_timestamp >= '.$sFirstRevisionSince.')';
28192894 }
28202895 if ($sAllRevisionsSince!='') {
28212896 $sSqlCond_page_rev .= ' AND '.$sPageTable.'.page_id=rev.rev_page AND rev.rev_timestamp >= '.$sAllRevisionsSince;
@@ -2863,7 +2938,7 @@
28642939 }
28652940 else
28662941 $sSqlSelectFrom = "SELECT $sSqlCalcFoundRows $sSqlDistinct " . $sSqlCl_to . $sPageTable.'.page_namespace as page_namespace,'.
2867 - $sPageTable.'.page_title as page_title' . $sSqlSelPage . $sSqlSortkey . $sSqlPage_counter .
 2942+ $sPageTable.'.page_title as page_title ,page_id' . $sSqlSelPage . $sSqlSortkey . $sSqlPage_counter .
28682943 $sSqlPage_size . $sSqlPage_touched . $sSqlRev_user .
28692944 $sSqlRev_timestamp . $sSqlRev_id . $sSqlCats . $sSqlCl_timestamp .
28702945 ' FROM ' . $sSqlRevisionTable . $sSqlRCTable . $sSqlPageLinksTable . $sPageTable;
@@ -3089,8 +3164,8 @@
30903165 }
30913166
30923167 if ($dbr->numRows( $res ) <= 0) {
3093 - if ($sNoResultsHeader != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsHeader));
3094 - if ($sNoResultsFooter != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsFooter));
 3168+ if ($sNoResultsHeader != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsHeader));
 3169+ if ($sNoResultsFooter != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsFooter));
30953170 if ($sNoResultsHeader == '' && $sNoResultsFooter == '') $output .= $logger->escapeMsg(DPL2_i18n::WARN_NORESULTS);
30963171 $dbr->freeResult( $res );
30973172 return $output;
@@ -3186,6 +3261,9 @@
31873262 if( isset($row->sortkey) ) {
31883263 $dplArticle->mStartChar = $wgContLang->convert($wgContLang->firstChar($row->sortkey));
31893264 }
 3265+ // page_id
 3266+ $dplArticle->mID = $row->page_id;
 3267+
31903268 //SHOW PAGE_COUNTER
31913269 if( isset($row->page_counter) )
31923270 $dplArticle->mCounter = $row->page_counter;
@@ -3312,14 +3390,14 @@
33133391 if ($sOneResultHeader != '' && $rowcount==1) {
33143392 $header = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',1,$sOneResultHeader));
33153393 } else if ($rowcount==0) {
3316 - if ($sNoResultsHeader != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsHeader));
3317 - if ($sNoResultsFooter != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsFooter));
 3394+ if ($sNoResultsHeader != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsHeader));
 3395+ if ($sNoResultsFooter != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsFooter));
33183396 if ($sNoResultsHeader == '' && $sNoResultsFooter == '') $output .= $logger->escapeMsg(DPL2_i18n::WARN_NORESULTS);
33193397 }
33203398 else {
33213399 if ($sResultsHeader != '') $header = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',$dpl->getRowCount(),$sResultsHeader));
33223400 }
3323 - $header = str_replace( '\n', "\n", str_replace( "¶", "\n", $header ));
 3401+ $header = str_replace( '\n', "\n", str_replace( "¶", "\n", $header ));
33243402 $header = str_replace('%VERSION%', self::VERSION,$header);
33253403 $footer='';
33263404 if ($sOneResultFooter != '' && $rowcount==1) {
@@ -3327,11 +3405,21 @@
33283406 } else {
33293407 if ($sResultsFooter != '') $footer = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',$rowcount,$sResultsFooter));
33303408 }
3331 - $footer = str_replace( '\n', "\n", str_replace( "¶", "\n", $footer ));
 3409+ $footer = str_replace( '\n', "\n", str_replace( "¶", "\n", $footer ));
33323410 $footer = str_replace('%VERSION%', self::VERSION, $footer);
33333411
33343412 $output .= $header . $dpl2result . $footer;
 3413+
33353414
 3415+ // save generated wiki text to dplcache page if desired
 3416+ if ($buildDPLCache) {
 3417+ if (!file_exists(dirname($cacheFile))) mkdir(dirname($cacheFile));
 3418+ $cacheTimeStamp = ExtDynamicPageList2::prettyTimeStamp(date('YmdHis'));
 3419+ file_put_contents($cacheFile,$output);
 3420+ if ($logger->iDebugLevel>=2) $output .= "{{Extension DPL cache|pos=bottom|mode=update|page={{FULLPAGENAME}}|cache=$DPLCache|date=$cacheTimeStamp|age=0}}";
 3421+ }
 3422+
 3423+
33363424 // The following requires an extra parser step which may consume some time
33373425 // we parse the DPL output and save all referenced found in that output in a global list
33383426 // in a final user exit after the whole document processing we eliminate all these links
@@ -3380,6 +3468,7 @@
33813469 }
33823470
33833471 return $output;
 3472+
33843473
33853474 }
33863475
@@ -3421,6 +3510,17 @@
34223511 $dbr->freeResult( $res );
34233512 return $cats;
34243513 }
 3514+
 3515+ private static function prettyTimeStamp($t) {
 3516+ return substr($t,0,4).'/'.substr($t,4,2).'/'.substr($t,6,2).' '.substr($t,8,2).':'.substr($t,10,2).':'.substr($t,12,2);
 3517+ }
 3518+ private static function durationTime($t) {
 3519+ if ($t<60) return "00:00:".str_pad($t,2,"0",STR_PAD_LEFT);
 3520+ if ($t<3600) return "00:".str_pad(floor($t/60),2,"0",STR_PAD_LEFT).':'.str_pad(floor(fmod($t,60)),2,"0",STR_PAD_LEFT);
 3521+ if ($t<86400) return str_pad(floor($t/3600),2,"0",STR_PAD_LEFT).':'.str_pad(floor(fmod(floor($t/60),60)),2,"0",STR_PAD_LEFT).':'.str_pad(fmod($t,60),2,"0",STR_PAD_LEFT);
 3522+ if ($t<2*86400) return "1 day";
 3523+ return floor($t/86400). ' days';
 3524+ }
34253525
34263526 public static function endReset( &$parser, $text ) {
34273527 if (!self::$createdLinks['resetdone']) {
@@ -3492,6 +3592,7 @@
34933593 class DPL2Article {
34943594 var $mTitle = ''; // title
34953595 var $mNamespace = -1; // namespace (number)
 3596+ var $mID = 0; // page_id
34963597 var $mSelTitle = ''; // selected title of initial page
34973598 var $mSelNamespace = -1;// selected namespace (number) of initial page
34983599 var $mImageSelTitle = ''; // selected title of image
@@ -3770,14 +3871,16 @@
37713872 }
37723873
37733874 // substitute symbolic names within a user defined format tag
3774 - function substTagParm($tag, $pagename, $article, $nr, $titleMaxLength) {
 3875+ function substTagParm($tag, $pagename, $article, $imageUrl, $nr, $titleMaxLength) {
37753876 global $wgLang;
37763877 if (strchr($tag,'%')<0) return $tag;
37773878 $sTag = str_replace('%PAGE%',$pagename,$tag);
 3879+ $sTag = str_replace('%PAGEID%',$article->mID,$sTag);
37783880 $sTag = str_replace('%NAMESPACE%',$this->nameSpaces[$article->mNamespace],$sTag);
 3881+ $sTag = str_replace('%IMAGE%',$imageUrl,$sTag);
37793882
37803883 $title = $article->mTitle->getText();
3781 - if (strpos($title,'%TITLE')>=0) {
 3884+ if (strpos($title,'%TITLE%')>=0) {
37823885 if ($this->mReplaceInTitle[0]!='') $title = preg_replace($this->mReplaceInTitle[0],$this->mReplaceInTitle[1],$title);
37833886 if( isset($titleMaxLength) && (strlen($title) > $titleMaxLength)) $title = substr($title, 0, $titleMaxLength) . '...';
37843887 $sTag = str_replace('%TITLE%',$title,$sTag);
@@ -3840,6 +3943,12 @@
38413944
38423945 $article = $this->mArticles[$i];
38433946 $pagename = $article->mTitle->getPrefixedText();
 3947+ $imageUrl='';
 3948+ if ($article->mNamespace==6) {
 3949+ // calculate URL for existing images
 3950+ $img = Image::newFromName($article->mTitle->getText());
 3951+ if ($img && $img->exists()) $imageUrl = $img->getURL();
 3952+ }
38443953 if ($this->mEscapeLinks && ($article->mNamespace==14 || $article->mNamespace==6) ) {
38453954 // links to categories or images need an additional ":"
38463955 $pagename = ':'.$pagename;
@@ -3877,9 +3986,9 @@
38783987 else {
38793988 // append full text to output
38803989 if (array_key_exists('0',$mode->sSectionTags)){
3881 - $incwiki .= $this->substTagParm($mode->sSectionTags[0], $pagename, $article,$this->filteredCount, $iTitleMaxLen);
 3990+ $incwiki .= $this->substTagParm($mode->sSectionTags[0], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen);
38823991 $pieces = array(0=>$text);
3883 - $this->formatSingleItems(&$pieces, 0);
 3992+ $this->formatSingleItems($pieces, 0);
38843993 $incwiki .= $pieces[0];
38853994 }
38863995 else $incwiki .= $text;
@@ -3949,7 +4058,7 @@
39504059 for ($sp=1;$sp<count($secPieces);$sp++) {
39514060 if (isset($mode->aMultiSecSeparators[$s])) {
39524061 $secPiece[$s] .= str_replace('%SECTION%',$sectionHeading[$sp],
3953 - $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article,
 4062+ $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article, $imageUrl,
39544063 $this->filteredCount, $iTitleMaxLen));
39554064 }
39564065 $secPiece[$s] .= $secPieces[$sp];
@@ -3968,7 +4077,7 @@
39694078 $template2, $template2.$defaultTemplateSuffix,$mustMatch,
39704079 $mustNotMatch,$this->mIncParsed,$iTitleMaxLen);
39714080 $secPiece[$s] = implode(isset($mode->aMultiSecSeparators[$s])?
3972 - $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article, $this->filteredCount, $iTitleMaxLen):'',$secPieces);
 4081+ $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen):'',$secPieces);
39734082 if ($mode->iDominantSection>=0 && $s==$mode->iDominantSection && count($secPieces)>1) $dominantPieces=$secPieces;
39744083 if (($mustMatch!='' || $mustNotMatch!='') && count($secPieces)<=1 && $secPieces[0]=='') {
39754084 $matchFailed=true; // NOTHING MATCHED
@@ -3978,7 +4087,7 @@
39794088 // Uses DPL2Include::includeSection() from LabeledSectionTransclusion extension to include labeled sections from the page
39804089 $secPieces = DPL2Include::includeSection($this->mParser, $article->mTitle->getPrefixedText(), $sSecLabel,'', false, $bIncludeTrim);
39814090 $secPiece[$s] = implode(isset($mode->aMultiSecSeparators[$s])?
3982 - $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article, $this->filteredCount, $iTitleMaxLen):'',$secPieces);
 4091+ $this->substTagParm($mode->aMultiSecSeparators[$s], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen):'',$secPieces);
39834092 if ($mode->iDominantSection>=0 && $s==$mode->iDominantSection && count($secPieces)>1) $dominantPieces=$secPieces;
39844093 if ( ($mustMatch !='' && preg_match($mustMatch ,$secPiece[$s])==false) ||
39854094 ($mustNotMatch !='' && preg_match($mustNotMatch,$secPiece[$s])!=false) ) {
@@ -3990,14 +4099,14 @@
39914100 // separator tags
39924101 if (count($mode->sSectionTags)==1) {
39934102 // If there is only one separator tag use it always
3994 - $septag[$s*2] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[0], $pagename, $article, $this->filteredCount, $iTitleMaxLen));
 4103+ $septag[$s*2] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[0], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen));
39954104 }
39964105 else if (isset($mode->sSectionTags[$s*2])) {
3997 - $septag[$s*2] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[$s*2], $pagename, $article, $this->filteredCount, $iTitleMaxLen));
 4106+ $septag[$s*2] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[$s*2], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen));
39984107 }
39994108 else $septag[$s*2] = '';
40004109 if (isset($mode->sSectionTags[$s*2+1])) {
4001 - $septag[$s*2+1] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[$s*2+1], $pagename, $article, $this->filteredCount, $iTitleMaxLen));
 4110+ $septag[$s*2+1] = str_replace('%SECTION%',$sectionHeading[0],$this->substTagParm($mode->sSectionTags[$s*2+1], $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen));
40024111 }
40034112 else $septag[$s*2+1]='';
40044113
@@ -4032,7 +4141,7 @@
40334142
40344143 // symbolic substitution of %PAGE% by the current article's name
40354144 if ($mode->name == 'userformat') {
4036 - $rBody .= $this->substTagParm($mode->sItemStart, $pagename, $article,$this->filteredCount, $iTitleMaxLen);
 4145+ $rBody .= $this->substTagParm($mode->sItemStart, $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen);
40374146 }
40384147 else {
40394148 $rBody .= $mode->sItemStart;
@@ -4073,7 +4182,7 @@
40744183 }
40754184
40764185 if ($mode->name == 'userformat') {
4077 - $rBody .= $this->substTagParm($mode->sItemEnd, $pagename, $article, $this->filteredCount, $iTitleMaxLen);
 4186+ $rBody .= $this->substTagParm($mode->sItemEnd, $pagename, $article, $imageUrl, $this->filteredCount, $iTitleMaxLen);
40784187 }
40794188 else {
40804189 $rBody .= $mode->sItemEnd;
@@ -4237,7 +4346,7 @@
42384347 // links to categories or images need an additional ":"
42394348 $pagename = ':'.$pagename;
42404349 }
4241 - return $this->substTagParm($tag, $pagename, $article, $this->filteredCount, $iTitleMaxLen);
 4350+ return $this->substTagParm($tag, $pagename, $article, $this->filteredCount, '', $iTitleMaxLen);
42424351 }
42434352
42444353 //format one item of an entry in the output list (i.e. the collection of occurences of one item from the include parameter)
@@ -4379,10 +4488,15 @@
43804489 if($this->iDebugLevel >= ExtDynamicPageList2::$debugMinLevels[$msgid]) {
43814490 $args = func_get_args();
43824491 array_shift( $args );
 4492+ $val='';
 4493+ if (array_key_exists(0,$args)) $val = $args[0];
 4494+ array_shift( $args );
43834495 /**
43844496 * @todo add a DPL id to identify the DPL tag that generates the message, in case of multiple DPLs in the page
43854497 */
4386 - return '<p>%DPL-' . ExtDynamicPageList2::VERSION . '-' . wfMsg('dpl2_log_' . $msgid, $args) . '</p>';
 4498+ $text = wfMsg('dpl2_log_' . $msgid, $args);
 4499+ $text = str_replace('$0',$val,$text);
 4500+ return '<p>%DPL-' . ExtDynamicPageList2::VERSION . '-' . $text . '</p>';
43874501 }
43884502 return '';
43894503 }
@@ -4391,7 +4505,7 @@
43924506 * Get a message.
43934507 * Parameters may be unescaped, this function will escape them for HTML.
43944508 */
4395 - function escapeMsg( $msgid /*, ... */ ) {
 4509+ function escapeMsg( $msgid ) {
43964510 $args = func_get_args();
43974511 $args = array_map( 'htmlspecialchars', $args );
43984512 return call_user_func_array( array( $this, 'msg' ), $args );
@@ -4428,4 +4542,5 @@
44294543 sort($paramoptions);
44304544 return $this->escapeMsg( $msgid, $paramvar, htmlspecialchars( $val ), ExtDynamicPageList2::$options[$paramvar]['default'], implode(' | ', $paramoptions ));
44314545 }
 4546+
44324547 }

Status & tagging log