diff --git a/includes/Article.php b/includes/Article.php
index 71ffb693ab8..0ac58b9eefa 100644
--- a/includes/Article.php
+++ b/includes/Article.php
@@ -64,16 +64,14 @@ class Article {
# Return the text of this revision
function getContent( $noredir )
{
- global $wgRequest,$wgUser,$wgOut;
-
- $fname = "Article::getContent";
- wfProfileIn( $fname );
+ global $wgRequest;
# Get variables from query string :P
$action = $wgRequest->getText( 'action', 'view' );
$section = $wgRequest->getText( 'section' );
- $sectiontitle = $wgRequest->getText( 'sectiontitle' );
- $oid = $wgRequest->getInt( 'oldid' );
+
+ $fname = "Article::getContent";
+ wfProfileIn( $fname );
if ( 0 == $this->getID() ) {
if ( "edit" == $action ) {
@@ -82,126 +80,60 @@ class Article {
}
wfProfileOut( $fname );
return wfMsg( "noarticletext" );
- } else {
- $this->loadContent( $noredir );
-
- # size threshold at which pages are automatically collapsed
- $collapsethreshold=$wgUser->getOption( "collapsethreshold" );
- if($collapsethreshold && strlen($this->mContent)>=$collapsethreshold) {
- $collapse=true;
- } else {
- $collapse=false;
- }
- #override user pref is expansion is explicitly requested
- if($wgRequest->getBool('collapse')) { $collapse=true; }
- if( $wgRequest->getText( 'collapse' ) == 'false') {
- $collapse=false;
- }
- if($oid) { $collapse=false; }
- $wgOut->setCollapse($collapse);
-
- # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
- # if so, a "This is an anonymous talk page .." message must be appended to the
- # displayed page (but not during editing!).
- $anontalk=false;
- if( ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
- preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle->getText()) &&
- $action=="view"
- ) { $anontalk=true; }
-
- # When a page is viewed in collapsed mode, only the intro section and, for
- # pages with multiple sections, a table of contents are shown.
- if($collapse && $action=="view" && $section=="") {
- $rv=$this->getSection($this->mContent,0,$sectiontitle);
- $wgOut->setToc(Parser::getTocFromSource($this->mContent));
- if($anontalk) { $rv = $rv . "\n" . wfMsg("anontalkpage"); }
- wfProfileOut( $fname );
- return $rv;
- }
- # $section contains a section number and is used for section viewing and editing.
- if($section!="") {
- if($section=="new" && $action=="edit") {
- wfProfileOut( $fname );
- return "";
- }
- $rv=$this->getSection($this->mContent,$section,$sectiontitle);
- if($anontalk) { $rv = $rv . "\n" . wfMsg("anontalkpage"); }
- wfProfileOut( $fname );
- return $rv;
- }
- }
-
- if($anontalk) { return $this->mContent . "\n" . wfMsg("anontalkpage"); }
- wfProfileOut( $fname );
- return $this->mContent;
-
- }
-
- # This function returns the text of a section, specified by a number ($section)
- # and a section title ($sectiontitle). A section is text under a heading like
- # == Heading == or
Heading
, or the first section before any such
- # heading (section 0).
- #
- # If a section contains subsections, these are also returned.
- #
- function getSection($text,$section,$sectiontitle) {
-
- # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
- # comments to be stripped as well)
- $striparray=array();
- $parser=new Parser();
- $parser->mOutputType=OT_WIKI;
- $striptext=$parser->strip($text, $striparray, true);
-
- # now that we can be sure that no pseudo-sections are in the source,
- # split it up by section
- $secs =
- preg_split(
- "/(^=+.*?=+|^.*?<\/h[1-6].*?" . ">)/mi",
- $striptext, -1,
- PREG_SPLIT_DELIM_CAPTURE);
- if($section==0) {
- $rv=$secs[0];
} else {
- $headline=$secs[$section*2-1];
- preg_match( "/^(=+).*?=+|^.*?<\/h[1-6].*?>/mi",$headline,$matches);
- $hlevel=$matches[1];
-
- # translate wiki heading into level
- if(strpos($hlevel,"=")!==false) {
- $hlevel=strlen($hlevel);
- }
-
- $rv=$headline. $secs[$section*2];
- $count=$section+1;
-
- $break=false;
- while(!empty($secs[$count*2-1]) && !$break) {
-
- $subheadline=$secs[$count*2-1];
- preg_match( "/^(=+).*?=+|^.*?<\/h[1-6].*?>/mi",$subheadline,$matches);
- $subhlevel=$matches[1];
- if(strpos($subhlevel,"=")!==false) {
- $subhlevel=strlen($subhlevel);
+ $this->loadContent( $noredir );
+
+ if(
+ # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
+ ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
+ preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle->getText()) &&
+ $action=="view"
+ )
+ {
+ wfProfileOut( $fname );
+ return $this->mContent . "\n" .wfMsg("anontalkpagetext"); }
+ else {
+ if($action=="edit") {
+ if($section!="") {
+ if($section=="new") {
+ wfProfileOut( $fname );
+ return "";
+ }
+
+ # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
+ # comments to be stripped as well)
+ $striparray=array();
+ $parser=new Parser();
+ $parser->mOutputType=OT_WIKI;
+ $striptext=$parser->strip($this->mContent, $striparray, true);
+
+ # now that we can be sure that no pseudo-sections are in the source,
+ # split it up by section
+ $secs =
+ preg_split(
+ "/(^=+.*?=+|^.*?<\/h[1-6].*?" . ">)/mi",
+ $striptext, -1,
+ PREG_SPLIT_DELIM_CAPTURE);
+
+ if($section==0) {
+ $rv=$secs[0];
+ } else {
+ $rv=$secs[$section*2-1] . $secs[$section*2];
+ }
+
+ # reinsert stripped tags
+ $rv=$parser->unstrip($rv,$striparray);
+ $rv=trim($rv);
+ wfProfileOut( $fname );
+ return $rv;
+ }
}
- if($subhlevel > $hlevel) {
- $rv.=$subheadline.$secs[$count*2];
- }
- if($subhlevel <= $hlevel) {
- $break=true;
- }
- $count++;
-
+ wfProfileOut( $fname );
+ return $this->mContent;
}
}
- # reinsert stripped tags
- $rv=$parser->unstrip($rv,$striparray);
- $rv=trim($rv);
- return $rv;
-
}
-
-
+
# Load the revision (including cur_text) into this object
function loadContent( $noredir = false )
{
@@ -540,7 +472,7 @@ class Article {
# If we got diff and oldid in the query, we want to see a
# diff page instead of the article.
- if ( !is_null( $diff ) ) {
+ if ( !is_null( $diff ) ) {
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
$de = new DifferenceEngine( intval($oldid), intval($diff) );
$de->showDiffPage();
@@ -672,7 +604,7 @@ class Article {
/* Side effects: loads last edit */
function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = ""){
$this->loadLastEdit();
- $oldtext = $this->getContent( true );
+ $oldtext = $this->getContent( true );
if ($section != "") {
if($section=="new") {
if($summary) $subject="== {$summary} ==\n\n";
@@ -688,58 +620,15 @@ class Article {
# now that we can be sure that no pseudo-sections are in the source,
# split it up
- # Unfortunately we can't simply do a preg_replace because that might
- # replace the wrong section, so we have to use the section counter instead
$secs=preg_split("/(^=+.*?=+|^.*?<\/h[1-6].*?" . ">)/mi",
$oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
$secs[$section*2]=$text."\n\n"; // replace with edited
-
- # section 0 is top (intro) section
- if($section!=0) {
-
- # headline of old section - we need to go through this section
- # to determine if there are any subsections that now need to
- # be erased, as the mother section has been replaced with
- # the text of all subsections.
- $headline=$secs[$section*2-1];
- preg_match( "/^(=+).*?=+|^.*?<\/h[1-6].*?>/mi",$headline,$matches);
- $hlevel=$matches[1];
-
- # determine headline level for wikimarkup headings
- if(strpos($hlevel,"=")!==false) {
- $hlevel=strlen($hlevel);
- }
-
- $secs[$section*2-1]=""; // erase old headline
- $count=$section+1;
- $break=false;
- while(!empty($secs[$count*2-1]) && !$break) {
-
- $subheadline=$secs[$count*2-1];
- preg_match(
- "/^(=+).*?=+|^.*?<\/h[1-6].*?>/mi",$subheadline,$matches);
- $subhlevel=$matches[1];
- if(strpos($subhlevel,"=")!==false) {
- $subhlevel=strlen($subhlevel);
- }
- if($subhlevel > $hlevel) {
- // erase old subsections
- $secs[$count*2-1]="";
- $secs[$count*2]="";
- }
- if($subhlevel <= $hlevel) {
- $break=true;
- }
- $count++;
-
- }
-
- }
+ if($section) { $secs[$section*2-1]=""; } // erase old headline
$text=join("",$secs);
+
# reinsert the stuff that we stripped out earlier
- $text=$parser->unstrip($text,$striparray);
+ $text=$parser->unstrip($text,$striparray,true);
}
-
}
return $text;
}
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index f5b71039e6f..9bc9c9876c4 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -375,10 +375,9 @@ $wgGoToEdit = false;
# constructs.
$wgUserHtml = true;
-# $wgUseTidy: use tidy to make sure we produce valid XHTML output.
-# tidy is a free tool that fixes broken HTML/transforms it into xhtml.
-# When enabled, it does some of the cleaning/converting that's done in php otherwise
-# Performace penalty on a long page: about 5%.
+# $wgUseTidy: use tidy to make sure HTML output is sane.
+# This should only be enabled if $wgUserHtml is true.
+# tidy is a free tool that fixes broken HTML.
# See http://www.w3.org/People/Raggett/tidy/
# $wgTidyBin should be set to the path of the binary and
# $wgTidyConf to the path of the configuration file.
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 3151ea06de2..2c04c1fdbdc 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -196,7 +196,7 @@ class EditPage {
return;
else
$isConflict = true;
- }
+ }
}
# First time through: get contents, set time for conflict
# checking, etc.
@@ -335,7 +335,7 @@ class EditPage {
$previewhead.="
" . wfMsg( "previewconflict" ) .
"
\n";
}
- $previewtext = $this->textbox1;
+ $previewtext = wfUnescapeHTML( $this->textbox1 );
$parserOptions = ParserOptions::newFromUser( $wgUser );
$parserOptions->setUseCategoryMagic( false );
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 5f553a328d5..e859ed22299 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -18,8 +18,6 @@ class OutputPage {
var $mParserOptions;
var $mShowFeedLinks = false;
var $mEnableClientCache = true;
- var $mToc; # Table of contents for collapsed pages (in HTML)
- var $mCollapse = false; # Collapse output? (Set in Article.php)
function OutputPage()
{
@@ -37,7 +35,6 @@ class OutputPage {
$this->mContainsOldMagic = $this->mContainsNewMagic = 0;
$this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
$this->mSquidMaxage = 0;
- $this->mToc='';
}
function addHeader( $name, $val ) { array_push( $this->mHeaders, "$name: $val" ) ; }
@@ -716,29 +713,5 @@ class OutputPage {
# $ret .= "";
return $ret;
}
-
- function setToc($toc) {
-
- $this->mToc=$toc;
-
- }
-
- function getToc() {
-
- return $this->mToc;
-
- }
-
- function setCollapse($collapse) {
-
- $this->mCollapse=$collapse;
-
- }
-
- function getCollapse() {
-
- return $this->mCollapse;
-
- }
}
?>
diff --git a/includes/Parser.php b/includes/Parser.php
index dfba14d2b90..79aa4e72447 100644
--- a/includes/Parser.php
+++ b/includes/Parser.php
@@ -547,9 +547,7 @@ class Parser
return $t ;
}
- // set isMain=false if you call from a template etc. and don't want to do stuff
- // like TOC insertion for that content
- function internalParse( $text, $linestart, $args = array(), $isMain=true )
+ function internalParse( $text, $linestart, $args = array() )
{
$fname = "Parser::internalParse";
wfProfileIn( $fname );
@@ -567,7 +565,7 @@ class Parser
$text = $this->replaceExternalLinks( $text );
$text = $this->doTokenizedParser ( $text );
$text = $this->doTableStuff ( $text ) ;
- $text = $this->formatHeadings( $text, $isMain );
+ $text = $this->formatHeadings( $text );
$sk =& $this->mOptions->getSkin();
$text = $sk->transformContent( $text );
@@ -1509,8 +1507,7 @@ class Parser
# Run full parser on the included text
$text = $this->strip( $text, $this->mStripState );
- $text = $this->internalParse( $text, (bool)$newline, $assocArgs, false );
- if(!empty($newline)) $text = "\n".$text;
+ $text = $this->internalParse( $text, (bool)$newline, $assocArgs );
# Add the result to the strip state for re-inclusion after
# the rest of the processing
@@ -1675,12 +1672,10 @@ class Parser
*
*/
- /* private */ function formatHeadings( $text, $isMain=true )
+ /* private */ function formatHeadings( $text )
{
- global $wgInputEncoding,$wgRequest,$wgOut;
+ global $wgInputEncoding;
- $startsection=$wgRequest->getVal('section');
- if($startsection) { $startsection--;}
$doNumberHeadings = $this->mOptions->getNumberHeadings();
$doShowToc = $this->mOptions->getShowToc();
if( !$this->mTitle->userCanEdit() ) {
@@ -1812,12 +1807,12 @@ class Parser
if ( empty( $head[$headlineCount] ) ) {
$head[$headlineCount] = "";
}
- $head[$headlineCount] .= $sk->editSectionLink($startsection+$headlineCount+1);
+ $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1);
}
# Add the edit section span
if( $rightClickHack ) {
- $headline = $sk->editSectionScript($startsection+$headlineCount+1,$headline);
+ $headline = $sk->editSectionScript($headlineCount+1,$headline);
}
# give headline the correct tag
@@ -1851,14 +1846,6 @@ class Parser
# Top anchor now in skin
$full = $full.$toc;
}
-
- # If a page is viewed in collapsed mode, a TOC generated
- # from the wikisource is stored in the title object.
- # This TOC is now fetched and inserted here if it exists.
- $collapsedtoc=$wgOut->getToc();
- if ($collapsedtoc && !$i && $isMain) {
- $full = $full.$collapsedtoc;
- }
if( !empty( $head[$i] ) ) {
$full .= $head[$i];
@@ -1869,115 +1856,6 @@ class Parser
return $full;
}
- /* Generates a HTML-formatted table of contents which links to individual sections
- from the wikisource. Used for collapsing long pages.
- */
- /* static */ function getTocFromSource( $text ) {
-
- global $wgUser,$wgInputEncoding,$wgTitle,$wgOut,$wgParser;
- $sk = $wgUser->getSkin();
-
- $striparray=array();
- $oldtype=$wgParser->mOutputType;
- $wgParser->mOutputType=OT_WIKI;
- $text=$wgParser->strip($text, $striparray, true);
- $wgParser->mOutputType=$oldtype;
-
- $numMatches = preg_match_all( "/^(=+)(.*?)=+|^(.*?)<\/h[1-6].*?>/mi",$text,$matches);
-
- # no headings: text cannot be collapsed
- if( $numMatches == 0 ) {
- return "";
- }
-
- # We combine the headlines into a bundle and convert them to HTML
- # in order to make stripping out the wikicrap easier.
- $combined=implode("!@@@!",$matches[2]);
- $myout=$wgParser->parse($combined,$wgTitle,$wgOut->mParserOptions);
- $combined_html=$myout->getText();
- $headlines=array();
- $headlines=explode("!@@@!",$combined_html);
-
- # headline counter
- $headlineCount = 0;
- $toclevel = 0;
- $toc = "";
- $full = "";
- $head = array();
- $sublevelCount = array();
- $level = 0;
- $prevlevel = 0;
- foreach( $headlines as $headline ) {
- $headline=trim($headline);
- $numbering = "";
- if( $level ) {
- $prevlevel = $level;
- }
- $level = $matches[1][$headlineCount];
-
- # wikisource headings need to be converted into numbers
- # =foo= equals
foo
, ==foo== equals
foo
etc.
- if(strpos($level,"=")!==false) {
- $level=strlen($level);
- }
-
- if( $prevlevel && $level > $prevlevel ) {
- # reset when we enter a new level
- $sublevelCount[$level] = 0;
- $toc .= $sk->tocIndent( $level - $prevlevel );
- $toclevel += $level - $prevlevel;
- }
- if( $level < $prevlevel ) {
- # reset when we step back a level
- $sublevelCount[$level+1]=0;
- $toc .= $sk->tocUnindent( $prevlevel - $level );
- $toclevel -= $prevlevel - $level;
- }
- # count number of headlines for each level
- @$sublevelCount[$level]++;
- $dot = 0;
- for( $i = 1; $i <= $level; $i++ ) {
- if( !empty( $sublevelCount[$i] ) ) {
- if( $dot ) {
- $numbering .= ".";
- }
- $numbering .= $sublevelCount[$i];
- $dot = 1;
- }
- }
-
-
- # The canonized header is a version of the header text safe to use for links
- # Avoid insertion of weird stuff like