From a00404a5cd1c2161cc5d1234befbb315af53f9da Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 13 Nov 2011 09:12:03 +0000 Subject: [PATCH] Refactored EditPage::getPreloadedText(): * Use WikiPage instead of Article (avoids conflicting with oldid url parameter) * Use getRedirectTarget() instead of creating a new Title with the content of the page * Changed userCanRead() calls to userCan( 'read' ) * Use "if ( something ) return;" instead of nesting if checks --- includes/EditPage.php | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 00012321d3..8bcb2a3258 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -789,31 +789,33 @@ class EditPage { */ protected function getPreloadedText( $preload ) { global $wgUser, $wgParser; + if ( !empty( $this->mPreloadText ) ) { return $this->mPreloadText; - } elseif ( $preload !== '' ) { - $title = Title::newFromText( $preload ); - # Check for existence to avoid getting MediaWiki:Noarticletext - if ( isset( $title ) && $title->exists() && $title->userCanRead() ) { - $article = new Article( $title ); - - if ( $article->isRedirect() ) { - $title = Title::newFromRedirectRecurse( $article->getContent() ); - # Redirects to missing titles are displayed, to hidden pages are followed - # Copying observed behaviour from ?action=view - if ( $title->exists() ) { - if ($title->userCanRead() ) { - $article = new Article( $title ); - } else { - return ""; - } - } - } - $parserOptions = ParserOptions::newFromUser( $wgUser ); - return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions ); + } + + if ( $preload === '' ) { + return ''; + } + + $title = Title::newFromText( $preload ); + # Check for existence to avoid getting MediaWiki:Noarticletext + if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) { + return ''; + } + + $page = WikiPage::factory( $title ); + if ( $page->isRedirect() ) { + $title = $page->getRedirectTarget(); + # Same as before + if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) { + return ''; } + $page = WikiPage::factory( $title ); } - return ''; + + $parserOptions = ParserOptions::newFromUser( $wgUser ); + return $wgParser->getPreloadText( $page->getRawText(), $title, $parserOptions ); } /** -- 2.20.1