Make phpcs-strict pass on includes/ (4/~10)
[lhc/web/wiklou.git] / includes / Wiki.php
index fbafba8..eff251f 100644 (file)
  * @internal documentation reviewed 15 Mar 2010
  */
 class MediaWiki {
-
        /**
-        * TODO: fold $output, etc, into this
+        * @todo Fold $output, etc, into this
         * @var IContextSource
         */
        private $context;
 
        /**
-        * @param $x null|WebRequest
+        * @param null|WebRequest $x
         * @return WebRequest
         */
        public function request( WebRequest $x = null ) {
@@ -44,7 +43,7 @@ class MediaWiki {
        }
 
        /**
-        * @param $x null|OutputPage
+        * @param null|OutputPage $x
         * @return OutputPage
         */
        public function output( OutputPage $x = null ) {
@@ -67,7 +66,7 @@ class MediaWiki {
        /**
         * Parse the request to get the Title object
         *
-        * @return Title object to be $wgTitle
+        * @return Title Title object to be $wgTitle
         */
        private function parseTitle() {
                global $wgContLang;
@@ -117,7 +116,11 @@ class MediaWiki {
                }
 
                // Use the main page as default title if nothing else has been provided
-               if ( $ret === null && strval( $title ) === '' && !$request->getCheck( 'curid' ) && $action !== 'delete' ) {
+               if ( $ret === null
+                       && strval( $title ) === ''
+                       && !$request->getCheck( 'curid' )
+                       && $action !== 'delete'
+               ) {
                        $ret = Title::newMainPage();
                }
 
@@ -142,7 +145,7 @@ class MediaWiki {
        /**
         * Returns the name of the action that will be executed.
         *
-        * @return string: action
+        * @return string Action
         */
        public function getAction() {
                static $action = null;
@@ -311,7 +314,7 @@ class MediaWiki {
         * Initialize the main Article object for "standard" actions (view, etc)
         * Create an Article object for the page, following redirects if needed.
         *
-        * @return mixed an Article, or a string to redirect to another URL
+        * @return mixed An Article, or a string to redirect to another URL
         */
        private function initializeArticle() {
                global $wgDisableHardRedirects;
@@ -393,8 +396,8 @@ class MediaWiki {
        /**
         * Perform one of the "standard" actions
         *
-        * @param $page Page
-        * @param $requestTitle The original title, before any redirects were applied
+        * @param Page $page
+        * @param Title $requestTitle The original title, before any redirects were applied
         */
        private function performAction( Page $page, Title $requestTitle ) {
                global $wgUseSquid, $wgSquidMaxage;
@@ -444,7 +447,15 @@ class MediaWiki {
        public function run() {
                try {
                        $this->checkMaxLag();
-                       $this->main();
+                       try {
+                               $this->main();
+                       } catch ( ErrorPageError $e ) {
+                               // Bug 62091: while exceptions are convenient to bubble up GUI errors,
+                               // they are not internal application faults. As with normal requests, this
+                               // should commit, print the output, do deferred updates, jobs, and profiling.
+                               wfGetLBFactory()->commitMasterChanges();
+                               $e->report(); // display the GUI error
+                       }
                        if ( function_exists( 'fastcgi_finish_request' ) ) {
                                fastcgi_finish_request();
                        }
@@ -534,7 +545,7 @@ class MediaWiki {
                        $request->getProtocol() == 'http'
                ) {
                        $oldUrl = $request->getFullRequestURL();
-                       $redirUrl = str_replace( 'http://', 'https://', $oldUrl );
+                       $redirUrl = preg_replace( '#^http://#', 'https://', $oldUrl );
 
                        if ( $request->wasPosted() ) {
                                // This is weird and we'd hope it almost never happens. This
@@ -651,8 +662,13 @@ class MediaWiki {
                        return;
                }
 
-               if ( !JobQueueGroup::singleton()->queuesHaveJobs( JobQueueGroup::TYPE_DEFAULT ) ) {
-                       return; // do not send request if there are probably no jobs
+               try {
+                       if ( !JobQueueGroup::singleton()->queuesHaveJobs( JobQueueGroup::TYPE_DEFAULT ) ) {
+                               return; // do not send request if there are probably no jobs
+                       }
+               } catch ( JobQueueError $e ) {
+                       MWExceptionHandler::logException( $e );
+                       return; // do not make the site unavailable
                }
 
                $query = array( 'title' => 'Special:RunJobs',