Minor RawPage tweaks
[lhc/web/wiklou.git] / includes / Wiki.php
index 26bad27..e8fd40d 100644 (file)
@@ -50,9 +50,8 @@ class MediaWiki {
         * @param $request WebRequest
         */
        function initialize( &$title, &$article, &$output, &$user, $request ) {
-               wfProfileIn( __METHOD__ );
                $this->preliminaryChecks( $title, $output, $request ) ;
-               if ( !$this->initializeSpecialCases( $title, $output, $request ) ) {
+               if( !$this->initializeSpecialCases( $title, $output, $request ) ) {
                        $new_article = $this->initializeArticle( $title, $request );
                        if( is_object( $new_article ) ) {
                                $article = $new_article;
@@ -60,11 +59,9 @@ class MediaWiki {
                        } elseif( is_string( $new_article ) ) {
                                $output->redirect( $new_article );
                        } else {
-                               wfProfileOut( __METHOD__ );
                                throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
                        }
                }
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -77,7 +74,7 @@ class MediaWiki {
         */
        function checkMaxLag( $maxLag ) {
                list( $host, $lag ) = wfGetLB()->getMaxLag();
-               if ( $lag > $maxLag ) {
+               if( $lag > $maxLag ) {
                        wfMaxlagError( $host, $lag, $maxLag );
                        return false;
                } else {
@@ -96,16 +93,14 @@ class MediaWiki {
         */
        function checkInitialQueries( $title, $action ) {
                global $wgOut, $wgRequest, $wgContLang;
-               if( $wgRequest->getVal( 'printable' ) == 'yes' ){
+               if( $wgRequest->getVal( 'printable' ) === 'yes' ) {
                        $wgOut->setPrintable();
                }
-
                $ret = NULL;
-
-               if ( $curid = $wgRequest->getInt( 'curid' ) ) {
+               if( $curid = $wgRequest->getInt( 'curid' ) ) {
                        # URLs like this are generated by RC, because rc_title isn't always accurate
                        $ret = Title::newFromID( $curid );
-               } elseif ( '' == $title && 'delete' != $action ) {
+               } elseif( '' == $title && 'delete' != $action ) {
                        $ret = Title::newMainPage();
                } else {
                        $ret = Title::newFromURL( $title );
@@ -115,7 +110,7 @@ class MediaWiki {
                                $wgContLang->findVariantLink( $title, $ret );
 
                }
-               if ( ( $oldid = $wgRequest->getInt( 'oldid' ) )
+               if( ( $oldid = $wgRequest->getInt( 'oldid' ) )
                        && ( is_null( $ret ) || $ret->getNamespace() != NS_SPECIAL ) ) {
                        // Allow oldid to override a changed or missing title.
                        $rev = Revision::newFromId( $oldid );
@@ -134,7 +129,6 @@ class MediaWiki {
         * @param $request WebRequest
         */
        function preliminaryChecks( &$title, &$output, $request ) {
-
                if( $request->getCheck( 'search' ) ) {
                        // Compatibility with old search URLs which didn't use Special:Search
                        // Just check for presence here, so blank requests still
@@ -143,16 +137,14 @@ class MediaWiki {
                        // Do this above the read whitelist check for security...
                        $title = SpecialPage::getTitleFor( 'Search' );
                }
-
                # If the user is not logged in, the Namespace:title of the article must be in
                # the Read array in order for the user to see it. (We have to check here to
                # catch special pages etc. We check again in Article::view())
-               if ( !is_null( $title ) && !$title->userCanRead() ) {
+               if( !is_null( $title ) && !$title->userCanRead() ) {
                        $output->loginToUse();
                        $output->output();
                        exit;
                }
-
        }
 
        /**
@@ -175,20 +167,20 @@ class MediaWiki {
                        $title = SpecialPage::getTitleFor( 'Badtitle' );
                        # Die now before we mess up $wgArticle and the skin stops working
                        throw new ErrorPageError( 'badtitle', 'badtitletext' );
-               } else if ( $title->getInterwiki() != '' ) {
+               } else if( $title->getInterwiki() != '' ) {
                        if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
                                $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
                        } else {
                                $url = $title->getFullURL();
                        }
                        /* Check for a redirect loop */
-                       if ( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
+                       if( !preg_match( '/^' . preg_quote( $this->getVal('Server'), '/' ) . '/', $url ) && $title->isLocal() ) {
                                $output->redirect( $url );
                        } else {
                                $title = SpecialPage::getTitleFor( 'Badtitle' );
                                throw new ErrorPageError( 'badtitle', 'badtitletext' );
                        }
-               } else if ( $action == 'view' && !$request->wasPosted() &&
+               } else if( $action == 'view' && !$request->wasPosted() &&
                        ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
                        !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
                {
@@ -220,7 +212,7 @@ class MediaWiki {
                                $output->setSquidMaxage( 1200 );
                                $output->redirect( $targetUrl, '301' );
                        }
-               } else if ( NS_SPECIAL == $title->getNamespace() ) {
+               } else if( NS_SPECIAL == $title->getNamespace() ) {
                        /* actions that need to be made when we have a special pages */
                        SpecialPage::executePath( $title );
                } else {
@@ -307,7 +299,7 @@ class MediaWiki {
                                        // Rewrite environment to redirected article
                                        $rarticle = self::articleFromTitle( $target );
                                        $rarticle->loadPageData( $rarticle->pageDataFromTitle( $dbr, $target ) );
-                                       if ( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
+                                       if( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
                                                $rarticle->setRedirectedFrom( $title );
                                                $article = $rarticle;
                                                $title = $target;
@@ -351,19 +343,17 @@ class MediaWiki {
         * @param $updates array of objects that hold an update to do
         */
        function doUpdates( &$updates ) {
-               wfProfileIn( __METHOD__ );
                /* No need to get master connections in case of empty updates array */
-               if (!$updates) {
-                       wfProfileOut( __METHOD__ );
+               if( !$updates ) {
                        return;
                }
-
+               wfProfileIn( __METHOD__ );
                $dbw = wfGetDB( DB_MASTER );
                foreach( $updates as $up ) {
                        $up->doUpdate();
 
                        # Commit after every update to prevent lock contention
-                       if ( $dbw->trxLevel() ) {
+                       if( $dbw->trxLevel() ) {
                                $dbw->commit();
                        }
                }
@@ -376,12 +366,12 @@ class MediaWiki {
        function doJobs() {
                $jobRunRate = $this->getVal( 'JobRunRate' );
 
-               if ( $jobRunRate <= 0 || wfReadOnly() ) {
+               if( $jobRunRate <= 0 || wfReadOnly() ) {
                        return;
                }
-               if ( $jobRunRate < 1 ) {
+               if( $jobRunRate < 1 ) {
                        $max = mt_getrandmax();
-                       if ( mt_rand( 0, $max ) > $max * $jobRunRate ) {
+                       if( mt_rand( 0, $max ) > $max * $jobRunRate ) {
                                return;
                        }
                        $n = 1;
@@ -395,7 +385,7 @@ class MediaWiki {
                        $success = $job->run();
                        $t += wfTime();
                        $t = round( $t*1000 );
-                       if ( !$success ) {
+                       if( !$success ) {
                                $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
                        } else {
                                $output .= "Success, Time: $t ms\n";
@@ -422,10 +412,7 @@ class MediaWiki {
         * @param $request WebRequest
         */
        function performAction( &$output, &$article, &$title, &$user, &$request ) {
-               wfProfileIn( __METHOD__ );
-
-               if ( !wfRunHooks( 'MediaWikiPerformAction', array( $output, $article, $title, $user, $request, $this ) ) ) {
-                       wfProfileOut( __METHOD__ );
+               if( !wfRunHooks( 'MediaWikiPerformAction', array( $output, $article, $title, $user, $request, $this ) ) ) {
                        return;
                }
 
@@ -440,6 +427,10 @@ class MediaWiki {
                                $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
                                $article->view();
                                break;
+                       case 'raw': // includes JS/CSS
+                               $raw = new RawPage( $article );
+                               $raw->view();
+                               break;
                        case 'watch':
                        case 'unwatch':
                        case 'delete':
@@ -507,16 +498,11 @@ class MediaWiki {
                                $history = new PageHistory( $article );
                                $history->history();
                                break;
-                       case 'raw':
-                               $raw = new RawPage( $article );
-                               $raw->view();
-                               break;
                        default:
                                if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
                                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
                                }
                }
-               wfProfileOut( __METHOD__ );
 
        }