From ec4174f085cdc04362d6b799555ebfcb2db051a3 Mon Sep 17 00:00:00 2001 From: Steve Sanbeg Date: Wed, 14 Mar 2007 18:20:21 +0000 Subject: [PATCH] When calling edit page for nonexistent section, generate error inside of just discarding edits, since edit links sometimes go to the wrong place. --- RELEASE-NOTES | 1 + includes/EditPage.php | 31 ++++++++++++++++++++++++++---- includes/Parser.php | 32 +++++++++---------------------- includes/SkinTemplate.php | 1 + languages/messages/MessagesEn.php | 2 ++ maintenance/nukePage.inc | 8 ++++++++ 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c04fc457ef..42d7c5b563 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -268,6 +268,7 @@ lighter making things easier to read. * Default tidy.conf has been moved from extensions module into includes. * Ignore lonely ''''' * (bug 3984) Searching in logs by title% +* (bug 9244) When calling edit page for nonexistent section, generate error inside of just discarding edits, since edit links sometimes go to the wrong place. * Private logs can now be created using $wgLogRestrictions * (bug 3576) Revisiondelete completed (RSS feeds checked, carries over delete/undelete) * Log events, file revisions, archived revisions can be deleted with revisiondelete diff --git a/includes/EditPage.php b/includes/EditPage.php index 8aca2d637c..7cb3abf41f 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -67,7 +67,7 @@ class EditPage { /** * Fetch initial editing page content. */ - private function getContent() { + private function getContent( $def_text = '' ) { global $wgOut, $wgRequest, $wgParser; # Get variables from query string :P @@ -143,7 +143,7 @@ class EditPage { if( $section == 'new' ) { $text = $this->getPreloadedText( $preload ); } else { - $text = $wgParser->getSection( $text, $section ); + $text = $wgParser->getSection( $text, $section, $def_text ); } } } @@ -430,7 +430,12 @@ class EditPage { # First time through: get contents, set time for conflict # checking, etc. if ( 'initial' == $this->formtype || $this->firsttime ) { - $this->initialiseForm(); + if ($this->initialiseForm() === false) { + $this->noSuchSectionPage(); + wfProfileOut( "$fname-business-end" ); + wfProfileOut( $fname ); + return; + } if( !$this->mTitle->getArticleId() ) wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) ); } @@ -871,10 +876,13 @@ class EditPage { function initialiseForm() { $this->edittime = $this->mArticle->getTimestamp(); $this->summary = ''; - $this->textbox1 = $this->getContent(); + $this->textbox1 = $this->getContent(false); + if ($this->textbox1 === false) return false; + if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ); wfProxyCheck(); + return true; } /** @@ -1470,6 +1478,21 @@ END $wgOut->returnToMain( false ); } + /** + * Creates a basic error page which informs the user that + * they have attempted to edit a nonexistant section. + */ + function noSuchSectionPage() { + global $wgOut; + + $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); + $wgOut->setArticleRelated( false ); + + $wgOut->addWikiText( wfMsg( 'nosuchsectiontext', $this->section ) ); + $wgOut->returnToMain( false ); + } + /** * Produce the stock "your edit contains spam" page * diff --git a/includes/Parser.php b/includes/Parser.php index b5f984c636..6ac046711d 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -4537,24 +4537,6 @@ class Parser $uniq = preg_quote( $this->uniqPrefix(), '/' ); $comment = "(?:$uniq-!--.*?QINU)"; $secs = preg_split( - /* - "/ - ^( - (?:$comment|<\/?noinclude>)* # Initial comments will be stripped - (?: - (=+) # Should this be limited to 6? - .+? # Section title... - \\2 # Ending = count must match start - | - ^ - - .*? - <\/h\\3\s*> - ) - (?:$comment|<\/?noinclude>|\s+)* # Trailing whitespace ok - )$ - /mix", - */ "/ ( ^ @@ -4578,7 +4560,8 @@ class Parser // "Section 0" returns the content before any other section. $rv = $secs[0]; } else { - $rv = ""; + //track missing section, will replace if found. + $rv = $newtext; } } elseif( $mode == "replace" ) { if( $section == 0 ) { @@ -4633,8 +4616,10 @@ class Parser } } } - # reinsert stripped tags - $rv = trim( $stripState->unstripBoth( $rv ) ); + if (is_string($rv)) + # reinsert stripped tags + $rv = trim( $stripState->unstripBoth( $rv ) ); + return $rv; } @@ -4647,10 +4632,11 @@ class Parser * * @param $text String: text to look in * @param $section Integer: section number + * @param $deftext: default to return if section is not found * @return string text of the requested section */ - public function getSection( $text, $section ) { - return $this->extractSections( $text, $section, "get" ); + public function getSection( $text, $section, $deftext='' ) { + return $this->extractSections( $text, $section, "get", $deftext ); } public function replaceSection( $oldtext, $section, $text ) { diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 7c4cf12d44..9643b1736e 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -752,6 +752,7 @@ class SkinTemplate extends Skin { ); } } + wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ; } else { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index dbe8333387..5d26e5b4d7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -946,6 +946,8 @@ You cannot use the 'email this user' feature unless a valid email address is spe 'whitelistacctext' => 'To be allowed to create accounts in this wiki you have to [[Special:Userlogin|log]] in and have the appropriate permissions.', 'confirmedittitle' => 'E-mail confirmation required to edit', 'confirmedittext' => 'You must confirm your e-mail address before editing pages. Please set and validate your e-mail address through your [[Special:Preferences|user preferences]].', +'nosuchsectiontitle' => 'No such section', +'nosuchsectiontext' => "You tried to edit a section that doesn't exist. Since there is no section \$1, there's no place to save your edit.", 'loginreqtitle' => 'Login Required', 'loginreqlink' => 'log in', 'loginreqpagetext' => 'You must $1 to view other pages.', diff --git a/maintenance/nukePage.inc b/maintenance/nukePage.inc index 7b17261449..804651b13d 100644 --- a/maintenance/nukePage.inc +++ b/maintenance/nukePage.inc @@ -73,6 +73,14 @@ function DeleteRevisions( $ids ) { $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" ); $dbw->commit(); + + #TODO: see if this is a "good" page, to decrement that as well. + $pages = $dbw->selectField('site_stats', 'ss_total_pages'); + $pages--; + $dbw->update( 'site_stats', + array('ss_total_pages' => $pages ), + array( 'ss_row_id' => 1), + __METHOD__ ); } -- 2.20.1