Merge "Misc fixes in RevisionDelete.php."
[lhc/web/wiklou.git] / includes / SpecialPageFactory.php
index 86c0bce..02b8d54 100644 (file)
@@ -1,6 +1,29 @@
 <?php
 /**
- * SpecialPage: handling special pages and lists thereof.
+ * Factory for handling the special page list and generating SpecialPage objects.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ * @defgroup SpecialPage SpecialPage
+ */
+
+/**
+ * Factory for handling the special page list and generating SpecialPage objects.
  *
  * To add a special page in an extension, add to $wgSpecialPages either
  * an object instance or an array containing the name and constructor
  * SpecialPage::$mList. To remove a core static special page at runtime, use
  * a SpecialPage_initList hook.
  *
- * @file
- * @ingroup SpecialPage
- * @defgroup SpecialPage SpecialPage
- */
-
-/**
- * Factory for handling the special page list and generating SpecialPage objects
  * @ingroup SpecialPage
  * @since 1.17
  */
@@ -126,8 +142,6 @@ class SpecialPageFactory {
                // Page tools
                'ComparePages'              => 'SpecialComparePages',
                'Export'                    => 'SpecialExport',
-               'GlobalFileUsage'           => 'SpecialGlobalFileUsage',
-               'GlobalTemplateUsage'       => 'SpecialGlobalTemplateUsage',
                'Import'                    => 'SpecialImport',
                'Undelete'                  => 'SpecialUndelete',
                'Whatlinkshere'             => 'SpecialWhatlinkshere',
@@ -140,6 +154,7 @@ class SpecialPageFactory {
                'Blankpage'                 => 'SpecialBlankpage',
                'Blockme'                   => 'SpecialBlockme',
                'Emailuser'                 => 'SpecialEmailUser',
+               'JavaScriptTest'            => 'SpecialJavaScriptTest',
                'Movepage'                  => 'MovePageForm',
                'Mycontributions'           => 'SpecialMycontributions',
                'Mypage'                    => 'SpecialMypage',
@@ -264,7 +279,7 @@ class SpecialPageFactory {
        /**
         * Add a page to a certain display group for Special:SpecialPages
         *
-        * @param $page SpecialPage|string
+        * @param $page Mixed: SpecialPage or string
         * @param $group String
         */
        public static function setGroup( $page, $group ) {
@@ -277,8 +292,7 @@ class SpecialPageFactory {
         * Get the group that the special page belongs in on Special:SpecialPage
         *
         * @param $page SpecialPage
-        *
-        * @return string
+        * @return String
         */
        public static function getGroup( &$page ) {
                $name = $page->getName();
@@ -343,18 +357,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;
                        }
@@ -409,12 +426,12 @@ class SpecialPageFactory {
         * 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
         */
-       public static function executePath( Title &$title, RequestContext &$context, $including = false ) {
+       public static function executePath( Title &$title, IContextSource &$context, $including = false ) {
                wfProfileIn( __METHOD__ );
 
                // @todo FIXME: Redirects broken due to this call
@@ -430,7 +447,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;
@@ -455,7 +477,7 @@ class SpecialPageFactory {
                                wfProfileOut( __METHOD__ );
                                return $title;
                        } else {
-                               $context->setTitle( $page->getTitle() );
+                               $context->setTitle( $page->getTitle( $par ) );
                        }
 
                } elseif ( !$page->isIncludable() ) {
@@ -476,20 +498,20 @@ class SpecialPageFactory {
 
        /**
         * Just like executePath() but will override global variables and execute
-        * the page in "inclusion" mode. Returns true if the excution was successful
-        * or false if there was no such special page, or a title object if it was
-        * a redirect.
+        * the page in "inclusion" mode. Returns true if the execution was
+        * successful or false if there was no such special page, or a title object
+        * if it was a redirect.
         *
         * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang
         * variables so that the special page will get the context it'd expect on a
         * normal request, and then restores them to their previous values after.
         *
         * @param $title Title
-        * @param $context RequestContext
+        * @param $context IContextSource
         *
         * @return String: HTML fragment
         */
-       static function capturePath( Title $title, RequestContext $context ) {
+       static function capturePath( Title $title, IContextSource $context ) {
                global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;
 
                // Save current globals
@@ -504,12 +526,12 @@ 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 );
 
-               // And restore that globals
+               // And restore the old globals
                $wgTitle = $oldTitle;
                $wgOut = $oldOut;
                $wgRequest = $oldRequest;