Be consistent in the interface and use Title::quickUserCan() instead of Title::userCa...
[lhc/web/wiklou.git] / includes / SpecialPageFactory.php
index eb19200..6610451 100644 (file)
@@ -138,6 +138,7 @@ class SpecialPageFactory {
                'Blankpage'                 => 'SpecialBlankpage',
                'Blockme'                   => 'SpecialBlockme',
                'Emailuser'                 => 'SpecialEmailUser',
+               'JavaScriptTest'            => 'SpecialJavaScriptTest',
                'Movepage'                  => 'MovePageForm',
                'Mycontributions'           => 'SpecialMycontributions',
                'Mypage'                    => 'SpecialMypage',
@@ -275,6 +276,7 @@ class SpecialPageFactory {
         * Get the group that the special page belongs in on Special:SpecialPage
         *
         * @param $page SpecialPage
+        * @return String
         */
        public static function getGroup( &$page ) {
                $name = $page->getName();
@@ -339,18 +341,21 @@ class SpecialPageFactory {
         * Return categorised listable special pages which are available
         * for the current user, and everyone.
         *
+        * @param $user User object to check permissions, $wgUser will be used
+        *              if not provided
         * @return Array( String => Specialpage )
         */
-       public static function getUsablePages() {
-               global $wgUser;
+       public static function getUsablePages( User $user = null ) {
                $pages = array();
+               if ( $user === null ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
                foreach ( self::getList() as $name => $rec ) {
                        $page = self::getPage( $name );
-                       if ( $page->isListed()
-                               && (
-                                       !$page->isRestricted()
-                                       || $page->userCanExecute( $wgUser )
-                               )
+                       if ( $page // not null
+                               && $page->isListed()
+                               && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
                        ) {
                                $pages[$name] = $page;
                        }
@@ -426,7 +431,12 @@ class SpecialPageFactory {
                if ( !$page ) {
                        $context->getOutput()->setArticleRelated( false );
                        $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
-                       $context->getOutput()->setStatusCode( 404 );
+
+                       global $wgSend404Code;
+                       if ( $wgSend404Code ) {
+                               $context->getOutput()->setStatusCode( 404 );
+                       }
+
                        $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
                        wfProfileOut( __METHOD__ );
                        return false;
@@ -500,7 +510,7 @@ class SpecialPageFactory {
                $wgOut = $context->getOutput();
                $wgRequest = $context->getRequest();
                $wgUser = $context->getUser();
-               $wgLang = $context->getLang();
+               $wgLang = $context->getLanguage();
 
                // The useful part
                $ret = self::executePath( $title, $context, true );