replace TYPE= with ENGINE=, (supported since 4.0, TYPE deprecated since 4.1)
[lhc/web/wiklou.git] / includes / Wiki.php
index 8c32004..0a0bd42 100644 (file)
@@ -28,7 +28,7 @@ class MediaWiki {
         * Retieves key/value pairs to circumvent global variables
         * Note that keys are case-insensitive!
         */
-       function getVal( $key, $default = "" ) {
+       function getVal( $key, $default = '' ) {
                $key = strtolower( $key );
                if( isset( $this->params[$key] ) ) {
                        return $this->params[$key];
@@ -101,7 +101,7 @@ class MediaWiki {
                        // Do this above the read whitelist check for security...
                        $title = Title::makeTitle( NS_SPECIAL, 'Search' );
                }
-               $this->setVal( "Search", $search );
+               $this->setVal( 'Search', $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
@@ -202,9 +202,17 @@ class MediaWiki {
                $article = $this->articleFromTitle( $title );
                
                // Namespace might change when using redirects
-               if( $action == 'view' && !$request->getVal( 'oldid' ) && $request->getVal( 'redirect' ) != 'no' ) {
+               if( $action == 'view' && !$request->getVal( 'oldid' ) &&
+                                               $request->getVal( 'redirect' ) != 'no' ) {
                        $dbr=&wfGetDB(DB_SLAVE);
-                       $article->loadPageData($article->pageDataFromTitle($dbr,$title));
+                       
+                       // If we don't check for existance we'll get "Trying to get
+                       // property of non-object" E_NOTICE in Article::loadPageData() when
+                       // viewing a page that does not exist
+                       if ( $article->exists() ) {
+                               $article->loadPageData($article->pageDataFromTitle($dbr,$title));
+                       }
+                       
                        /* Follow redirects only for... redirects */
                        if ($article->mIsRedirect) {
                                $target = $article->followRedirect();
@@ -216,20 +224,19 @@ class MediaWiki {
                                        }
                                }
                                if( is_object( $target ) ) {
-                                       // evil globals hack!
                                        /* Rewrite environment to redirected article */
-                                       $rarticle =& new Article($target);
+                                       $rarticle = $this->articleFromTitle($target);
                                        $rarticle->loadPageData($rarticle->pageDataFromTitle($dbr,$target));
                                        if ($rarticle->mTitle->mArticleID) {
-                                               $article =& $rarticle;
-                                               $wgTitle =& $target;
+                                               $article = $rarticle;
+                                               $wgTitle = $target;
                                                $article->setRedirectedFrom( $title );
                                        } else {
-                                               $wgTitle =& $title;
+                                               $wgTitle = $title;
                                        }
                                }
                        } else {
-                               $wgTitle =& $article->mTitle;
+                               $wgTitle = $article->mTitle;
                        }
                }
                wfProfileOut( 'MediaWiki::initializeArticle' );
@@ -242,6 +249,7 @@ class MediaWiki {
        function finalCleanup ( &$deferredUpdates, &$loadBalancer, &$output ) {
                wfProfileIn( 'MediaWiki::finalCleanup' );
                $this->doUpdates( $deferredUpdates );
+               $this->doJobs();
                $loadBalancer->saveMasterPos();
                # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
                $loadBalancer->commitAll();
@@ -259,7 +267,39 @@ class MediaWiki {
                foreach( $updates as $up ) {
                        $up->doUpdate();
                }
-               wfProfileOut( 'MediaWiki::doUpdates' );         
+               wfProfileOut( 'MediaWiki::doUpdates' );
+       }
+
+       /**
+        * Do a job from the job queue
+        */
+       function doJobs() {
+               global $wgJobLogFile, $wgJobRunRate;
+               
+               if ( $wgJobRunRate <= 0 ) {
+                       return;
+               }
+               if ( $wgJobRunRate < 1 ) {
+                       $max = mt_getrandmax();
+                       if ( mt_rand( 0, $max ) > $max * $wgJobRunRate ) {
+                               return;
+                       }
+                       $n = 1;
+               } else {
+                       $n = intval( $wgJobRunRate );
+               }
+
+               require_once( 'JobQueue.php' );
+
+               while ( $n-- && false != ($job = Job::pop())) {
+                       $output = $job->toString() . "\n";
+                       if ( !$job->run() ) {
+                               $output .= "Error: " . $job->getLastError() . "\n";
+                       }
+                       if ( $wgJobLogFile ) {
+                               error_log( $output, 3, $wgJobLogFile );
+                       }
+               }
        }
        
        /**
@@ -282,7 +322,7 @@ class MediaWiki {
                $action = $this->getVal('Action');
                if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
                        /* No such action; this will switch to the default case */
-                       $action = "nosuchaction"; 
+                       $action = 'nosuchaction';
                }
 
                switch( $action ) {
@@ -368,8 +408,8 @@ class MediaWiki {
                                if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
                                        $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
                                }
+               }
                wfProfileOut( 'MediaWiki::performAction' );
-       }
 
        
        }