Index: trunk/phase3/includes/SpecialPageFactory.php |
— | — | @@ -416,19 +416,21 @@ |
417 | 417 | |
418 | 418 | // Check for redirect |
419 | 419 | if ( !$including ) { |
420 | | - $redirect = $page->getRedirect( $par ); |
421 | | - $query = $page->getRedirectQuery(); |
422 | | - if ( $redirect instanceof Title ) { |
423 | | - $url = $redirect->getFullUrl( $query ); |
424 | | - $context->output->redirect( $url ); |
425 | | - wfProfileOut( __METHOD__ ); |
426 | | - return $redirect; |
427 | | - } elseif ( $redirect === true ) { |
428 | | - global $wgScript; |
429 | | - $url = $wgScript . '?' . wfArrayToCGI( $query ); |
430 | | - $context->output->redirect( $url ); |
431 | | - wfProfileOut( __METHOD__ ); |
432 | | - return $redirect; |
| 420 | + if( $page instanceof SpecialRedirectToSpecial ){ |
| 421 | + $redirect = $page->getRedirect( $par ); |
| 422 | + $query = $page->getRedirectQuery(); |
| 423 | + if ( $redirect instanceof Title ) { |
| 424 | + $url = $redirect->getFullUrl( $query ); |
| 425 | + $context->output->redirect( $url ); |
| 426 | + wfProfileOut( __METHOD__ ); |
| 427 | + return $redirect; |
| 428 | + } elseif ( $redirect === true ) { |
| 429 | + global $wgScript; |
| 430 | + $url = $wgScript . '?' . wfArrayToCGI( $query ); |
| 431 | + $context->output->redirect( $url ); |
| 432 | + wfProfileOut( __METHOD__ ); |
| 433 | + return $redirect; |
| 434 | + } |
433 | 435 | } |
434 | 436 | |
435 | 437 | // Redirect to canonical alias for GET commands |
— | — | @@ -449,7 +451,7 @@ |
450 | 452 | $context->title = $page->getTitle(); |
451 | 453 | } |
452 | 454 | |
453 | | - } elseif ( !$page->includable() ) { |
| 455 | + } elseif ( !$page->isIncludable() ) { |
454 | 456 | wfProfileOut( __METHOD__ ); |
455 | 457 | return false; |
456 | 458 | } |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -28,52 +28,34 @@ |
29 | 29 | * @ingroup SpecialPage |
30 | 30 | */ |
31 | 31 | class SpecialPage { |
32 | | - /**#@+ |
33 | | - * @access private |
34 | | - */ |
| 32 | + |
| 33 | + // The canonical name of this special page |
| 34 | + // Also used for the default <h1> heading, @see getDescription() |
| 35 | + /*private*/ var $mName; |
| 36 | + |
| 37 | + // The local name of this special page |
| 38 | + private $mLocalName; |
| 39 | + |
| 40 | + // Minimum user level required to access this page, or "" for anyone. |
| 41 | + // Also used to categorise the pages in Special:Specialpages |
| 42 | + private $mRestriction; |
| 43 | + |
| 44 | + // Listed in Special:Specialpages? |
| 45 | + private $mListed; |
| 46 | + |
| 47 | + // Function name called by the default execute() |
| 48 | + private $mFunction; |
| 49 | + |
| 50 | + // File which needs to be included before the function above can be called |
| 51 | + private $mFile; |
| 52 | + |
| 53 | + // Whether or not this special page is being included from an article |
| 54 | + protected $mIncluding; |
| 55 | + |
| 56 | + // Whether the special page can be included in an article |
| 57 | + protected $mIncludable; |
| 58 | + |
35 | 59 | /** |
36 | | - * The canonical name of this special page |
37 | | - * Also used for the default <h1> heading, @see getDescription() |
38 | | - */ |
39 | | - var $mName; |
40 | | - /** |
41 | | - * The local name of this special page |
42 | | - */ |
43 | | - var $mLocalName; |
44 | | - /** |
45 | | - * Minimum user level required to access this page, or "" for anyone. |
46 | | - * Also used to categorise the pages in Special:Specialpages |
47 | | - */ |
48 | | - var $mRestriction; |
49 | | - /** |
50 | | - * Listed in Special:Specialpages? |
51 | | - */ |
52 | | - var $mListed; |
53 | | - /** |
54 | | - * Function name called by the default execute() |
55 | | - */ |
56 | | - var $mFunction; |
57 | | - /** |
58 | | - * File which needs to be included before the function above can be called |
59 | | - */ |
60 | | - var $mFile; |
61 | | - /** |
62 | | - * Whether or not this special page is being included from an article |
63 | | - */ |
64 | | - var $mIncluding; |
65 | | - /** |
66 | | - * Whether the special page can be included in an article |
67 | | - */ |
68 | | - var $mIncludable; |
69 | | - /** |
70 | | - * Query parameters that can be passed through redirects |
71 | | - */ |
72 | | - var $mAllowedRedirectParams = array(); |
73 | | - /** |
74 | | - * Query parameteres added by redirects |
75 | | - */ |
76 | | - var $mAddedRedirectParams = array(); |
77 | | - /** |
78 | 60 | * Current request context |
79 | 61 | * @var RequestContext |
80 | 62 | */ |
— | — | @@ -380,25 +362,87 @@ |
381 | 363 | } |
382 | 364 | } |
383 | 365 | |
384 | | - function getName() { return $this->mName; } |
385 | | - function getRestriction() { return $this->mRestriction; } |
386 | | - function getFile() { return $this->mFile; } |
387 | | - function isListed() { return $this->mListed; } |
| 366 | + /** |
| 367 | + * Get the name of this Special Page. |
| 368 | + * @return String |
| 369 | + */ |
| 370 | + function getName() { |
| 371 | + return $this->mName; |
| 372 | + } |
388 | 373 | |
| 374 | + /** |
| 375 | + * Get the permission that a user must have to execute this page |
| 376 | + * @return String |
| 377 | + */ |
| 378 | + function getRestriction() { |
| 379 | + return $this->mRestriction; |
| 380 | + } |
| 381 | + |
| 382 | + /** |
| 383 | + * Get the file which will be included by SpecialPage::execute() if your extension is |
| 384 | + * still stuck in the past and hasn't overridden the execute() method. No modern code |
| 385 | + * should want or need to know this. |
| 386 | + * @return String |
| 387 | + * @deprecated since 1.18 |
| 388 | + */ |
| 389 | + function getFile() { |
| 390 | + return $this->mFile; |
| 391 | + } |
| 392 | + |
| 393 | + // FIXME: decide which syntax to use for this, and stick to it |
| 394 | + /** |
| 395 | + * Whether this special page is listed in Special:SpecialPages |
| 396 | + * @since r3583 (v1.3) |
| 397 | + * @return Bool |
| 398 | + */ |
| 399 | + function isListed() { |
| 400 | + return $this->mListed; |
| 401 | + } |
| 402 | + /** |
| 403 | + * Set whether this page is listed in Special:Specialpages, at run-time |
| 404 | + * @since r3583 (v1.3) |
| 405 | + * @return Bool |
| 406 | + */ |
| 407 | + function setListed( $listed ) { |
| 408 | + return wfSetVar( $this->mListed, $listed ); |
| 409 | + } |
| 410 | + /** |
| 411 | + * Get or set whether this special page is listed in Special:SpecialPages |
| 412 | + * @since r11308 (v1.6) |
| 413 | + * @return Bool |
| 414 | + */ |
| 415 | + function listed( $x = null) { |
| 416 | + return wfSetVar( $this->mListed, $x ); |
| 417 | + } |
| 418 | + |
| 419 | + /** |
| 420 | + * Whether it's allowed to transclude the special page via {{Special:Foo/params}} |
| 421 | + * @return Bool |
| 422 | + */ |
| 423 | + public function isIncludable(){ |
| 424 | + return $this->mIncludable; |
| 425 | + } |
| 426 | + |
| 427 | + /** |
| 428 | + * These mutators are very evil, as the relevant variables should not mutate. So |
| 429 | + * don't use them. |
| 430 | + * @deprecated since 1.18 |
| 431 | + */ |
389 | 432 | function name( $x = null ) { return wfSetVar( $this->mName, $x ); } |
390 | | - function restrictions( $x = null) { |
391 | | - # Use the one below this |
392 | | - wfDeprecated( __METHOD__ ); |
393 | | - return wfSetVar( $this->mRestriction, $x ); |
394 | | - } |
395 | 433 | function restriction( $x = null) { return wfSetVar( $this->mRestriction, $x ); } |
396 | | - function listed( $x = null) { return wfSetVar( $this->mListed, $x ); } |
397 | 434 | function func( $x = null) { return wfSetVar( $this->mFunction, $x ); } |
398 | 435 | function file( $x = null) { return wfSetVar( $this->mFile, $x ); } |
399 | 436 | function includable( $x = null ) { return wfSetVar( $this->mIncludable, $x ); } |
400 | | - function including( $x = null ) { return wfSetVar( $this->mIncluding, $x ); } |
401 | 437 | |
402 | 438 | /** |
| 439 | + * Whether the special page is being evaluated via transclusion |
| 440 | + * @return Bool |
| 441 | + */ |
| 442 | + function including( $x = null ) { |
| 443 | + return wfSetVar( $this->mIncluding, $x ); |
| 444 | + } |
| 445 | + |
| 446 | + /** |
403 | 447 | * Get the localised name of the special page |
404 | 448 | */ |
405 | 449 | function getLocalName() { |
— | — | @@ -528,49 +572,6 @@ |
529 | 573 | function getTitle( $subpage = false ) { |
530 | 574 | return self::getTitleFor( $this->mName, $subpage ); |
531 | 575 | } |
532 | | - |
533 | | - /** |
534 | | - * Set whether this page is listed in Special:Specialpages, at run-time |
535 | | - * |
536 | | - * @return Bool |
537 | | - */ |
538 | | - function setListed( $listed ) { |
539 | | - return wfSetVar( $this->mListed, $listed ); |
540 | | - } |
541 | | - |
542 | | - /** |
543 | | - * If the special page is a redirect, then get the Title object it redirects to. |
544 | | - * False otherwise. |
545 | | - * |
546 | | - * @return Title|false |
547 | | - */ |
548 | | - function getRedirect( $subpage ) { |
549 | | - return false; |
550 | | - } |
551 | | - |
552 | | - /** |
553 | | - * Return part of the request string for a special redirect page |
554 | | - * This allows passing, e.g. action=history to Special:Mypage, etc. |
555 | | - * |
556 | | - * @return String |
557 | | - */ |
558 | | - function getRedirectQuery() { |
559 | | - $params = array(); |
560 | | - |
561 | | - foreach( $this->mAllowedRedirectParams as $arg ) { |
562 | | - if( $this->getContext()->request->getVal( $arg, null ) !== null ){ |
563 | | - $params[$arg] = $this->getContext()->request->getVal( $arg ); |
564 | | - } |
565 | | - } |
566 | | - |
567 | | - foreach( $this->mAddedRedirectParams as $arg => $val ) { |
568 | | - $params[$arg] = $val; |
569 | | - } |
570 | | - |
571 | | - return count( $params ) |
572 | | - ? $params |
573 | | - : false; |
574 | | - } |
575 | 576 | |
576 | 577 | /** |
577 | 578 | * Sets the context this SpecialPage is executed in |
— | — | @@ -667,6 +668,10 @@ |
668 | 669 | function __construct( $name, $restriction = '', $function = false, $file = 'default' ) { |
669 | 670 | parent::__construct( $name, $restriction, false, $function, $file ); |
670 | 671 | } |
| 672 | + |
| 673 | + public function isListed(){ |
| 674 | + return false; |
| 675 | + } |
671 | 676 | } |
672 | 677 | |
673 | 678 | /** |
— | — | @@ -678,6 +683,10 @@ |
679 | 684 | function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) { |
680 | 685 | parent::__construct( $name, $restriction, $listed, $function, $file, true ); |
681 | 686 | } |
| 687 | + |
| 688 | + public function isIncludable(){ |
| 689 | + return true; |
| 690 | + } |
682 | 691 | } |
683 | 692 | |
684 | 693 | /** |
— | — | @@ -685,6 +694,13 @@ |
686 | 695 | * @ingroup SpecialPage |
687 | 696 | */ |
688 | 697 | abstract class SpecialRedirectToSpecial extends UnlistedSpecialPage { |
| 698 | + |
| 699 | + // Query parameters that can be passed through redirects |
| 700 | + private $mAllowedRedirectParams = array(); |
| 701 | + |
| 702 | + // Query parameteres added by redirects |
| 703 | + private $mAddedRedirectParams = array(); |
| 704 | + |
689 | 705 | var $redirName, $redirSubpage; |
690 | 706 | |
691 | 707 | function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) { |
— | — | @@ -695,13 +711,43 @@ |
696 | 712 | $this->mAddedRedirectParams = $addedRedirectParams; |
697 | 713 | } |
698 | 714 | |
699 | | - function getRedirect( $subpage ) { |
| 715 | + /** |
| 716 | + * If the special page is a redirect, then get the Title object it redirects to. |
| 717 | + * False otherwise. |
| 718 | + * |
| 719 | + * @return Title|false |
| 720 | + */ |
| 721 | + public function getRedirect( $subpage ) { |
700 | 722 | if ( $this->redirSubpage === false ) { |
701 | 723 | return SpecialPage::getTitleFor( $this->redirName, $subpage ); |
702 | 724 | } else { |
703 | 725 | return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage ); |
704 | 726 | } |
705 | 727 | } |
| 728 | + |
| 729 | + /** |
| 730 | + * Return part of the request string for a special redirect page |
| 731 | + * This allows passing, e.g. action=history to Special:Mypage, etc. |
| 732 | + * |
| 733 | + * @return String |
| 734 | + */ |
| 735 | + public function getRedirectQuery() { |
| 736 | + $params = array(); |
| 737 | + |
| 738 | + foreach( $this->mAllowedRedirectParams as $arg ) { |
| 739 | + if( $this->getContext()->request->getVal( $arg, null ) !== null ){ |
| 740 | + $params[$arg] = $this->getContext()->request->getVal( $arg ); |
| 741 | + } |
| 742 | + } |
| 743 | + |
| 744 | + foreach( $this->mAddedRedirectParams as $arg => $val ) { |
| 745 | + $params[$arg] = $val; |
| 746 | + } |
| 747 | + |
| 748 | + return count( $params ) |
| 749 | + ? $params |
| 750 | + : false; |
| 751 | + } |
706 | 752 | } |
707 | 753 | |
708 | 754 | /** |
— | — | @@ -794,7 +840,7 @@ |
795 | 841 | |
796 | 842 | function getRedirect( $subpage ) { |
797 | 843 | global $wgUser; |
798 | | - return SpecialPageFactory::getTitleFor( 'Contributions', $wgUser->getName() ); |
| 844 | + return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() ); |
799 | 845 | } |
800 | 846 | } |
801 | 847 | |
— | — | @@ -809,7 +855,7 @@ |
810 | 856 | |
811 | 857 | function getRedirect( $subpage ) { |
812 | 858 | global $wgUser; |
813 | | - return SpecialPageFactory::getTitleFor( 'Listfiles', $wgUser->getName() ); |
| 859 | + return SpecialPage::getTitleFor( 'Listfiles', $wgUser->getName() ); |
814 | 860 | } |
815 | 861 | } |
816 | 862 | |
Index: trunk/extensions/Configure/specials/ConfigurationPage.php |
— | — | @@ -140,7 +140,7 @@ |
141 | 141 | static $allowed = null; |
142 | 142 | if ( $allowed === null ) { |
143 | 143 | global $wgUser; |
144 | | - $allowed = $wgUser->isAllowed( $this->mRestriction . '-all' ); |
| 144 | + $allowed = $wgUser->isAllowed( $this->getRestriction() . '-all' ); |
145 | 145 | } |
146 | 146 | return $allowed; |
147 | 147 | } |
— | — | @@ -153,7 +153,7 @@ |
154 | 154 | static $allowed = null; |
155 | 155 | if ( $allowed === null ) { |
156 | 156 | global $wgUser; |
157 | | - $allowed = $wgUser->isAllowed( $this->mRestriction . '-interwiki' ); |
| 157 | + $allowed = $wgUser->isAllowed( $this->getRestriction() . '-interwiki' ); |
158 | 158 | } |
159 | 159 | return $allowed; |
160 | 160 | } |
Index: trunk/extensions/examples/SpecialIncludable.php |
— | — | @@ -25,18 +25,17 @@ |
26 | 26 | // See FourFileTemplate how to do i18n |
27 | 27 | //$wgExtensionMessagesFiles['Includable'] = dirname( __FILE__ ) . '/Includable.i18n.php'; |
28 | 28 | |
29 | | -class SpecialIncludable extends SpecialPage { |
| 29 | +class SpecialIncludable extends IncludableSpecialPage { |
30 | 30 | /** |
31 | 31 | * Constructor |
32 | 32 | */ |
33 | 33 | function __construct() { |
34 | 34 | parent::__construct( 'Includable' ); |
35 | | - $this->includable( true ); |
36 | 35 | } |
37 | 36 | |
38 | 37 | /** |
39 | | - * main() |
40 | | - */ |
| 38 | + * main() |
| 39 | + */ |
41 | 40 | function execute( $par = null ) { |
42 | 41 | global $wgOut; |
43 | 42 | |