Use local context to get messages
[lhc/web/wiklou.git] / includes / SpecialPage.php
index 8bca60b..fca8c06 100644 (file)
@@ -31,7 +31,7 @@ class SpecialPage {
 
        // The canonical name of this special page
        // Also used for the default <h1> heading, @see getDescription()
-       /*private*/ var $mName;
+       protected $mName;
 
        // The local name of this special page
        private $mLocalName;
@@ -57,7 +57,7 @@ class SpecialPage {
 
        /**
         * Current request context
-        * @var RequestContext
+        * @var IContextSource
         */
        protected $mContext;
 
@@ -226,28 +226,15 @@ class SpecialPage {
         * page, and true if it was successful.
         *
         * @param $title          Title object
-        * @param $context        RequestContext
+        * @param $context        IContextSource
         * @param $including      Bool output is being captured for use in {{special:whatever}}
         * @return Bool
         * @deprecated since 1.18 call SpecialPageFactory method directly
         */
-       public static function executePath( &$title, RequestContext &$context, $including = false ) {
+       public static function executePath( &$title, IContextSource &$context, $including = false ) {
                return SpecialPageFactory::executePath( $title, $context, $including );
        }
 
-       /**
-        * Just like executePath() except it returns the HTML instead of outputting it
-        * Returns false if there was no such special page, or a title object if it was
-        * a redirect.
-        *
-        * @param $title Title
-        * @return String: HTML fragment
-        * @deprecated since 1.18 call SpecialPageFactory method directly
-        */
-       static function capturePath( &$title ) {
-               return SpecialPageFactory::capturePath( $title );
-       }
-
        /**
         * Get the local name for a specified canonical name
         *
@@ -545,7 +532,7 @@ class SpecialPage {
                if ( $this->userCanExecute( $this->getUser() ) ) {
                        $func = $this->mFunction;
                        // only load file if the function does not exist
-                       if(!is_callable($func) and $this->mFile) {
+                       if( !is_callable($func) && $this->mFile ) {
                                require_once( $this->mFile );
                        }
                        $this->outputHeader();
@@ -571,7 +558,7 @@ class SpecialPage {
                } else {
                        $msg = $summaryMessageKey;
                }
-               if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
+               if ( !$this->msg( $msg )->isBlank() && !$this->including() ) {
                        $this->getOutput()->wrapWikiMsg(
                                "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
                }
@@ -589,7 +576,7 @@ class SpecialPage {
         * @return String
         */
        function getDescription() {
-               return wfMsg( strtolower( $this->mName ) );
+               return $this->msg( strtolower( $this->mName ) )->text();
        }
 
        /**
@@ -605,7 +592,7 @@ class SpecialPage {
        /**
         * Sets the context this SpecialPage is executed in
         *
-        * @param $context RequestContext
+        * @param $context IContextSource
         * @since 1.18
         */
        public function setContext( $context ) {
@@ -615,11 +602,11 @@ class SpecialPage {
        /**
         * Gets the context this SpecialPage is executed in
         *
-        * @return RequestContext
+        * @return IContextSource
         * @since 1.18
         */
        public function getContext() {
-               if ( $this->mContext instanceof RequestContext ) {
+               if ( $this->mContext instanceof IContextSource ) {
                        return $this->mContext;
                } else {
                        wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
@@ -671,7 +658,7 @@ class SpecialPage {
         * Shortcut to get user's language
         *
         * @return Language
-        * @since 1.19
+        * @since 1.18
         */
        public function getLang() {
                return $this->getContext()->getLang();
@@ -694,7 +681,12 @@ class SpecialPage {
         * @see wfMessage
         */
        public function msg( /* $args */ ) {
-               return call_user_func_array( array( $this->getContext(), 'msg' ), func_get_args() );
+               // Note: can't use func_get_args() directly as second or later item in
+               // a parameter list until PHP 5.3 or you get a fatal error.
+               // Works fine as the first parameter, which appears elsewhere in the
+               // code base. Sighhhh.
+               $args = func_get_args();
+               return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
        }
 
        /**
@@ -703,14 +695,14 @@ class SpecialPage {
         * @param $params array
         */
        protected function addFeedLinks( $params ) {
-               global $wgFeedClasses, $wgOut;
+               global $wgFeedClasses;
 
                $feedTemplate = wfScript( 'api' ) . '?';
 
                foreach( $wgFeedClasses as $format => $class ) {
                        $theseParams = $params + array( 'feedformat' => $format );
                        $url = $feedTemplate . wfArrayToCGI( $theseParams );
-                       $wgOut->addFeedLink( $format, $url );
+                       $this->getOutput()->addFeedLink( $format, $url );
                }
        }
 }
@@ -748,14 +740,11 @@ abstract class FormSpecialPage extends SpecialPage {
        protected function getForm() {
                $this->fields = $this->getFormFields();
 
-               // Give hooks a chance to alter the form, adding extra fields or text etc
-               wfRunHooks( "Special{$this->getName()}ModifyFormFields", array( &$this->fields ) );
-
                $form = new HTMLForm( $this->fields, $this->getContext() );
                $form->setSubmitCallback( array( $this, 'onSubmit' ) );
-               $form->setWrapperLegend( wfMessage( strtolower( $this->getName() ) . '-legend' ) );
+               $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
                $form->addHeaderText(
-                       wfMessage( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
+                       $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
 
                // Retain query parameters (uselang etc)
                $params = array_diff_key(
@@ -1016,7 +1005,9 @@ class SpecialMypage extends RedirectSpecialPage {
        function __construct() {
                parent::__construct( 'Mypage' );
                $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
-                       'section', 'oldid', 'diff', 'dir' );
+                       'section', 'oldid', 'diff', 'dir',
+                       // Options for action=raw; missing ctype can break JS or CSS in some browsers
+                       'ctype', 'maxage', 'smaxage' );
        }
 
        function getRedirect( $subpage ) {