From 842fef7c4dc3c07ea3a1a4499d41ea27b901c152 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 28 May 2005 11:09:22 +0000 Subject: [PATCH] basic support for special page inclusions --- includes/DefaultSettings.php | 6 ++ includes/OutputPage.php | 38 +++-------- includes/Parser.php | 96 ++++++++++++++++++---------- includes/SpecialAllpages.php | 102 ++++++++++++++++-------------- includes/SpecialContributions.php | 4 +- includes/SpecialPage.php | 71 +++++++++++++++++++-- includes/SpecialRecentchanges.php | 71 +++++++++++++-------- 7 files changed, 241 insertions(+), 147 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e2d361deb0..d8a6843ace 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1490,4 +1490,10 @@ $wgTrustedMediaFormats= array( #"application/x-shockwafe-flash", //flash/shockwave movie ); +/** + * Allow special page inclusions such as {{Special:Allpages}} + */ +$wgAllowSpecialInclusion = true; + + ?> diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 327271365a..879f5e8f13 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -219,6 +219,7 @@ class OutputPage { function addHTML( $text ) { $this->mBodytext .= $text; } function clearHTML() { $this->mBodytext = ''; } + function getHTML() { return $this->mBodytext; } function debug( $text ) { $this->mDebugtext .= $text; } function setParserOptions( $options ) { @@ -244,6 +245,9 @@ class OutputPage { $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions, $linestart ); $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); + if ( $parserOutput->getCacheTime() == -1 ) { + $this->enableClientCache( false ); + } $this->addHTML( $parserOutput->getText() ); } @@ -258,12 +262,15 @@ class OutputPage { $text = $parserOutput->getText(); - if ( $cacheArticle ) { + if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) { $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser ); } $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); + if ( $parserOutput->getCacheTime() == -1 ) { + $this->enableClientCache( false ); + } $this->addHTML( $text ); } @@ -467,35 +474,6 @@ class OutputPage { $wgOutputEncoding = strtolower( $wgOutputEncoding ); return; } - - /* - # This code is unused anyway! - # Commenting out. --bv 2003-11-15 - - $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] ); - $best = 0.0; - $bestset = "*"; - - foreach ( $a as $s ) { - if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) { - $set = $m[1]; - $q = (float)($m[2]); - } else { - $set = $s; - $q = 1.0; - } - if ( $q > $best ) { - $bestset = $set; - $best = $q; - } - } - #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; } - if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; } - $wgOutputEncoding = strtolower( $bestset ); - -# Disable for now -# - */ $wgOutputEncoding = $wgInputEncoding; } diff --git a/includes/Parser.php b/includes/Parser.php index 4dee7f277f..ca7340086f 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -83,7 +83,7 @@ define( 'EXT_IMAGE_REGEX', * settings: * $wgUseTex*, $wgUseDynamicDates*, $wgInterwikiMagic*, * $wgNamespacesWithSubpages, $wgAllowExternalImages*, - * $wgLocaltimezone + * $wgLocaltimezone, $wgAllowSpecialInclusion* * * * only within ParserOptions * @@ -2132,7 +2132,8 @@ class Parser } # Load from database - $itcamefromthedatabase = false; + $replaceHeadings = false; + $isHTML = false; $lastPathLevel = $this->mTemplatePath; if ( !$found ) { $ns = NS_TEMPLATE; @@ -2145,13 +2146,23 @@ class Parser # Check for excessive inclusion $dbk = $title->getPrefixedDBkey(); if ( $this->incrementIncludeCount( $dbk ) ) { - # This should never be reached. - $article = new Article( $title ); - $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals(); - if ( $articleContent !== false ) { - $found = true; - $text = $linestart . $articleContent; - $itcamefromthedatabase = true; + if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() ) { + # Capture special page output + $text = SpecialPage::capturePath( $title ); + if ( $text && !is_object( $text ) ) { + $found = true; + $noparse = true; + $isHTML = true; + $this->mOutput->setCacheTime( -1 ); + } + } else { + $article = new Article( $title ); + $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals(); + if ( $articleContent !== false ) { + $found = true; + $text = $linestart . $articleContent; + $replaceHeadings = true; + } } } @@ -2219,33 +2230,41 @@ class Parser wfProfileOut( $fname ); return $matches[0]; } else { - # replace ==section headers== - # XXX this needs to go away once we have a better parser. - if ( $this->mOutputType != OT_WIKI && $itcamefromthedatabase ) { - if( !is_null( $title ) ) - $encodedname = base64_encode($title->getPrefixedDBkey()); - else - $encodedname = base64_encode(""); - $m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, - PREG_SPLIT_DELIM_CAPTURE); - $text = ''; - $nsec = 0; - for( $i = 0; $i < count($m); $i += 2 ) { - $text .= $m[$i]; - if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue; - $hl = $m[$i + 1]; - if( strstr($hl, "" . $m2[3]; + + $nsec++; } - preg_match('/^(={1,6})(.*?)(={1,6})\s*?$/m', $hl, $m2); - $text .= $m2[1] . $m2[2] . "" . $m2[3]; - - $nsec++; } } } + # Prune lower levels off the recursion check path $this->mTemplatePath = $lastPathLevel; @@ -3122,7 +3141,7 @@ class Parser class ParserOutput { var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic; - var $mCacheTime; # Used in ParserCache + var $mCacheTime; # Timestamp on this article, or -1 for uncacheable. Used in ParserCache. var $mVersion; # Compatibility check var $mTitleText; # title text of the chosen language variant @@ -3170,7 +3189,8 @@ class ParserOutput */ function expired( $touched ) { global $wgCacheEpoch; - return $this->getCacheTime() <= $touched || + return $this->getCacheTime() == -1 || // parser says it's uncacheable + $this->getCacheTime() <= $touched || $this->getCacheTime() <= $wgCacheEpoch || !isset( $this->mVersion ) || version_compare( $this->mVersion, MW_PARSER_VERSION, "lt" ); @@ -3193,6 +3213,7 @@ class ParserOptions var $mDateFormat; # Date format index var $mEditSection; # Create "edit section" links var $mNumberHeadings; # Automatically number headings + var $mAllowSpecialInclusion; # Allow inclusion of special pages function getUseTeX() { return $this->mUseTeX; } function getUseDynamicDates() { return $this->mUseDynamicDates; } @@ -3202,6 +3223,8 @@ class ParserOptions function getDateFormat() { return $this->mDateFormat; } function getEditSection() { return $this->mEditSection; } function getNumberHeadings() { return $this->mNumberHeadings; } + function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } + function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); } function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } @@ -3210,6 +3233,7 @@ class ParserOptions function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); } function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); } function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); } + function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); } function setSkin( &$x ) { $this->mSkin =& $x; } @@ -3230,7 +3254,8 @@ class ParserOptions /** Get user options */ function initialiseFromUser( &$userInput ) { - global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; + global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages, + $wgAllowSpecialInclusion; $fname = 'ParserOptions::initialiseFromUser'; wfProfileIn( $fname ); if ( !$userInput ) { @@ -3250,6 +3275,7 @@ class ParserOptions $this->mDateFormat = $user->getOption( 'date' ); $this->mEditSection = $user->getOption( 'editsection' ); $this->mNumberHeadings = $user->getOption( 'numberheadings' ); + $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion; wfProfileOut( $fname ); } } diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php index b4142aad89..357f610d66 100644 --- a/includes/SpecialAllpages.php +++ b/includes/SpecialAllpages.php @@ -8,7 +8,7 @@ * Entry point : initialise variables and call subfunctions. * @param string $par Becomes "FOO" when called like Special:Allpages/FOO (default NULL) */ -function wfSpecialAllpages( $par=NULL ) { +function wfSpecialAllpages( $par=NULL, $specialPage ) { global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgContLang; # Config $indexMaxperpage = 480; @@ -36,11 +36,11 @@ function wfSpecialAllpages( $par=NULL ) { } if ( isset($par) ) { - indexShowChunk( $namespace, $par, $invert ); + indexShowChunk( $namespace, $par, $invert, $specialPage->including() ); } elseif ( isset($from) ) { - indexShowChunk( $namespace, $from, $invert ); + indexShowChunk( $namespace, $from, $invert, $specialPage->including() ); } else { - indexShowToplevel ( $namespace, $invert ); + indexShowToplevel ( $namespace, $invert, $specialPage->including() ); } } @@ -50,7 +50,7 @@ function wfSpecialAllpages( $par=NULL ) { * @param string $from Article name we are starting listing at. * @param bool $invert true if we want the namespaces inverted (default false) */ -function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert ) { +function indexNamespaceForm ( $namespace = NS_MAIN, $from = '', $invert = false ) { global $wgContLang, $wgScript; $t = Title::makeTitle( NS_SPECIAL, "Allpages" ); @@ -97,7 +97,7 @@ function namespaceForm ( $namespace = NS_MAIN, $from = '', $invert ) { * @param integer $namespace (default NS_MAIN) * @param bool $invert true if we want the namespaces inverted (default false) */ -function indexShowToplevel ( $namespace = NS_MAIN, $invert ) { +function indexShowToplevel ( $namespace = NS_MAIN, $invert = false, $including = false ) { global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser; $sk = $wgUser->getSkin(); $fname = "indexShowToplevel"; @@ -120,7 +120,7 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert ) { if ( $sections < 3 ) { # If there are only two or less sections, don't even display them. # Instead, display the first section directly. - indexShowChunk( $namespace, '', $invert ); + indexShowChunk( $namespace, '', $invert, $including ); return; } @@ -167,33 +167,37 @@ function indexShowToplevel ( $namespace = NS_MAIN, $invert ) { } $out .= ''; - $nsForm = namespaceForm ( $namespace, '', $invert ); - + $nsForm = indexNamespaceForm ( $namespace, '', $invert ); + # Is there more? - $morelinks = ''; - if ( $offset > 0 ) { - $morelinks = $sk->makeKnownLink ( - $wgContLang->specialPage ( 'Allpages' ), - wfMsg ( 'allpagesprev' ), - ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : '' - ); - } - if ( $stopat < $sections-1 ) { - if ( $morelinks != '' ) { $morelinks .= " | "; } - $morelinks .= $sk->makeKnownLink ( - $wgContLang->specialPage ( 'Allpages' ), - wfMsg ( 'allpagesnext' ), - 'offset=' . ($offset + $toplevelMaxperpage) - ); - } - - if ( $morelinks != '' ) { - $out2 = ''; - $out2 .= '
' . $nsForm; - $out2 .= ''; - $out2 .= $morelinks . '

'; + if ( $including ) { + $out2 = ''; } else { - $out2 = $nsForm . '
'; + $morelinks = ''; + if ( $offset > 0 ) { + $morelinks = $sk->makeKnownLink ( + $wgContLang->specialPage ( 'Allpages' ), + wfMsg ( 'allpagesprev' ), + ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : '' + ); + } + if ( $stopat < $sections-1 ) { + if ( $morelinks != '' ) { $morelinks .= " | "; } + $morelinks .= $sk->makeKnownLink ( + $wgContLang->specialPage ( 'Allpages' ), + wfMsg ( 'allpagesnext' ), + 'offset=' . ($offset + $toplevelMaxperpage) + ); + } + + if ( $morelinks != '' ) { + $out2 = ''; + $out2 .= '
' . $nsForm; + $out2 .= ''; + $out2 .= $morelinks . '

'; + } else { + $out2 = $nsForm . '
'; + } } $wgOut->addHtml( $out2 . $out ); @@ -229,7 +233,7 @@ function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN, $invert ) { * @param string $from list all pages from this name (default FALSE) * @param bool $invert true if we want the namespaces inverted (default false) */ -function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) { +function indexShowChunk( $namespace = NS_MAIN, $from, $invert = false, $including = false ) { global $wgOut, $wgUser, $indexMaxperpage, $wgContLang; $sk = $wgUser->getSkin(); $maxPlusOne = $indexMaxperpage + 1; @@ -277,21 +281,25 @@ function indexShowChunk( $namespace = NS_MAIN, $from, $invert ) { } $out .= ''; - $nsForm = namespaceForm ( $namespace, $from, $invert ); - $out2 = ''; - $out2 .= '
' . $nsForm; - $out2 .= '' . - $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ), - wfMsg ( 'allpages' ) ); - if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) { - $namespaceparam = $namespace ? "&namespace=$namespace" : ""; - $invertparam = $invert ? "&invert=$invert" : ''; - $out2 .= " | " . $sk->makeKnownLink( - $wgContLang->specialPage( "Allpages" ), - wfMsg ( 'nextpage', $s->page_title ), - "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam . $invertparam ); + if ( $including ) { + $out2 = ''; + } else { + $nsForm = indexNamespaceForm ( $namespace, $from, $invert ); + $out2 = ''; + $out2 .= '
' . $nsForm; + $out2 .= '' . + $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ), + wfMsg ( 'allpages' ) ); + if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) { + $namespaceparam = $namespace ? "&namespace=$namespace" : ""; + $invertparam = $invert ? "&invert=$invert" : ''; + $out2 .= " | " . $sk->makeKnownLink( + $wgContLang->specialPage( "Allpages" ), + wfMsg ( 'nextpage', $s->page_title ), + "from=" . wfUrlEncode ( $s->page_title ) . $namespaceparam . $invertparam ); + } + $out2 .= "

"; } - $out2 .= "

"; $wgOut->addHtml( $out2 . $out ); } diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index cabb915cf3..430d889a64 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -103,7 +103,7 @@ function wfSpecialContributions( $par = null ) { $res = $dbr->query( $sql, $fname ); $numRows = $dbr->numRows( $res ); - $wgOut->addHTML( namespaceForm( $target, $hideminor, $namespace, $invert ) ); + $wgOut->addHTML( ucNamespaceForm( $target, $hideminor, $namespace, $invert ) ); $top = wfShowingResults( $offset, $limit ); $wgOut->addHTML( "

{$top}\n" ); @@ -216,7 +216,7 @@ function ucListEdit( $sk, $row ) { * @param string $namespace currently selected namespace, NULL for show all * @param bool $invert inverts the namespace selection on true (default null) */ -function namespaceForm ( $target, $hideminor, $namespace, $invert ) { +function ucNamespaceForm ( $target, $hideminor, $namespace, $invert ) { global $wgContLang, $wgScript; $namespaceselect = "