Merge branch 'Wikidata' into master.
[lhc/web/wiklou.git] / includes / OutputPage.php
index bf70467..53f6da1 100644 (file)
@@ -56,9 +56,9 @@ class OutputPage extends ContextSource {
        /**
         * Holds the debug lines that will be output as comments in page source if
         * $wgDebugComments is enabled. See also $wgShowDebug.
-        * TODO: make a getter method for this
+        * @deprecated since 1.20; use MWDebug class instead.
         */
-       public $mDebugtext = ''; // TODO: we might want to replace it by wfDebug() wfDebugLog()
+       public $mDebugtext = '';
 
        /// Should be private. Stores contents of "<title>" tag
        var $mHTMLtitle = '';
@@ -255,7 +255,7 @@ class OutputPage extends ContextSource {
        function __construct( IContextSource $context = null ) {
                if ( $context === null ) {
                        # Extensions should use `new RequestContext` instead of `new OutputPage` now.
-                       wfDeprecated( __METHOD__ );
+                       wfDeprecated( __METHOD__, '1.18' );
                } else {
                        $this->setContext( $context );
                }
@@ -851,11 +851,10 @@ class OutputPage extends ContextSource {
                $this->getContext()->setTitle( $t );
        }
 
-
        /**
         * Replace the subtile with $str
         *
-        * @param $str String|Message: new value of the subtitle
+        * @param $str String|Message: new value of the subtitle. String should be safe HTML.
         */
        public function setSubtitle( $str ) {
                $this->clearSubtitle();
@@ -875,7 +874,7 @@ class OutputPage extends ContextSource {
        /**
         * Add $str to the subtitle
         *
-        * @param $str String|Message to add to the subtitle
+        * @param $str String|Message to add to the subtitle. String should be safe HTML.
         */
        public function addSubtitle( $str ) {
                if ( $str instanceof Message ) {
@@ -1314,15 +1313,6 @@ class OutputPage extends ContextSource {
                return $this->mBodytext;
        }
 
-       /**
-        * Add $text to the debug output
-        *
-        * @param $text String: debug text
-        */
-       public function debug( $text ) {
-               $this->mDebugtext .= $text;
-       }
-
        /**
         * Get/set the ParserOptions object to use for wikitext parsing
         *
@@ -1725,7 +1715,7 @@ class OutputPage extends ContextSource {
        /**
         * Return a Vary: header on which to vary caches. Based on the keys of $mVaryHeader,
         * such as Accept-Encoding or Cookie
-        * 
+        *
         * @return String
         */
        public function getVaryHeader() {
@@ -1912,7 +1902,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.18 Use HttpStatus::getMessage() instead.
         */
        public static function getStatusMessage( $code ) {
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.18' );
                return HttpStatus::getMessage( $code );
        }
 
@@ -1999,8 +1989,13 @@ class OutputPage extends ContextSource {
                        wfProfileOut( 'Output-skin' );
                }
 
+               // This hook allows last minute changes to final overall output by modifying output buffer
+               wfRunHooks( 'AfterFinalPageOutput', array( $this ) );
+
                $this->sendCacheControl();
+
                ob_end_flush();
+
                wfProfileOut( __METHOD__ );
        }
 
@@ -2032,10 +2027,6 @@ class OutputPage extends ContextSource {
         *                   based on $pageTitle
         */
        public function prepareErrorPage( $pageTitle, $htmlTitle = false ) {
-               if ( $this->getTitle() ) {
-                       $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
-               }
-
                $this->setPageTitle( $pageTitle );
                if ( $htmlTitle !== false ) {
                        $this->setHTMLTitle( $htmlTitle );
@@ -2053,13 +2044,18 @@ class OutputPage extends ContextSource {
         *
         * showErrorPage( 'titlemsg', 'pagetextmsg', array( 'param1', 'param2' ) );
         * showErrorPage( 'titlemsg', $messageObject );
+        * showErrorPage( $titleMessageObj, $messageObject );
         *
-        * @param $title String: message key for page title
+        * @param $title Mixed: message key (string) for page title, or a Message object
         * @param $msg Mixed: message key (string) for page text, or a Message object
         * @param $params Array: message parameters; ignored if $msg is a Message object
         */
        public function showErrorPage( $title, $msg, $params = array() ) {
-               $this->prepareErrorPage( $this->msg( $title ), $this->msg( 'errorpagetitle' ) );
+               if( !$title instanceof Message ) {
+                       $title = $this->msg( $title );
+               }
+
+               $this->prepareErrorPage( $title );
 
                if ( $msg instanceof Message ){
                        $this->addHTML( $msg->parse() );
@@ -2077,8 +2073,6 @@ class OutputPage extends ContextSource {
         * @param $action String: action that was denied or null if unknown
         */
        public function showPermissionsErrorPage( $errors, $action = null ) {
-               global $wgGroupPermissions;
-
                // For some action (read, edit, create and upload), display a "login to do this action"
                // error if all of the following conditions are met:
                // 1. the user is not logged in
@@ -2087,8 +2081,8 @@ class OutputPage extends ContextSource {
                if ( in_array( $action, array( 'read', 'edit', 'createpage', 'createtalk', 'upload' ) )
                        && $this->getUser()->isAnon() && count( $errors ) == 1 && isset( $errors[0][0] )
                        && ( $errors[0][0] == 'badaccess-groups' || $errors[0][0] == 'badaccess-group0' )
-                       && ( ( isset( $wgGroupPermissions['user'][$action] ) && $wgGroupPermissions['user'][$action] )
-                       || ( isset( $wgGroupPermissions['autoconfirmed'][$action] ) && $wgGroupPermissions['autoconfirmed'][$action] ) )
+                       && ( User::groupHasPermission( 'user', $action )
+                       || User::groupHasPermission( 'autoconfirmed', $action ) )
                ) {
                        $displayReturnto = null;
 
@@ -2346,13 +2340,22 @@ $templates
         * Add a "return to" link pointing to a specified title
         *
         * @param $title Title to link
-        * @param $query String query string
+        * @param $query Array query string parameters
         * @param $text String text of the link (input is not escaped)
+        * @param $options Options array to pass to Linker
         */
-       public function addReturnTo( $title, $query = array(), $text = null ) {
-               $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
+       public function addReturnTo( $title, $query = array(), $text = null, $options = array() ) {
+               if( in_array( 'http', $options ) ) {
+                       $proto = PROTO_HTTP;
+               } elseif( in_array( 'https', $options ) ) {
+                       $proto = PROTO_HTTPS;
+               } else {
+                       $proto = PROTO_RELATIVE;
+               }
+
+               $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL( '', false, $proto ) ) );
                $link = $this->msg( 'returnto' )->rawParams(
-                       Linker::link( $title, $text, array(), $query ) )->escaped();
+                       Linker::link( $title, $text, array(), $query, $options ) )->escaped();
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
@@ -2386,7 +2389,7 @@ $templates
                        $titleObj = Title::newMainPage();
                }
 
-               $this->addReturnTo( $titleObj, $returntoquery );
+               $this->addReturnTo( $titleObj, wfCgiToArray( $returntoquery ) );
        }
 
        /**
@@ -2456,7 +2459,7 @@ $templates
         */
        private function addDefaultModules() {
                global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
-                       $wgAjaxWatch, $wgEnableMWSuggest;
+                       $wgAjaxWatch;
 
                // Add base resources
                $this->addModules( array(
@@ -2484,8 +2487,8 @@ $templates
                                $this->addModules( 'mediawiki.page.watch.ajax' );
                        }
 
-                       if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
-                               $this->addModules( 'mediawiki.legacy.mwsuggest' );
+                       if ( !$this->getUser()->getOption( 'disablesuggest', false ) ) {
+                               $this->addModules( 'mediawiki.searchSuggest' );
                        }
                }
 
@@ -2909,7 +2912,7 @@ $templates
         * @return array
         */
        public function getJSVars() {
-               global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
+               global $wgUseAjax, $wgContLang;
 
                $latestRevID = 0;
                $pageID = 0;
@@ -2975,9 +2978,6 @@ $templates
                foreach ( $title->getRestrictionTypes() as $type ) {
                        $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
                }
-               if ( $wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
-                       $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $this->getUser() );
-               }
                if ( $title->isMainPage() ) {
                        $vars['wgIsMainPage'] = true;
                }
@@ -3516,7 +3516,7 @@ $templates
         * Add a wikitext-formatted message to the output.
         * This is equivalent to:
         *
-        *    $wgOut->addWikiText( wfMsgNoTrans( ... ) )
+        *    $wgOut->addWikiText( wfMessage( ... )->plain() )
         */
        public function addWikiMsg( /*...*/ ) {
                $args = func_get_args();
@@ -3545,9 +3545,6 @@ $templates
         * message names, or arrays, in which case the first element is the message name,
         * and subsequent elements are the parameters to that message.
         *
-        * The special named parameter 'options' in a message specification array is passed
-        * through to the $options parameter of wfMsgExt().
-        *
         * Don't use this for messages that are not in users interface language.
         *
         * For example:
@@ -3556,7 +3553,7 @@ $templates
         *
         * Is equivalent to:
         *
-        *    $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "\n</div>" );
+        *    $wgOut->addWikiText( "<div class='error'>\n" . wfMessage( 'some-error' )->plain() . "\n</div>" );
         *
         * The newline after opening div is needed in some wikitext. See bug 19226.
         *
@@ -3573,14 +3570,17 @@ $templates
                                $args = $spec;
                                $name = array_shift( $args );
                                if ( isset( $args['options'] ) ) {
-                                       $options = $args['options'];
                                        unset( $args['options'] );
+                                       wfDeprecated(
+                                               'Adding "options" to ' . __METHOD__ . ' is no longer supported',
+                                               '1.20'
+                                       );
                                }
                        }  else {
                                $args = array();
                                $name = $spec;
                        }
-                       $s = str_replace( '$' . ( $n + 1 ), wfMsgExt( $name, $options, $args ), $s );
+                       $s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s );
                }
                $this->addWikiText( $s );
        }