r51852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51851‎ | r51852 | r51853 >
Date:16:07, 14 June 2009
Author:shinjiman
Status:deferred (Comments)
Tags:
Comment:
Update the DPL codebase to 1.8.3.
code based on Gero aka Algorithmix
Modified paths:
  • /trunk/extensions/DynamicPageList/DPLMain.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DPLSetup.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DynamicPageList.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DynamicPageListMigration.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicPageList/DynamicPageList.php
@@ -59,7 +59,7 @@
6060
6161 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
6262
63 -$DPLVersion = '1.8.1';
 63+$DPLVersion = '1.8.3';
6464
6565 $wgExtensionCredits['parserhook'][] = array(
6666 'path' => __FILE__,
Index: trunk/extensions/DynamicPageList/DPLSetup.php
@@ -27,7 +27,7 @@
2828 * addcategories: bug fixed
2929 * CATLIST variable defined
3030 * @version 0.9.3
31 - * allow � as an alias for |
 31+ * allow ?as an alias for |
3232 * escapelinks= introduced
3333 * @version 0.9.4
3434 * allow "-" with categories =
@@ -314,8 +314,15 @@
315315 * @version 1.8.1
316316 * bugfix: %DATE% was not expanded when addedit=true and ordermethod=lastedit were chosen
317317 * bugfix: allrevisionssince delivered wrong results
 318+ * @version 1.8.2
 319+ * bugfix: ordermethod=lastedit AND minoredits=exclude produced a SQL error
 320+
 321+ * bugfix dplcache
 322+ * config switch: respectParserCache
 323+ * date timestamp adapt to user preferences
 324+ * @version 1.8.3
 325+ * bugfix: URL variable expansion
318326
319 -
320327 * ! when making changes here you must update the version field in DynamicPageList.php and DynamicPageListMigration.php !
321328 */
322329
@@ -351,6 +358,8 @@
352359 public static $behavingLikeIntersection = false; // Changes certain default values to comply with Extension:Intersection
353360 public static $functionalRichness = 0; // The amount of functionality of DPL that is accesible for the user;
354361 // .. to be set by DynamicPageList.php and DynamicPageListMigration.php
 362+ public static $respectParserCache = false; // false = make page dynamic ; true = execute only when parser cache is refreshed
 363+ // .. to be changed in LocalSettings.php
355364
356365 /**
357366 * Map parameters to possible values.
@@ -369,7 +378,9 @@
370379 'addpagesize' => array('default' => 'false', 'true', 'no', 'yes', '0', '1', 'off', 'on'),
371380 'addpagetoucheddate' => array('default' => 'false', 'true', 'no', 'yes', '0', '1', 'off', 'on'),
372381 'adduser' => array('default' => 'false', 'true', 'no', 'yes', '0', '1', 'off', 'on'),
373 - 'allowcachedresults' => array('default' => 'false', 'true', 'no', 'yes', '0', '1', 'off', 'on', 'yes+warn'),
 382+
 383+ // default of allowchacheresults depends on behaveasIntersetion and on LopcalSettings ...
 384+ 'allowcachedresults' => array( 'true', 'false', 'no', 'yes', 'yes+warn', '0', '1', 'off', 'on'),
374385 /**
375386 * search for a page with the same title in another namespace (this is normally the article to a talk page)
376387 */
@@ -533,7 +544,7 @@
534545 /**
535546 * listseparators is an array of four tags (in html or wiki syntax) which defines the output of DPL
536547 * if mode = 'userformat' was specified.
537 - * '\n' or '�' in the input will be interpreted as a newline character.
 548+ * '\n' or '? in the input will be interpreted as a newline character.
538549 * '%xxx%' in the input will be replaced by a corresponding value (xxx= PAGE, NR, COUNT etc.)
539550 * t1 and t4 are the "outer envelope" for the whole result list,
540551 * t2,t3 form an inner envelope around the article name of each entry.
@@ -863,6 +874,7 @@
864875 suppresserrors
865876 ',
866877 1 => '
 878+ allowcachedresults
867879 execandexit
868880 columns
869881 debug
@@ -899,7 +911,6 @@
900912 addpagesize
901913 addpagetoucheddate
902914 adduser
903 - allowcachedresults
904915 categoriesminmax
905916 createdby
906917 dominantsection
@@ -1146,7 +1157,7 @@
11471158 $numargs = func_num_args();
11481159 if ($numargs < 2) {
11491160 $input = "#dpl: no arguments specified";
1150 - return str_replace('�','<','�pre>�nowiki>'.$input.'�/nowiki>�/pre>');
 1161+ return str_replace('?,'<','�pre>�nowiki>'.$input.'?nowiki>?pre>');
11511162 }
11521163
11531164 // fetch all user-provided arguments (skipping $parser)
@@ -1156,7 +1167,7 @@
11571168 $input .= str_replace("\n","",$p1) ."\n";
11581169 }
11591170 // for debugging you may want to uncomment the following statement
1160 - // return str_replace('�','<','�pre>�nowiki>'.$input.'�/nowiki>�/pre>');
 1171+ // return str_replace('?,'<','�pre>�nowiki>'.$input.'?nowiki>?pre>');
11611172
11621173
11631174 // $dump1 = self::dumpParsedRefs($parser,"before DPL func");
Index: trunk/extensions/DynamicPageList/DPLMain.php
@@ -11,6 +11,9 @@
1212 // The real callback function for converting the input text to wiki text output
1313 public static function dynamicPageList( $input, $params, &$parser, &$bReset, $calledInMode ) {
1414
 15+ // Output
 16+ $output = '';
 17+
1518 error_reporting(E_ALL);
1619
1720 global $wgUser, $wgContLang, $wgRequest, $wgRawHtml;
@@ -74,16 +77,9 @@
7578
7679 // check parameters which can be set via the URL
7780
78 - if (strpos($input,'{%DPL_')!== false) {
 81+ if (strpos($input,'{%DPL_') >= 0) {
7982 for($i=1;$i<=5;$i++) {
80 - $dplArg = $wgRequest->getVal('DPL_arg'.$i,'');
81 - if ($dplArg=='') {
82 - $input=preg_replace('/\{%DPL_arg'.$i.':(.*)%\}/U', '\1' ,$input);
83 - $input=preg_replace('/\{%DPL_arg'.$i.'%\}/U', '\1' ,$input);
84 - } else {
85 - $input=preg_replace('/\{%DPL_arg'.$i.':.*%\}/U ', $dplArg ,$input);
86 - $input=str_replace('{%DPL_arg'.$i.'%}' , $dplArg ,$input);
87 - }
 83+ $input = self::resolveUrlArg($input,'DPL_arg'.$i);
8884 }
8985 }
9086
@@ -94,7 +90,8 @@
9591 $iCount = -1;
9692
9793 // commandline parameters like %DPL_offset% are replaced
98 - $input = str_replace('{%DPL_offset%}',$iOffset,$input);
 94+ $input = self::resolveUrlArg($input,'DPL_offset');
 95+ $input = self::resolveUrlArg($input,'DPL_count');
9996
10097 $originalInput = $input;
10198
@@ -126,13 +123,14 @@
127124 // execAndExit
128125 $sExecAndExit= ExtDynamicPageList::$options['execandexit']['default'];
129126
130 - // ordermethod, order, mode, userdateformat:
 127+ // ordermethod, order, mode, userdateformat, allowcachedresults:
131128 // if we have to behave like Extension:Intersection we use different default values for some commands
132129 if (ExtDynamicPageList::$behavingLikeIntersection) {
133130 ExtDynamicPageList::$options['ordermethod'] = array('default' => 'categoryadd', 'categoryadd', 'lastedit');
134131 ExtDynamicPageList::$options['order'] = array('default' => 'descending', 'ascending', 'descending');
135132 ExtDynamicPageList::$options['mode'] = array('default' => 'unordered', 'none', 'ordered', 'unordered');
136133 ExtDynamicPageList::$options['userdateformat'] = array('default' => 'Y-m-d: ');
 134+ ExtDynamicPageList::$options['allowcachedresults']['default'] = 'true';
137135 }
138136 else {
139137 ExtDynamicPageList::$options['ordermethod'] = array('default' => 'title', 'counter', 'size', 'category', 'sortkey',
@@ -142,6 +140,7 @@
143141 ExtDynamicPageList::$options['order'] = array('default' => 'ascending', 'ascending', 'descending');
144142 ExtDynamicPageList::$options['mode'] = array('default' => 'unordered', 'category', 'inline', 'none', 'ordered', 'unordered', 'userformat');
145143 ExtDynamicPageList::$options['userdateformat'] = array('default' => 'Y-m-d H:i: ');
 144+ ExtDynamicPageList::$options['allowcachedresults']['default'] = ExtDynamicPageList::$respectParserCache;
146145 }
147146 $aOrderMethods = array(ExtDynamicPageList::$options['ordermethod']['default']);
148147 $sOrder = ExtDynamicPageList::$options['order']['default'];
@@ -305,9 +304,6 @@
306305 $sUpdateRules = ExtDynamicPageList::$options['updaterules']['default'];
307306 $sDeleteRules = ExtDynamicPageList::$options['deleterules']['default'];
308307
309 - // Output
310 - $output = '';
311 -
312308
313309 // ###### PARSE PARAMETERS ######
314310
@@ -315,10 +311,10 @@
316312 $input = str_replace('»','>',$input);
317313 $input = str_replace('«','<',$input);
318314
319 - // use the � as a general alias for |
 315+ // use the � as a general alias for |
320316 $input = str_replace('¦','|',$input); // the symbol is utf8-escaped
321317
322 - // the combination '�{' and '}�'will be translated to double curly braces; this allows postponed template execution
 318+ // the combination '�{' and '}�'will be translated to double curly braces; this allows postponed template execution
323319 // which is crucial for DPL queries which call other DPL queries
324320 $input = str_replace('²{','{{',$input);
325321 $input = str_replace('}²','}}',$input);
@@ -572,7 +568,7 @@
573569 case 'execandexit':
574570 // we offer a possibility to execute a DPL command without querying the database
575571 // this is useful if you want to catch the command line parameters DPL_arg1,... etc
576 - return $sArg;
 572+ $sExecAndExit = $sArg;
577573 break;
578574
579575
@@ -945,7 +941,6 @@
946942 $bSelectionCriteriaFound=true;
947943 $bConflictsWithOpenReferences=true;
948944 $bAllowCachedResults = true;
949 - $parser->disableCache(false);
950945 }
951946 break;
952947
@@ -1203,7 +1198,6 @@
12041199 $bAllowCachedResults = true;
12051200 $bWarnCachedResults = true;
12061201 }
1207 - if ($bAllowCachedResults) $parser->disableCache();
12081202 }
12091203 else
12101204 $output .= $logger->msgWrongParam('allowcachedresults', $sArg);
@@ -1445,8 +1439,21 @@
14461440 // justify limits;
14471441 $iCount = ExtDynamicPageList::$maxResultCount;
14481442 }
 1443+
 1444+
 1445+ // disable parser cache if caching is not allowed (which is default for DPL but not for <DynamicPageList>)
 1446+ if ( !$bAllowCachedResults) {
 1447+ $parser->disableCache();
 1448+ }
 1449+ // place cache warning in resultsheader
 1450+ if ($bWarnCachedResults) $sResultsHeader = '{{DPL Cache Warning}}' . $sResultsHeader;
14491451
14501452
 1453+
 1454+ if ($sExecAndExit != '') return $sExecAndExit;
 1455+
 1456+
 1457+
14511458 // if Caching is desired AND if the cache is up to date: get result from Cache and exit
14521459
14531460 global $wgUploadDirectory, $wgRequest;
@@ -1492,10 +1499,7 @@
14931500 $iTotalIncludeCatCount = count($aIncludeCategories, COUNT_RECURSIVE) - $iIncludeCatCount;
14941501 $iExcludeCatCount = count($aExcludeCategories);
14951502 $iTotalCatCount = $iTotalIncludeCatCount + $iExcludeCatCount;
1496 -
1497 - // place cache warning in resultsheader
1498 - if ($bWarnCachedResults) $sResultsHeader = '{{DPL Cache Warning}}' . $sResultsHeader;
1499 -
 1503+
15001504 if ($calledInMode=='tag') {
15011505 // in tag mode 'eliminate' is the same as 'reset' for tpl,cat,img
15021506 if ($bReset[5]) { $bReset[1] = true; $bReset[5] = false; }
@@ -1519,7 +1523,8 @@
15201524 }
15211525
15221526
1523 - // ###### CHECKS ON PARAMETERS ######
 1527+ // ###### CHECKS ON PARAMETERS ######
 1528+
15241529 // too many categories!
15251530 if ( ($iTotalCatCount > ExtDynamicPageList::$maxCategoryCount) && (!ExtDynamicPageList::$allowUnlimitedCategories) )
15261531 return $output . $logger->escapeMsg(DPL_i18n::FATAL_TOOMANYCATS, ExtDynamicPageList::$maxCategoryCount);
@@ -1723,16 +1728,19 @@
17241729 // deleted because of conflict with revsion-parameters
17251730 $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 )';
17261731 break;
 1732+ case 'pagetouched':
 1733+ $sSqlPage_touched = ", $sPageTable.page_touched as page_touched";
 1734+ break;
17271735 case 'lastedit':
1728 - if ($bAddUser) {
 1736+ if (ExtDynamicPageList::$behavingLikeIntersection) {
 1737+ $sSqlPage_touched = ", $sPageTable.page_touched as page_touched";
 1738+ }
 1739+ else {
17291740 $sSqlRevisionTable = $sRevisionTable . ' AS rev, ';
17301741 $sSqlRev_timestamp = ', rev_timestamp';
17311742 // deleted because of conflict with revision-parameters
17321743 $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 )';
17331744 }
1734 - else {
1735 - $sSqlPage_touched = ", $sPageTable.page_touched as page_touched";
1736 - }
17371745 break;
17381746 case 'sortkey':
17391747 // We need the namespaces with strictly positive indices (DPL allowed namespaces, except the first one: Main).
@@ -2040,7 +2048,7 @@
20412049 $sSqlPage_counter = ", $sPageTable.page_counter as page_counter";
20422050 if ($bAddPageSize)
20432051 $sSqlPage_size = ", $sPageTable.page_len as page_len";
2044 - if ($bAddPageTouchedDate)
 2052+ if ($bAddPageTouchedDate && $sSqlPage_touched=='')
20452053 $sSqlPage_touched = ", $sPageTable.page_touched as page_touched";
20462054 if ($bAddUser || $bAddAuthor || $bAddLastEditor || $sSqlRevisionTable != '')
20472055 $sSqlRev_user = ', rev_user, rev_user_text';
@@ -2262,7 +2270,9 @@
22632271 $sSqlWhere .= 'rev_timestamp';
22642272 break;
22652273 case 'lastedit':
2266 - $sSqlWhere .= 'page_touched';
 2274+ // extension:intersection used to sort by page_touched although the field is called 'lastedit'
 2275+ if (ExtDynamicPageList::$behavingLikeIntersection) $sSqlWhere .= 'page_touched';
 2276+ else $sSqlWhere .= 'rev_timestamp';
22672277 break;
22682278 case 'pagetouched':
22692279 $sSqlWhere .= 'page_touched';
@@ -2363,7 +2373,10 @@
23642374 }
23652375 }
23662376
2367 -
 2377+
 2378+ // find user's time correction
 2379+ $timeCorrection = self::getTimeCorrection($wgUser);
 2380+
23682381 $iArticle = 0;
23692382
23702383 while( $row = $dbr->fetchObject ( $res ) ) {
@@ -2473,6 +2486,11 @@
24742487 elseif ($bAddFirstCategoryDate) $dplArticle->mDate = $row->cl_timestamp;
24752488 elseif ($bAddEditDate && isset($row->rev_timestamp)) $dplArticle->mDate = $row->rev_timestamp;
24762489 elseif ($bAddEditDate && isset($row->page_touched)) $dplArticle->mDate = $row->page_touched;
 2490+
 2491+ // time zone adjustment
 2492+ if ($dplArticle->mDate!='') {
 2493+ $dplArticle->mDate= date('YmdHis',strtotime($dplArticle->mDate)-$timeCorrection);
 2494+ }
24772495
24782496 if ($dplArticle->mDate!='' && $sUserDateFormat!='') {
24792497 // we apply the userdateformat
@@ -2488,7 +2506,7 @@
24892507
24902508 //USER/AUTHOR(S)
24912509 // because we are going to do a recursive parse at the end of the output phase
2492 - // we have to generate wiki syntax for linking to a user�s homepage
 2510+ // we have to generate wiki syntax for linking to a user�s homepage
24932511 if($bAddUser || $bAddAuthor || $bAddLastEditor || $sLastRevisionBefore.$sAllRevisionsBefore.$sFirstRevisionSince.$sAllRevisionsSince != '') {
24942512 $dplArticle->mUserLink = '[[User:'.$row->rev_user_text.'|'.$row->rev_user_text.']]';
24952513 $dplArticle->mUser = $row->rev_user_text;
@@ -2652,7 +2670,7 @@
26532671 ExtDynamicPageList::$createdLinks[3][$imgid] = $imgid;
26542672 }
26552673 }
2656 -
 2674+
26572675 return $output;
26582676
26592677 }
@@ -2756,5 +2774,27 @@
27572775 return false;
27582776 }
27592777
 2778+ private static function getTimeCorrection($user) {
 2779+ $i=strtotime('20000101 00:00:00');
 2780+ $corr = $user->getOption('timecorrection','00:00').':00';
 2781+ if ($corr[0]=='-') {
 2782+ return strtotime('20000101 '.substr($corr,1)) - $i;
 2783+ }
 2784+ else {
 2785+ return $i - strtotime('20000101 '.$corr);
 2786+ }
 2787+ }
 2788+
 2789+ private static function resolveUrlArg($input,$arg) {
 2790+ global $wgRequest;
 2791+ $dplArg = $wgRequest->getVal($arg,'');
 2792+ if ($dplArg=='') {
 2793+ $input=preg_replace('/\{%'.$arg.':(.*)%\}/U', '\1' ,$input);
 2794+ return str_replace('{%'.$arg.'%}', '' ,$input);
 2795+ } else {
 2796+ $input=preg_replace('/\{%'.$arg.':.*%\}/U ', $dplArg ,$input);
 2797+ return str_replace('{%'.$arg.'%}' , $dplArg ,$input);
 2798+ }
 2799+ }
27602800 }
27612801
Index: trunk/extensions/DynamicPageList/DynamicPageListMigration.php
@@ -40,7 +40,7 @@
4141
4242 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
4343
44 -$DPLVersion = '1.8.1';
 44+$DPLVersion = '1.8.3';
4545
4646 $wgExtensionCredits['parserhook'][] = array(
4747 'path' => __FILE__,

Follow-up revisions

RevisionCommit summaryAuthorDate
r51881Follow-up r51852, fix text encoding issues.shinjiman11:24, 15 June 2009

Comments

#Comment by Nikerabbit (talk | contribs)   16:49, 14 June 2009

There seems to be new and existing text encoding problems.

#Comment by Shinjiman (talk | contribs)   11:26, 15 June 2009

Fixed in r51881.

I think maybe need to ask User:Algorithmix (the original author of this extension) about the encoding issue of the source file, and some files are not encoding by UTF-8. :(

Status & tagging log