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;
$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;
$r = "redirect=no";
else
$r = "";
- $wgOut->redirect( $this->mTitle->getFullURL( $r ) );
+ $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
}
# Add this page to my watchlist
}
}
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;