Make UserNotLoggedIn redirect to login page
[lhc/web/wiklou.git] / includes / specialpage / SpecialPage.php
index 4cfde33..df8d9de 100644 (file)
@@ -101,8 +101,8 @@ class SpecialPage {
         * @param string $name Name of the special page, as seen in links and URLs
         * @param string $restriction User right required, e.g. "block" or "delete"
         * @param bool $listed Whether the page is listed in Special:Specialpages
-        * @param callable|bool $function unused
-        * @param string $file unused
+        * @param callable|bool $function Unused
+        * @param string $file Unused
         * @param bool $includable Whether the page can be included in normal pages
         */
        public function __construct(
@@ -134,7 +134,7 @@ class SpecialPage {
        // @todo FIXME: Decide which syntax to use for this, and stick to it
        /**
         * Whether this special page is listed in Special:SpecialPages
-        * @since r3583 (v1.3)
+        * @since 1.3 (r3583)
         * @return bool
         */
        function isListed() {
@@ -274,44 +274,20 @@ class SpecialPage {
        }
 
        /**
-        * If the user is not logged in, throws UserNotLoggedIn error.
+        * If the user is not logged in, throws UserNotLoggedIn error
         *
-        * Default error message includes a link to Special:Userlogin with properly set 'returnto' query
-        * parameter.
+        * The user will be redirected to Special:Userlogin with the given message as an error on
+        * the form.
         *
         * @since 1.23
-        * @param string|Message $reasonMsg [optional] Passed on to UserNotLoggedIn constructor. Strings
-        *     will be used as message keys. If a string is given, the message will also receive a
-        *     formatted login link (generated using the 'loginreqlink' message) as first parameter. If a
-        *     Message is given, it will be passed on verbatim.
-        * @param string|Message $titleMsg [optional] Passed on to UserNotLoggedIn constructor. Strings
-        *     will be used as message keys.
+        * @param string $reasonMsg [optional] Message key to be displayed on login page
+        * @param string $titleMsg [optional] Passed on to UserNotLoggedIn constructor
         * @throws UserNotLoggedIn
         */
-       public function requireLogin( $reasonMsg = null, $titleMsg = null ) {
+       public function requireLogin(
+               $reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin'
+       ) {
                if ( $this->getUser()->isAnon() ) {
-                       // Use default messages if not given or explicit null passed
-                       if ( !$reasonMsg ) {
-                               $reasonMsg = 'exception-nologin-text-manual';
-                       }
-                       if ( !$titleMsg ) {
-                               $titleMsg = 'exception-nologin';
-                       }
-
-                       // Convert to Messages with current context
-                       if ( is_string( $reasonMsg ) ) {
-                               $loginreqlink = Linker::linkKnown(
-                                       SpecialPage::getTitleFor( 'Userlogin' ),
-                                       $this->msg( 'loginreqlink' )->escaped(),
-                                       array(),
-                                       array( 'returnto' => $this->getPageTitle()->getPrefixedText() )
-                               );
-                               $reasonMsg = $this->msg( $reasonMsg )->rawParams( $loginreqlink );
-                       }
-                       if ( is_string( $titleMsg ) ) {
-                               $titleMsg = $this->msg( $titleMsg );
-                       }
-
                        throw new UserNotLoggedIn( $reasonMsg, $titleMsg );
                }
        }
@@ -328,7 +304,7 @@ class SpecialPage {
         *   - `prefixSearchSubpages( "" )` should return `array( foo", "bar", "baz" )`
         *
         * @param string $search Prefix to search for
-        * @param integer $limit Maximum number of results to return
+        * @param int $limit Maximum number of results to return
         * @return string[] Matching subpages
         */
        public function prefixSearchSubpages( $search, $limit = 10 ) {
@@ -345,8 +321,8 @@ class SpecialPage {
         * @param array $subpages
         * @return string[]
         */
-       protected static function prefixSearchArray( $search, $limit, Array $subpages ) {
-               $escaped = preg_quote( $search );
+       protected static function prefixSearchArray( $search, $limit, array $subpages ) {
+               $escaped = preg_quote( $search, '/' );
                return array_slice( preg_grep( "/^$escaped/i", $subpages ), 0, $limit );
        }