r50814 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50813‎ | r50814 | r50815 >
Date:08:12, 20 May 2009
Author:shinjiman
Status:deferred
Tags:
Comment:
update the DPL codebase to 1.7.8
Modified paths:
  • /trunk/extensions/DynamicPageList/DynamicPageList2.php (modified) (history)
  • /trunk/extensions/DynamicPageList/DynamicPageList2Include.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DynamicPageList/DynamicPageList2.php
@@ -282,7 +282,16 @@
283283 * CATBULLETS variable
284284 * @version 1.7.6
285285 * error correction: non existing array index 0 when trying to includematch content in a non-existing chapter (near #3887)
286 - *
 286+ * @version 1.7.7
 287+ * configuration switch allows to run DPL from protected pages only (ExtDynamicPageList2::$options['RunFromProtectedPagesOnly'])
 288+ * @version 1.7.8
 289+ * allow html/wiki comments within template parameter assignments (include statement, line 540ff of DynamicPageList2Include.php)
 290+ * accept include=* together with table=
 291+ * Bugfix: %PAGES% was wrong (showing total pages in some cases
 292+ * Bugfix: labeled section inclusion did not work because content was automatically truncated to a length of zero
 293+ * added minrevisions & maxrevisions
 294+ * @version 1.7.9
 295+ * ...
287296 * ! when making changes here you must update the VERSION constant at the beginning of class ExtDynamicPageList2 !
288297 */
289298
@@ -299,9 +308,10 @@
300309 $wgHooks['LanguageGetMagic'][] = 'ExtDynamicPageList2__languageGetMagic';
301310
302311 $wgExtensionCredits['parserhook'][] = array(
303 - 'path' => __FILE__,
304 - 'name' => 'DynamicPageList2',
305 - 'author' => array( "[http://en.wikinews.org/wiki/User:IlyaHaykinson IlyaHaykinson]", "[http://en.wikinews.org/wiki/User:Amgine Amgine]", "[http://de.wikipedia.org/wiki/Benutzer:Unendlich Unendlich]", "[http://meta.wikimedia.org/wiki/User:Dangerman Cyril Dangerville]", "[http://de.wikipedia.org/wiki/Benutzer:Algorithmix Algorithmix]" ),
 312+ 'name' => 'DynamicPageList',
 313+ 'author' => '[http://en.wikinews.org/wiki/User:IlyaHaykinson IlyaHaykinson], [http://en.wikinews.org/wiki/User:Amgine Amgine],'
 314+ .'[http://de.wikipedia.org/wiki/Benutzer:Unendlich Unendlich], [http://meta.wikimedia.org/wiki/User:Dangerman Cyril Dangerville], '
 315+ .'[http://de.wikipedia.org/wiki/Benutzer:Algorithmix Algorithmix]',
306316 'url' => 'http://www.mediawiki.org/wiki/Extension:DynamicPageList',
307317 'description' => 'a highly flexible report generator for MediaWikis - manual and examples: see [http://semeb.com/dpldemo]',
308318 'version' => ExtDynamicPageList2::VERSION
@@ -320,7 +330,7 @@
321331
322332 class ExtDynamicPageList2
323333 {
324 - const VERSION = '1.7.6'; // current version
 334+ const VERSION = '1.7.8'; // current version
325335
326336 /**
327337 * Extension options
@@ -689,6 +699,11 @@
690700 */
691701 'allrevisionssince' => array('default' => '', 'pattern' => '#^[-./:0-9]+$#'),
692702 /**
 703+ * Minimum/Maximum number of revisions required
 704+ */
 705+ 'minrevisions' => array('default' => '', 'pattern' => '/^\d*$/'),
 706+ 'maxrevisions' => array('default' => '', 'pattern' => '/^\d*$/'),
 707+ /**
693708 * noresultsheader / footer is some wiki text which will be output (instead of a warning message)
694709 * if the result set is empty; setting 'noresultsheader' to something like ' ' will suppress
695710 * the warning about empty result set.
@@ -792,6 +807,10 @@
793808 'titlemaxlength' => array('default' => '', 'pattern' => '/^\d*$/')
794809 );
795810
 811+ // Note: If you add a line like the followin to your LocalSetings.php, DPL will only run from protected pages
 812+ // ExtDynamicPageList2::$options['RunFromProtectedPagesOnly'] = "<small><i>Extension DPL (warning): current configuration allows execution from protected pages only.</i></small>";
 813+
 814+
796815 public static $debugMinLevels = array();
797816 public static $createdLinks; // the links created by DPL are collected here;
798817 // they can be removed during the final ouput
@@ -1110,7 +1129,13 @@
11111130 $localParser = new Parser();
11121131 $pOptions = $parser->mOptions;
11131132 $pTitle = $parser->mTitle;
1114 -
 1133+
 1134+ // check if DPL shall only be executed from protected pages
 1135+ if (array_key_exists('RunFromProtectedPagesOnly',self::$options) &&
 1136+ self::$options['RunFromProtectedPagesOnly']==true && !($parser->mTitle->isProtected('edit'))) {
 1137+ return (self::$options['RunFromProtectedPagesOnly']);
 1138+ }
 1139+
11151140 // get database access
11161141 $dbr =& wfGetDB( DB_SLAVE );
11171142 $sPageTable = $dbr->tableName( 'page' );
@@ -1169,7 +1194,12 @@
11701195 $sAllRevisionsBefore = self::$options['allrevisionsbefore']['default'];
11711196 $sFirstRevisionSince = self::$options['firstrevisionsince']['default'];
11721197 $sAllRevisionsSince = self::$options['allrevisionssince']['default'];
1173 -
 1198+
 1199+ $_sMinRevisions = self::$options['minrevisions']['default'];
 1200+ $iMinRevisions = ($_sMinRevisions == '') ? NULL: intval($_sMinRevisions);
 1201+ $_sMaxRevisions = self::$options['maxrevisions']['default'];
 1202+ $iMaxRevisions = ($_sMaxRevisions == '') ? NULL: intval($_sMaxRevisions);
 1203+
11741204 $sRedirects = self::$options['redirects']['default'];
11751205
11761206 $bSuppressErrors = self::argBoolean(self::$options['suppresserrors']['default']);
@@ -1221,7 +1251,7 @@
12221252
12231253
12241254 $aSecLabels = array();
1225 - if($bIncPage && $_incpage != '*') $aSecLabels = explode(',', $_incpage);
 1255+ if($bIncPage) $aSecLabels = explode(',', $_incpage);
12261256 $aSecLabelsMatch = array();
12271257 $aSecLabelsNotMatch = array();
12281258 $bIncParsed = false; // default is to match raw parameters
@@ -1718,7 +1748,22 @@
17191749 else // wrong value
17201750 $output .= $logger->msgWrongParam($sType, $sArg);
17211751 break;
 1752+ case 'minrevisions':
 1753+ //ensure that $iMinRevisions is a number
 1754+ if( preg_match(self::$options['minrevisions']['pattern'], $sArg) )
 1755+ $iMinRevisions = ($sArg == '') ? NULL: intval($sArg);
 1756+ else // wrong value
 1757+ $output .= $logger->msgWrongParam('minrevisions', $sArg);
 1758+ break;
 1759+ case 'maxrevisions':
 1760+ //ensure that $iMaxRevisions is a number
 1761+ if( preg_match(self::$options['maxrevisions']['pattern'], $sArg) )
 1762+ $iMaxRevisions = ($sArg == '') ? NULL: intval($sArg);
 1763+ else // wrong value
 1764+ $output .= $logger->msgWrongParam('maxrevisions', $sArg);
 1765+ break;
17221766
 1767+
17231768 case 'openreferences':
17241769 if( in_array($sArg, self::$options['openreferences']) )
17251770 $acceptOpenReferences = self::argBoolean($sArg);
@@ -1855,7 +1900,7 @@
18561901 case 'include':
18571902 case 'includepage':
18581903 $bIncPage = $sArg !== '';
1859 - if($bIncPage && $sArg != '*')
 1904+ if($bIncPage)
18601905 $aSecLabels= explode(',', $sArg);
18611906 break;
18621907
@@ -2928,6 +2973,13 @@
29292974 // page_id=rev_page (if revision table required)
29302975 $sSqlWhere .= $sSqlCond_page_rev;
29312976
 2977+ if ($iMinRevisions != NULL) {
 2978+ $sSqlWhere .= " and ((select count(rev_aux2.rev_page) from revision as rev_aux2 where rev_aux2.rev_page=page.page_id) >= $iMinRevisions)";
 2979+ }
 2980+ if ($iMaxRevisions != NULL) {
 2981+ $sSqlWhere .= " and ((select count(rev_aux3.rev_page) from revision as rev_aux3 where rev_aux3.rev_page=page.page_id) <= $iMaxRevisions)";
 2982+ }
 2983+
29322984 // count(all categories) <= max no of categories
29332985 $sSqlWhere .= $sSqlCond_MaxCat;
29342986
@@ -3258,14 +3310,14 @@
32593311 $dpl2result = $dpl->getText();
32603312 $header='';
32613313 if ($sOneResultHeader != '' && $rowcount==1) {
3262 - $header = str_replace('%PAGES%',1,$sOneResultHeader);
 3314+ $header = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',1,$sOneResultHeader));
32633315 } else if ($rowcount==0) {
32643316 if ($sNoResultsHeader != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsHeader));
32653317 if ($sNoResultsFooter != '') $output .= str_replace( '\n', "\n", str_replace( "¶", "\n", $sNoResultsFooter));
32663318 if ($sNoResultsHeader == '' && $sNoResultsFooter == '') $output .= $logger->escapeMsg(DPL2_i18n::WARN_NORESULTS);
32673319 }
32683320 else {
3269 - if ($sResultsHeader != '') $header = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',$rowcount,$sResultsHeader));
 3321+ if ($sResultsHeader != '') $header = str_replace('%TOTALPAGES%',$rowcount,str_replace('%PAGES%',$dpl->getRowCount(),$sResultsHeader));
32703322 }
32713323 $header = str_replace( '\n', "\n", str_replace( "¶", "\n", $header ));
32723324 $header = str_replace('%VERSION%', self::VERSION,$header);
@@ -3785,6 +3837,7 @@
37863838 $rBody='';
37873839 // the following statement caused a problem with multiple columns: $this->filteredCount = 0;
37883840 for ($i = $iStart; $i < $iStart+$iCount; $i++) {
 3841+
37893842 $article = $this->mArticles[$i];
37903843 $pagename = $article->mTitle->getPrefixedText();
37913844 if ($this->mEscapeLinks && ($article->mNamespace==14 || $article->mNamespace==6) ) {
@@ -3796,7 +3849,7 @@
37973850
37983851 if ($this->mIncPage) {
37993852 $matchFailed=false;
3800 - if(empty($this->mIncSecLabels)) { // include whole article
 3853+ if(empty($this->mIncSecLabels) || $this->mIncSecLabels[0]=='*') { // include whole article
38013854 $title = $article->mTitle->getPrefixedText();
38023855 if ($mode->name == 'userformat') $incwiki = '';
38033856 else $incwiki = '<br/>';
@@ -3823,7 +3876,13 @@
38243877 }
38253878 else {
38263879 // append full text to output
3827 - $incwiki .= $text;
 3880+ if (array_key_exists('0',$mode->sSectionTags)){
 3881+ $incwiki .= $this->substTagParm($mode->sSectionTags[0], $pagename, $article,$this->filteredCount, $iTitleMaxLen);
 3882+ $pieces = array(0=>$text);
 3883+ $this->formatSingleItems(&$pieces, 0);
 3884+ $incwiki .= $pieces[0];
 3885+ }
 3886+ else $incwiki .= $text;
38283887 }
38293888 }
38303889 else {
@@ -4002,7 +4061,7 @@
40034062 if($article->mUserLink != '') $rBody .= ' . . [[User:' . $article->mUser .'|'.$article->mUser.']]';
40044063 if($article->mContributor != '')$rBody .= ' . . [[User:' . $article->mContributor .'|'.$article->mContributor." $article->mContrib]]";
40054064
4006 - if( !empty($article->mCategoryLinks) ) $rBody .= ' . . <small>' . wfMsg('categories') . ': ' . $wgLang->pipeList( $article->mCategoryLinks ) . '</small>';
 4065+ if( !empty($article->mCategoryLinks) ) $rBody .= ' . . <small>' . wfMsg('categories') . ': ' . implode(' | ', $article->mCategoryLinks) . '</small>';
40074066 }
40084067
40094068 // add included contents
Index: trunk/extensions/DynamicPageList/DynamicPageList2Include.php
@@ -82,6 +82,10 @@
8383 * allow % within included template parameters
8484 * @version 1.7.3
8585 * %SECTION% can now be used within multiseseparators (see includeHeading)
 86+ * @version 1.7.8
 87+ * allow html/wiki comments within template parameter assignments (include statement, line 540ff of DynamicPageList2Include.php)
 88+ * @version 1.7.9
 89+ * bug fix (near line #150): section inclusion did not work because all content was truncated to 0 bytes
8690
8791 */
8892
@@ -125,12 +129,14 @@
126130 private static function parse($parser, $title, $text, $part1, $skiphead=0, $recursionCheck=true, $maxLength=-1, $link='', $trim=false)
127131 {
128132 global $wgVersion;
129 -
 133+
130134 // if someone tries something like<section begin=blah>lst only</section>
131135 // text, may as well do the right thing.
132136 $text = str_replace('</section>', '', $text);
133 -
 137+
 138+
134139 if (self::open($parser, $part1)) {
 140+
135141
136142 //Handle recursion here, so we can break cycles. Although we can't do
137143 //feature detection here, r18473 was only a few weeks before the
@@ -141,7 +147,7 @@
142148 self::close($parser, $part1);
143149 }
144150
145 - if ($maxLength>=0) {
 151+ if ($maxLength>0) {
146152 $text = self::limitTranscludedText($text,$maxLength,$link);
147153 }
148154 if ($trim) return trim($text);
@@ -230,7 +236,7 @@
231237 }
232238 $any=false;
233239 $pat = self::createSectionPattern($sec,$to,$any);
234 -
 240+
235241 preg_match_all( $pat, $text, $m, PREG_PATTERN_ORDER);
236242
237243 foreach ($m[2] as $nr=>$piece) {
@@ -541,9 +547,9 @@
542548 // named parameter
543549 $exParmQuote = str_replace('/','\/',$exParm);
544550 foreach ($parms as $parm) {
545 - if (!preg_match("/^\s*$exParmQuote\s*=/",$parm)) continue;
 551+ if (!preg_match("/^\s*$exParmQuote\s*(<!--.*-->)*\s*=/",$parm)) continue;
546552 $found=true;
547 - $output[$n] .= $dpl->formatTemplateArg(preg_replace("/^$exParmQuote\s*=\s*/","",$parm),$dplNr,$exParmKey,$firstCall,$maxlen);
 553+ $output[$n] .= $dpl->formatTemplateArg(preg_replace("/^$exParmQuote\s*(<!--.*-->)*\s*=\s*/","",$parm),$dplNr,$exParmKey,$firstCall,$maxlen);
548554 break;
549555 }
550556 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r50815follow up r50814, fixing up author and path detailsshinjiman08:18, 20 May 2009

Status & tagging log