Revision: 51852
Author:   shinjiman
Date:     2009-06-14 16:07:50 +0000 (Sun, 14 Jun 2009)

Log Message:
-----------
Update the DPL codebase to 1.8.3.
code based on Gero aka Algorithmix

Modified Paths:
--------------
    trunk/extensions/DynamicPageList/DPLMain.php
    trunk/extensions/DynamicPageList/DPLSetup.php
    trunk/extensions/DynamicPageList/DynamicPageList.php
    trunk/extensions/DynamicPageList/DynamicPageListMigration.php

Modified: trunk/extensions/DynamicPageList/DPLMain.php
===================================================================
--- trunk/extensions/DynamicPageList/DPLMain.php        2009-06-14 14:40:31 UTC 
(rev 51851)
+++ trunk/extensions/DynamicPageList/DPLMain.php        2009-06-14 16:07:50 UTC 
(rev 51852)
@@ -11,6 +11,9 @@
     // The real callback function for converting the input text to wiki text 
output
     public static function dynamicPageList( $input, $params, &$parser, 
&$bReset, $calledInMode ) {
 
+        // Output
+        $output = '';
+
         error_reporting(E_ALL);
 
         global $wgUser, $wgContLang, $wgRequest, $wgRawHtml;
@@ -74,16 +77,9 @@
         
                // check parameters which can be set via the URL
 
-               if (strpos($input,'{%DPL_')!== false) {
+               if (strpos($input,'{%DPL_') >= 0) {
                        for($i=1;$i<=5;$i++) {
-                               $dplArg = $wgRequest->getVal('DPL_arg'.$i,'');
-                               if ($dplArg=='') {
-                                       
$input=preg_replace('/\{%DPL_arg'.$i.':(.*)%\}/U', '\1'    ,$input);
-                                       
$input=preg_replace('/\{%DPL_arg'.$i.'%\}/U',      '\1'    ,$input);
-                               } else {
-                                       
$input=preg_replace('/\{%DPL_arg'.$i.':.*%\}/U  ', $dplArg ,$input);
-                                       $input=str_replace('{%DPL_arg'.$i.'%}'  
         , $dplArg ,$input);
-                               }
+                               $input = 
self::resolveUrlArg($input,'DPL_arg'.$i);
                        }
                }
 
@@ -94,7 +90,8 @@
                $iCount = -1;
                
                // commandline parameters like %DPL_offset% are replaced
-               $input = str_replace('{%DPL_offset%}',$iOffset,$input);
+               $input = self::resolveUrlArg($input,'DPL_offset');
+               $input = self::resolveUrlArg($input,'DPL_count');
 
                $originalInput = $input;
 
@@ -126,13 +123,14 @@
                // execAndExit
         $sExecAndExit= ExtDynamicPageList::$options['execandexit']['default'];
 
-               // ordermethod, order, mode, userdateformat:
+               // ordermethod, order, mode, userdateformat, allowcachedresults:
                // if we have to behave like Extension:Intersection we use 
different default values for some commands
                if (ExtDynamicPageList::$behavingLikeIntersection) {
                        ExtDynamicPageList::$options['ordermethod'] = 
array('default' => 'categoryadd', 'categoryadd', 'lastedit');
                        ExtDynamicPageList::$options['order'] = array('default' 
=> 'descending', 'ascending', 'descending');
                        ExtDynamicPageList::$options['mode'] = array('default' 
=> 'unordered', 'none', 'ordered', 'unordered');
                        ExtDynamicPageList::$options['userdateformat'] = 
array('default' => 'Y-m-d: ');
+                       
ExtDynamicPageList::$options['allowcachedresults']['default'] = 'true';
                }
                else {
                        ExtDynamicPageList::$options['ordermethod'] = 
array('default' => 'title', 'counter', 'size', 'category', 'sortkey', 
@@ -142,6 +140,7 @@
                        ExtDynamicPageList::$options['order'] = array('default' 
=> 'ascending', 'ascending', 'descending');
                        ExtDynamicPageList::$options['mode'] = array('default' 
=> 'unordered', 'category', 'inline', 'none', 'ordered', 'unordered', 
'userformat');
                        ExtDynamicPageList::$options['userdateformat'] = 
array('default' => 'Y-m-d H:i: ');
+                       
ExtDynamicPageList::$options['allowcachedresults']['default'] = 
ExtDynamicPageList::$respectParserCache;
                }
                $aOrderMethods          = 
array(ExtDynamicPageList::$options['ordermethod']['default']);
         $sOrder                        = 
ExtDynamicPageList::$options['order']['default'];
@@ -305,9 +304,6 @@
         $sUpdateRules = ExtDynamicPageList::$options['updaterules']['default'];
         $sDeleteRules = ExtDynamicPageList::$options['deleterules']['default'];
 
-        // Output
-        $output = '';
-               
 
     // ###### PARSE PARAMETERS ######
     
@@ -315,10 +311,10 @@
         $input = str_replace('»','>',$input);
         $input = str_replace('«','<',$input);
     
-        // use the \xA6 as a general alias for |
+        // use the � as a general alias for |
         $input = str_replace('¦','|',$input); // the symbol is utf8-escaped
     
-        // the combination '\xB2{' and '}\xB2'will be translated to double 
curly braces; this allows postponed template execution
+        // the combination '�{' and '}�'will be translated to double curly 
braces; this allows postponed template execution
         // which is crucial for DPL queries which call other DPL queries
         $input = str_replace('²{','{{',$input);
         $input = str_replace('}²','}}',$input);
@@ -572,7 +568,7 @@
                 case 'execandexit':
                     // we offer a possibility to execute a DPL command without 
querying the database
                                        // this is useful if you want to catch 
the command line parameters DPL_arg1,... etc
-                    return $sArg;
+                    $sExecAndExit = $sArg;
                     break;
                                 
                                 
@@ -945,7 +941,6 @@
                         $bSelectionCriteriaFound=true;
                         $bConflictsWithOpenReferences=true;
                         $bAllowCachedResults = true;
-                                               $parser->disableCache(false);
                     }
                     break;
                 
@@ -1203,7 +1198,6 @@
                                $bAllowCachedResults = true;
                                $bWarnCachedResults = true;
                         }
-                                               if ($bAllowCachedResults) 
$parser->disableCache();
                     }
                     else
                         $output .= 
$logger->msgWrongParam('allowcachedresults', $sArg);
@@ -1445,8 +1439,21 @@
                        // justify limits;
                        $iCount = ExtDynamicPageList::$maxResultCount;  
                }
+
+
+           // disable parser cache     if caching is not allowed (which is 
default for DPL but not for <DynamicPageList>)      
+        if ( !$bAllowCachedResults) {
+                       $parser->disableCache();
+               }
+        // place cache warning in resultsheader                
+        if ($bWarnCachedResults) $sResultsHeader = '{{DPL Cache Warning}}' . 
$sResultsHeader;
                
         
+               
+        if ($sExecAndExit != '') return $sExecAndExit;
+
+               
+               
                // if Caching is desired AND if the cache is up to date: get 
result from Cache and exit
 
                global $wgUploadDirectory, $wgRequest;
@@ -1492,10 +1499,7 @@
         $iTotalIncludeCatCount = count($aIncludeCategories, COUNT_RECURSIVE) - 
$iIncludeCatCount;
         $iExcludeCatCount = count($aExcludeCategories);
         $iTotalCatCount = $iTotalIncludeCatCount + $iExcludeCatCount;
-    
-        // place cache warning in resultsheader                
-        if ($bWarnCachedResults) $sResultsHeader = '{{DPL Cache Warning}}' . 
$sResultsHeader;
-    
+        
         if ($calledInMode=='tag') {
             // in tag mode 'eliminate' is the same as 'reset' for tpl,cat,img
             if ($bReset[5]) { $bReset[1] = true; $bReset[5] = false; }
@@ -1519,7 +1523,8 @@
         }
 
 
-    // ###### CHECKS ON PARAMETERS ######
+               // ###### CHECKS ON PARAMETERS ######
+               
         // too many categories!
         if ( ($iTotalCatCount > ExtDynamicPageList::$maxCategoryCount) && 
(!ExtDynamicPageList::$allowUnlimitedCategories) )
             return $output . $logger->escapeMsg(DPL_i18n::FATAL_TOOMANYCATS, 
ExtDynamicPageList::$maxCategoryCount);
@@ -1723,16 +1728,19 @@
                     // deleted because of conflict with revsion-parameters
                     $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 )';
                     break;
+                case 'pagetouched':
+                                               $sSqlPage_touched = ", 
$sPageTable.page_touched as page_touched";
+                                               break;
                 case 'lastedit':
-                                       if ($bAddUser) {
+                                       if 
(ExtDynamicPageList::$behavingLikeIntersection) {
+                                               $sSqlPage_touched = ", 
$sPageTable.page_touched as page_touched";
+                                       }
+                                       else {
                                                $sSqlRevisionTable = 
$sRevisionTable . ' AS rev, ';
                                                $sSqlRev_timestamp = ', 
rev_timestamp';
                                                // deleted because of conflict 
with revision-parameters
                                                $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 )';
                                        }
-                                       else {
-                                               $sSqlPage_touched = ", 
$sPageTable.page_touched as page_touched";
-                                       }
                     break;
                 case 'sortkey':
                     // We need the namespaces with strictly positive indices 
(DPL allowed namespaces, except the first one: Main).
@@ -2040,7 +2048,7 @@
             $sSqlPage_counter = ", $sPageTable.page_counter as page_counter";
         if ($bAddPageSize)
             $sSqlPage_size = ", $sPageTable.page_len as page_len";
-        if ($bAddPageTouchedDate)
+        if ($bAddPageTouchedDate && $sSqlPage_touched=='')
             $sSqlPage_touched = ", $sPageTable.page_touched as page_touched";
         if ($bAddUser || $bAddAuthor || $bAddLastEditor || $sSqlRevisionTable 
!= '')
             $sSqlRev_user = ', rev_user, rev_user_text';
@@ -2262,7 +2270,9 @@
                         $sSqlWhere .= 'rev_timestamp';
                         break;
                     case 'lastedit':
-                        $sSqlWhere .= 'page_touched';
+                                               // extension:intersection used 
to sort by page_touched although the field is called 'lastedit'
+                                               if 
(ExtDynamicPageList::$behavingLikeIntersection)      $sSqlWhere .= 
'page_touched';
+                                               else                            
                                                                $sSqlWhere .= 
'rev_timestamp';
                         break;
                     case 'pagetouched':
                         $sSqlWhere .= 'page_touched';
@@ -2363,7 +2373,10 @@
             }
         }
     
-        
+
+               // find user's time correction
+               $timeCorrection = self::getTimeCorrection($wgUser);
+
         $iArticle = 0;
     
         while( $row = $dbr->fetchObject ( $res ) ) {
@@ -2473,6 +2486,11 @@
                 elseif ($bAddFirstCategoryDate)                                
                        $dplArticle->mDate = $row->cl_timestamp;
                 elseif ($bAddEditDate && isset($row->rev_timestamp))   
$dplArticle->mDate = $row->rev_timestamp;
                 elseif ($bAddEditDate && isset($row->page_touched))            
$dplArticle->mDate = $row->page_touched;
+                               
+                               // time zone adjustment
+                if ($dplArticle->mDate!='') {
+                                       $dplArticle->mDate= 
date('YmdHis',strtotime($dplArticle->mDate)-$timeCorrection);
+                               }
                 
                 if ($dplArticle->mDate!='' && $sUserDateFormat!='') {
                                        // we apply the userdateformat
@@ -2488,7 +2506,7 @@
                 
                 //USER/AUTHOR(S)
                 // because we are going to do a recursive parse at the end of 
the output phase
-                // we have to generate wiki syntax for linking to a user\xB4s 
homepage
+                // we have to generate wiki syntax for linking to a user�s 
homepage
                 if($bAddUser || $bAddAuthor || $bAddLastEditor || 
$sLastRevisionBefore.$sAllRevisionsBefore.$sFirstRevisionSince.$sAllRevisionsSince
 != '') {
                     $dplArticle->mUserLink  = 
'[[User:'.$row->rev_user_text.'|'.$row->rev_user_text.']]';
                     $dplArticle->mUser = $row->rev_user_text;
@@ -2652,7 +2670,7 @@
                 ExtDynamicPageList::$createdLinks[3][$imgid] = $imgid;
             }
         }
-    
+
         return $output;
         
     }
@@ -2756,5 +2774,27 @@
                return false; 
        }       
        
+       private static function getTimeCorrection($user) {
+               $i=strtotime('20000101 00:00:00');
+               $corr = $user->getOption('timecorrection','00:00').':00';
+               if ($corr[0]=='-') {
+                       return strtotime('20000101 '.substr($corr,1)) - $i;
+               }
+               else {
+                       return $i - strtotime('20000101 '.$corr);
+               }
+       }
+
+       private static function resolveUrlArg($input,$arg) {
+               global $wgRequest;
+               $dplArg = $wgRequest->getVal($arg,'');
+               if ($dplArg=='') {
+                       $input=preg_replace('/\{%'.$arg.':(.*)%\}/U', '\1'    
,$input);
+                       return str_replace('{%'.$arg.'%}',                   '' 
      ,$input);
+               } else {
+                       $input=preg_replace('/\{%'.$arg.':.*%\}/U  ', $dplArg 
,$input);
+                       return str_replace('{%'.$arg.'%}'           , $dplArg 
,$input);
+               }
+       }
 }
 

Modified: trunk/extensions/DynamicPageList/DPLSetup.php
===================================================================
--- trunk/extensions/DynamicPageList/DPLSetup.php       2009-06-14 14:40:31 UTC 
(rev 51851)
+++ trunk/extensions/DynamicPageList/DPLSetup.php       2009-06-14 16:07:50 UTC 
(rev 51852)
@@ -27,7 +27,7 @@
  *          addcategories: bug fixed
  *          CATLIST variable defined
  * @version 0.9.3
- *          allow \xA6 as an alias for |
+ *          allow ?as an alias for |
  *          escapelinks= introduced
  * @version 0.9.4
  *          allow "-" with categories = 
@@ -314,8 +314,15 @@
  * @version 1.8.1
  *                     bugfix: %DATE% was not expanded when addedit=true and 
ordermethod=lastedit were chosen
  *                     bugfix: allrevisionssince delivered wrong results
+ * @version 1.8.2
+ *                     bugfix: ordermethod=lastedit AND minoredits=exclude 
produced a SQL error
+
+ *                     bugfix dplcache
+ *                     config switch: respectParserCache
+ *                     date timestamp adapt to user preferences
+ * @version 1.8.3
+ *                     bugfix: URL variable expansion
  
- 
  *             ! when making changes here you must update the version field in 
DynamicPageList.php and DynamicPageListMigration.php !
  */
 
@@ -351,6 +358,8 @@
        public  static $behavingLikeIntersection = false; // Changes certain 
default values to comply with Extension:Intersection
        public  static $functionalRichness               = 0;     // The amount 
of functionality of DPL that is accesible for the user;
                                                                                
                          // .. to be set by DynamicPageList.php and 
DynamicPageListMigration.php
+    public  static $respectParserCache          = false; // false = make page 
dynamic ; true = execute only when parser cache is refreshed
+                                                                               
                          // .. to be changed in LocalSettings.php
 
     /**
      * Map parameters to possible values.
@@ -369,7 +378,9 @@
         'addpagesize'          => array('default' => 'false', 'true', 'no', 
'yes', '0', '1', 'off', 'on'),
         'addpagetoucheddate'   => array('default' => 'false', 'true', 'no', 
'yes', '0', '1', 'off', 'on'),
         'adduser'              => array('default' => 'false', 'true', 'no', 
'yes', '0', '1', 'off', 'on'),
-        'allowcachedresults'   => array('default' => 'false', 'true', 'no', 
'yes', '0', '1', 'off', 'on', 'yes+warn'),
+               
+               // default of allowchacheresults depends on behaveasIntersetion 
and on LopcalSettings ...
+        'allowcachedresults'   => array( 'true', 'false', 'no', 'yes', 
'yes+warn', '0', '1', 'off', 'on'),
         /**
          * search for a page with the same title in another namespace (this is 
normally the article to a talk page)
          */
@@ -533,7 +544,7 @@
         /**
          * listseparators is an array of four tags (in html or wiki syntax) 
which defines the output of DPL
          * if mode = 'userformat' was specified.
-         *   '\n' or '\xB6'  in the input will be interpreted as a newline 
character.
+         *   '\n' or '?  in the input will be interpreted as a newline 
character.
          *   '%xxx%'      in the input will be replaced by a corresponding 
value (xxx= PAGE, NR, COUNT etc.)
          * t1 and t4 are the "outer envelope" for the whole result list, 
          * t2,t3 form an inner envelope around the article name of each entry.
@@ -863,6 +874,7 @@
                                        suppresserrors
                                        ',
                        1 =>    '
+                                       allowcachedresults
                                        execandexit
                                        columns
                                        debug
@@ -899,7 +911,6 @@
                                        addpagesize
                                        addpagetoucheddate
                                        adduser
-                                       allowcachedresults
                                        categoriesminmax
                                        createdby
                                        dominantsection
@@ -1146,7 +1157,7 @@
         $numargs = func_num_args();
         if ($numargs < 2) {
           $input = "#dpl: no arguments specified";
-          return 
str_replace('\xA7','<','\xA7pre>\xA7nowiki>'.$input.'\xA7/nowiki>\xA7/pre>');
+          return 
str_replace('?,'<','\xA7pre>\xA7nowiki>'.$input.'?nowiki>?pre>');
         }
         
         // fetch all user-provided arguments (skipping $parser)
@@ -1156,7 +1167,7 @@
           $input .= str_replace("\n","",$p1) ."\n";
         }
         // for debugging you may want to uncomment the following statement
-        // return 
str_replace('\xA7','<','\xA7pre>\xA7nowiki>'.$input.'\xA7/nowiki>\xA7/pre>');
+        // return 
str_replace('?,'<','\xA7pre>\xA7nowiki>'.$input.'?nowiki>?pre>');
     
         
         // $dump1   = self::dumpParsedRefs($parser,"before DPL func");

Modified: trunk/extensions/DynamicPageList/DynamicPageList.php
===================================================================
--- trunk/extensions/DynamicPageList/DynamicPageList.php        2009-06-14 
14:40:31 UTC (rev 51851)
+++ trunk/extensions/DynamicPageList/DynamicPageList.php        2009-06-14 
16:07:50 UTC (rev 51852)
@@ -59,7 +59,7 @@
 
 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
 
-$DPLVersion = '1.8.1';
+$DPLVersion = '1.8.3';
 
 $wgExtensionCredits['parserhook'][] = array(
        'path'           => __FILE__,

Modified: trunk/extensions/DynamicPageList/DynamicPageListMigration.php
===================================================================
--- trunk/extensions/DynamicPageList/DynamicPageListMigration.php       
2009-06-14 14:40:31 UTC (rev 51851)
+++ trunk/extensions/DynamicPageList/DynamicPageListMigration.php       
2009-06-14 16:07:50 UTC (rev 51852)
@@ -40,7 +40,7 @@
 
 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList__languageGetMagic';
 
-$DPLVersion = '1.8.1';
+$DPLVersion = '1.8.3';
 
 $wgExtensionCredits['parserhook'][] = array(
        'path'           => __FILE__,



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to