r102885 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102884‎ | r102885 | r102886 >
Date:09:12, 13 November 2011
Author:ialex
Status:ok
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -789,31 +789,33 @@
790790 */
791791 protected function getPreloadedText( $preload ) {
792792 global $wgUser, $wgParser;
 793+
793794 if ( !empty( $this->mPreloadText ) ) {
794795 return $this->mPreloadText;
795 - } elseif ( $preload !== '' ) {
796 - $title = Title::newFromText( $preload );
797 - # Check for existence to avoid getting MediaWiki:Noarticletext
798 - if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
799 - $article = new Article( $title );
 796+ }
 797+
 798+ if ( $preload === '' ) {
 799+ return '';
 800+ }
800801
801 - if ( $article->isRedirect() ) {
802 - $title = Title::newFromRedirectRecurse( $article->getContent() );
803 - # Redirects to missing titles are displayed, to hidden pages are followed
804 - # Copying observed behaviour from ?action=view
805 - if ( $title->exists() ) {
806 - if ($title->userCanRead() ) {
807 - $article = new Article( $title );
808 - } else {
809 - return "";
810 - }
811 - }
812 - }
813 - $parserOptions = ParserOptions::newFromUser( $wgUser );
814 - return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
 802+ $title = Title::newFromText( $preload );
 803+ # Check for existence to avoid getting MediaWiki:Noarticletext
 804+ if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
 805+ return '';
 806+ }
 807+
 808+ $page = WikiPage::factory( $title );
 809+ if ( $page->isRedirect() ) {
 810+ $title = $page->getRedirectTarget();
 811+ # Same as before
 812+ if ( $title === null || !$title->exists() || !$title->userCan( 'read' ) ) {
 813+ return '';
815814 }
 815+ $page = WikiPage::factory( $title );
816816 }
817 - return '';
 817+
 818+ $parserOptions = ParserOptions::newFromUser( $wgUser );
 819+ return $wgParser->getPreloadText( $page->getRawText(), $title, $parserOptions );
818820 }
819821
820822 /**

Status & tagging log