From f48f6617c81d50cd280957ac9d2a0f386549b7dc Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Fri, 14 May 2004 13:03:57 +0000 Subject: [PATCH] Small tweak to section editing- try to generate a section (toc-)anchor from the edited section and append that anchor to the url redirected to, so just edited section is shown by default Shortcomings: * won't append a number to duplicate headlines on a page (result: will go to first header with that content) * doesn't actually parse the headline, headlines with [\\['{<>] in them will just fall back to the old behaviour --- includes/Article.php | 8 ++++---- includes/EditPage.php | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 2c3123b803..b659637d48 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -719,7 +719,7 @@ class Article { return $text; } - function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false ) + function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = "" ) { global $wgOut, $wgUser, $wgLinkCache; global $wgDBtransactions, $wgMwRedir; @@ -824,14 +824,14 @@ class Article { $u->doUpdate(); } - $this->showArticle( $text, wfMsg( "updated" ) ); + $this->showArticle( $text, wfMsg( "updated" ), $sectionanchor ); return true; } # After we've either updated or inserted the article, update # the link tables and redirect to the new page. - function showArticle( $text, $subtitle ) + function showArticle( $text, $subtitle , $sectionanchor ) { global $wgOut, $wgUser, $wgLinkCache; global $wgMwRedir; @@ -850,7 +850,7 @@ class Article { $r = "redirect=no"; else $r = ""; - $wgOut->redirect( $this->mTitle->getFullURL( $r ) ); + $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor ); } # Add this page to my watchlist diff --git a/includes/EditPage.php b/includes/EditPage.php index 2c04c1fdbd..5ea232ba95 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -191,8 +191,27 @@ class EditPage { } } if ( ! $isConflict ) { - # All's well: update the article here - if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis )) + # All's well + $sectionanchor = ''; + if( $this->section != '' ) { + # Try to get a section anchor from the section source, redirect to edited section if header found + # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded + # for duplicate heading checking and maybe parsing + $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches ); + # we can't deal with anchors, includes, html etc in the header for now, + # headline would need to be parsed to improve this + if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) { + global $wgInputEncoding; + $headline = do_html_entity_decode( $matches[2], ENT_COMPAT, $wgInputEncoding ); + # strip out HTML, will be useful when + # $headline = preg_replace( "/<.*?" . ">/","",$headline ); + $headline = trim( $headline ); + $sectionanchor = '#'.preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', urlencode( $headline ) ); + } + } + + # update the article here + if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis, '', $sectionanchor )) return; else $isConflict = true; -- 2.20.1