From 80f2572678d8c96889f9c4f9da96b31d5b804c34 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 5 Jul 2006 22:45:41 +0000 Subject: [PATCH] * Separate out EditPage's getContent bits from regular Article getContent. Cleans up read-only-mode warning on empty pages and neats up some code. --- RELEASE-NOTES | 3 ++ includes/Article.php | 59 ++---------------------------- includes/EditPage.php | 84 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 82 insertions(+), 64 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e041dfddb9..aa23384b25 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -643,6 +643,9 @@ Some default configuration options have changed: * Update to Venetian translation (vec) * Update to Slovenian translation (sl) * Add standard user tool links to deleted revision list +* Separate out EditPage's getContent bits from regular Article getContent. + Cleans up read-only-mode warning on empty pages and neats up some code. + == Compatibility == diff --git a/includes/Article.php b/includes/Article.php index b6a0b94937..b1e1f620c8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -146,25 +146,9 @@ class Article { function getContent() { global $wgRequest, $wgUser, $wgOut; - # Get variables from query string :P - $action = $wgRequest->getText( 'action', 'view' ); - $section = $wgRequest->getText( 'section' ); - $preload = $wgRequest->getText( 'preload' ); - wfProfileIn( __METHOD__ ); if ( 0 == $this->getID() ) { - if ( 'edit' == $action ) { - wfProfileOut( __METHOD__ ); - - # If requested, preload some text. - $text=$this->getPreloadedText($preload); - - # We used to put MediaWiki:Newarticletext here if - # $text was empty at this point. - # This is now shown above the edit box instead. - return $text; - } wfProfileOut( __METHOD__ ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); @@ -177,51 +161,11 @@ class Article { return "
$ret
"; } else { $this->loadContent(); - if($action=='edit') { - if($section!='') { - if($section=='new') { - wfProfileOut( __METHOD__ ); - $text=$this->getPreloadedText($preload); - return $text; - } - - # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML - # comments to be stripped as well) - $rv=$this->getSection($this->mContent,$section); - wfProfileOut( __METHOD__ ); - return $rv; - } - } wfProfileOut( __METHOD__ ); return $this->mContent; } } - /** - * Get the contents of a page from its title and remove includeonly tags - * - * @param $preload String: the title of the page. - * @return string The contents of the page. - */ - function getPreloadedText($preload) { - if ( $preload === '' ) - return ''; - else { - $preloadTitle = Title::newFromText( $preload ); - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { - $rev=Revision::newFromTitle($preloadTitle); - if ( is_object( $rev ) ) { - $text = $rev->getText(); - // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing - // its own mini-parser! -ævar - $text = preg_replace( '~~', '', $text ); - return $text; - } else - return ''; - } - } - } - /** * This function returns the text of a section, specified by a number ($section). * A section is text under a heading like == Heading == or \Heading\, or @@ -232,6 +176,7 @@ class Article { * @param $text String: text to look in * @param $section Integer: section number * @return string text of the requested section + * @deprecated */ function getSection($text,$section) { global $wgParser; @@ -278,6 +223,7 @@ class Article { # unused: # $lastid = $oldid; } + if ( !$oldid ) { $oldid = 0; } @@ -735,6 +681,7 @@ class Article { return; } } + # Should the parser cache be used? $pcache = $wgEnableParserCache && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 && diff --git a/includes/EditPage.php b/includes/EditPage.php index 2ffda77fc9..d43a12026d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -49,6 +49,74 @@ class EditPage { global $wgTitle; $this->mTitle =& $wgTitle; } + + /** + * Fetch initial editing page content. + */ + private function getContent() { + global $wgRequest, $wgParser; + + # Get variables from query string :P + $section = $wgRequest->getVal( 'section' ); + $preload = $wgRequest->getVal( 'preload' ); + + wfProfileIn( __METHOD__ ); + + $text = ''; + if( !$this->mTitle->exists() ) { + + # If requested, preload some text. + $text = $this->getPreloadedText( $preload ); + + # We used to put MediaWiki:Newarticletext here if + # $text was empty at this point. + # This is now shown above the edit box instead. + } else { + // FIXME: may be better to use Revision class directly + // But don't mess with it just yet. Article knows how to + // fetch the page record from the high-priority server, + // which is needed to guarantee we don't pick up lagged + // information. + + $text = $this->mArticle->getContent(); + + if( $section != '' ) { + if( $section == 'new' ) { + $text = $this->getPreloadedText( $preload ); + } else { + $text = $wgParser->getSection( $text, $section ); + } + } + } + + wfProfileOut( __METHOD__ ); + return $text; + } + + /** + * Get the contents of a page from its title and remove includeonly tags + * + * @param $preload String: the title of the page. + * @return string The contents of the page. + */ + private function getPreloadedText($preload) { + if ( $preload === '' ) + return ''; + else { + $preloadTitle = Title::newFromText( $preload ); + if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { + $rev=Revision::newFromTitle($preloadTitle); + if ( is_object( $rev ) ) { + $text = $rev->getText(); + // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing + // its own mini-parser! -ævar + $text = preg_replace( '~~', '', $text ); + return $text; + } else + return ''; + } + } + } /** * This is the function that extracts metadata from the article body on the first view. @@ -61,7 +129,7 @@ class EditPage { if ( !$wgUseMetadataEdit ) return ; if ( $wgMetadataWhitelist == '' ) return ; $s = '' ; - $t = $this->mArticle->getContent(); + $t = $this->getContent(); # MISSING : filtering @@ -185,7 +253,7 @@ class EditPage { if ( ! $this->mTitle->userCanEdit() ) { wfDebug( "$fname: user can't edit\n" ); - $wgOut->readOnlyPage( $this->mArticle->getContent(), true ); + $wgOut->readOnlyPage( $this->getContent(), true ); wfProfileOut( $fname ); return; } @@ -206,7 +274,7 @@ class EditPage { return; } else { wfDebug( "$fname: read-only page\n" ); - $wgOut->readOnlyPage( $this->mArticle->getContent(), true ); + $wgOut->readOnlyPage( $this->getContent(), true ); wfProfileOut( $fname ); return; } @@ -230,7 +298,7 @@ class EditPage { } else if ( $this->diff ) { $this->formtype = 'diff'; } else { - $wgOut->readOnlyPage( $this->mArticle->getContent() ); + $wgOut->readOnlyPage( $this->getContent() ); wfProfileOut( $fname ); return; } @@ -734,7 +802,7 @@ class EditPage { */ function initialiseForm() { $this->edittime = $this->mArticle->getTimestamp(); - $this->textbox1 = $this->mArticle->getContent(); + $this->textbox1 = $this->getContent(); $this->summary = ''; if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ) ; @@ -768,7 +836,7 @@ class EditPage { $wgOut->addWikiText( wfMsg( 'explainconflict' ) ); $this->textbox2 = $this->textbox1; - $this->textbox1 = $this->mArticle->getContent(); + $this->textbox1 = $this->getContent(); $this->edittime = $this->mArticle->getTimestamp(); } else { @@ -1314,7 +1382,7 @@ END } else { # if user want to see preview when he edit an article if( $wgUser->getOption('previewonfirst') and ($this->textbox1 == '')) { - $this->textbox1 = $this->mArticle->getContent(); + $this->textbox1 = $this->getContent(); } $toparse = $this->textbox1; @@ -1348,7 +1416,7 @@ END # If the user made changes, preserve them when showing the markup # (This happens when a user is blocked during edit, for instance) $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' ); - $source = $first ? $this->mArticle->getContent() : $this->textbox1; + $source = $first ? $this->getContent() : $this->textbox1; # Spit out the source or the user's modified version $rows = $wgUser->getOption( 'rows' ); -- 2.20.1