r103095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103094‎ | r103095 | r103096 >
Date:00:37, 15 November 2011
Author:johnduhart
Status:ok (Comments)
Tags:
Comment:
Added function to SpecialPage to simplify permissions checking in SpecialPage classes.
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialPage.php
@@ -511,6 +511,17 @@
512512 }
513513
514514 /**
 515+ * Checks if userCanExecute, and if not throws a PermissionsError
 516+ *
 517+ * @since 1.19
 518+ */
 519+ public function checkPermissions() {
 520+ if ( !$this->userCanExecute( $this->getUser() ) ) {
 521+ $this->displayRestrictionError();
 522+ }
 523+ }
 524+
 525+ /**
515526 * Sets headers - this should be called from the execute() method of all derived classes!
516527 */
517528 function setHeaders() {
@@ -530,18 +541,15 @@
531542 */
532543 function execute( $par ) {
533544 $this->setHeaders();
 545+ $this->checkPermissions();
534546
535 - if ( $this->userCanExecute( $this->getUser() ) ) {
536 - $func = $this->mFunction;
537 - // only load file if the function does not exist
538 - if( !is_callable($func) && $this->mFile ) {
539 - require_once( $this->mFile );
540 - }
541 - $this->outputHeader();
542 - call_user_func( $func, $par, $this );
543 - } else {
544 - $this->displayRestrictionError();
 547+ $func = $this->mFunction;
 548+ // only load file if the function does not exist
 549+ if( !is_callable($func) && $this->mFile ) {
 550+ require_once( $this->mFile );
545551 }
 552+ $this->outputHeader();
 553+ call_user_func( $func, $par, $this );
546554 }
547555
548556 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r103096Followup r100506 and add permissions checking that I missed using functions a...johnduhart00:41, 15 November 2011
r103115Updated core SpecialPages to use new functions introduced in r103111 and r103095johnduhart01:34, 15 November 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   00:38, 15 November 2011

One of the subclasses has a checkExecutePermissions(). A merge might be a good idea.

#Comment by Johnduhart (talk | contribs)   02:44, 15 November 2011

Not exactly a merge, but r103111 changes a few things with that.

Status & tagging log