r82567 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82566‎ | r82567 | r82568 >
Date:19:28, 21 February 2011
Author:ialex
Status:deferred
Tags:
Comment:
Removed some usages of $wgTitle
Modified paths:
  • /trunk/extensions/AuthorProtect/AuthorProtect.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AuthorProtect/AuthorProtect.php
@@ -23,7 +23,7 @@
2424 $wgExtensionMessagesFiles['AuthorProtect'] = dirname( __FILE__ ) . '/AuthorProtect.i18n.php';
2525 $wgGroupPermissions['sysop']['author'] = true; // sysops can edit every page despite author protection
2626 $wgGroupPermissions['user']['authorprotect'] = true; // registered users can protect pages they author
27 -$wgHooks['SkinTemplateContentActions'][] = 'efMakeContentAction';
 27+$wgHooks['SkinTemplateNavigation::Universal'][] = 'efMakeContentAction';
2828 $wgHooks['UnknownAction'][] = 'efAuthorProtectForm';
2929 $wgHooks['userCan'][] = 'efAuthorProtectDelay';
3030 $wgHooks['UserGetRights'][] = 'efAssignAuthor';
@@ -44,7 +44,7 @@
4545 $user->getRights(); // delay hook execution for compatibility w/ ConfirmAccount
4646 $act = ( $action == '' || $action == 'view' ) ? 'edit' : $action;
4747 $wgAuthorProtectDelayRun = false;
48 - if ( userIsAuthor() && isAuthorProtected( $title, $act ) ) {
 48+ if ( userIsAuthor( $title ) && isAuthorProtected( $title, $act ) ) {
4949 $result = true;
5050 return false;
5151 }
@@ -83,28 +83,29 @@
8484 $wgUser->getRights();
8585 }
8686
87 -function efMakeContentAction( &$cactions ) {
88 - global $wgUser, $wgRequest, $wgTitle;
89 - if ( userIsAuthor() && $wgUser->isAllowed( 'authorprotect' ) && !$wgUser->isAllowed( 'protect' ) ) {
 87+function efMakeContentAction( $skin, &$cactions ) {
 88+ global $wgUser, $wgRequest;
 89+
 90+ $title = $skin->getTitle();
 91+ if ( userIsAuthor( $title ) && $wgUser->isAllowed( 'authorprotect' ) && !$wgUser->isAllowed( 'protect' ) ) {
9092 $action = $wgRequest->getText( 'action' );
91 - $cactions['authorprotect'] = array(
 93+ $cactions['actions']['authorprotect'] = array(
9294 'class' => $action == 'authorprotect' ? 'selected' : false,
93 - 'text' => wfMsg( efAuthorProtectMessage( $wgTitle ) ),
94 - 'href' => $wgTitle->getLocalUrl( 'action=authorprotect' ),
 95+ 'text' => wfMsg( efAuthorProtectMessage( $title ) ),
 96+ 'href' => $title->getLocalUrl( 'action=authorprotect' ),
9597 );
9698 }
9799 return true;
98100 }
99101
100102 function efAuthorProtectForm( $action, $article ) {
101 - global $wgTitle, $wgAuthorProtectDoProtect;
102103 if ( $action == 'authorprotect' ) {
103104 global $wgOut, $wgUser, $wgRequest, $wgRestrictionTypes;
104105 if ( $wgUser->isAllowed( 'authorprotect' ) ) {
105 - if ( userIsAuthor() ) {
 106+ if ( userIsAuthor( $article->getTitle() ) ) {
106107 $wgOut->setPageTitle( wfMsg( 'authorprotect' ) );
107108 if ( !$wgRequest->wasPosted() ) {
108 - $wgOut->addHTML( efAuthorProtectMakeProtectForm() );
 109+ $wgOut->addHTML( efAuthorProtectMakeProtectForm( $article->getTitle() ) );
109110 } else {
110111 if ( !$wgUser->matchEditToken( $wgRequest->getText( 'wpToken' ) ) ) {
111112 $wgOut->setPageTitle( wfMsg( 'errorpagetitle' ) );
@@ -115,7 +116,7 @@
116117 $expiration = array();
117118 $expiry = efAuthorProtectExpiry( $wgRequest->getText( 'wpExpiryTime' ) );
118119 foreach ( $wgRestrictionTypes as $type ) {
119 - $rest = $wgTitle->getRestrictions( $type );
 120+ $rest = $article->getTitle()->getRestrictions( $type );
120121 if ( $rest !== array() ) {
121122 if ( !$wgUser->isAllowed( $rest[0] ) && !in_array( 'author', $rest ) ) {
122123 $restrictions[$type] = $rest[0]; // don't let them lower the protection level
@@ -164,17 +165,17 @@
165166 return true; // unknown action, so state that the action doesn't exist
166167 }
167168
168 -function efAuthorProtectMakeProtectForm() {
169 - global $wgRestrictionTypes, $wgTitle, $wgUser;
 169+function efAuthorProtectMakeProtectForm( $title ) {
 170+ global $wgRestrictionTypes, $wgUser;
170171 $token = $wgUser->editToken();
171172 // FIXME: raw html messages
172173 $form = Xml::openElement( 'p' ) . wfMsg( 'authorprotect-intro' ) . Xml::closeElement( 'p' );
173 - $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgTitle->getLocalUrl( 'action=authorprotect' ) ) );
 174+ $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $title->getLocalUrl( 'action=authorprotect' ) ) );
174175
175176 $br = Html::element( 'br' );
176177
177178 foreach ( $wgRestrictionTypes as $type ) {
178 - $rest = $wgTitle->getRestrictions( $type );
 179+ $rest = $title->getRestrictions( $type );
179180 if ( $rest !== array() ) {
180181 if ( !$wgUser->isAllowed( $rest[0] ) && !in_array( 'author', $rest ) )
181182 continue; // it's protected at a level higher than them, so don't let them change it so they can now mess with stuff
@@ -195,11 +196,14 @@
196197 return $form;
197198 }
198199
199 -function userIsAuthor() {
200 - global $wgTitle, $wgUser;
201 - if ( !$wgTitle instanceOf Title )
 200+function userIsAuthor( $title = null ) {
 201+ global $wgUser;
 202+
 203+ if ( !$title instanceOf Title ) {
202204 return false; // quick hack to prevent the API from messing up.
203 - $id = $wgTitle->getArticleId();
 205+ }
 206+
 207+ $id = $title->getArticleId();
204208 $dbr = wfGetDB( DB_SLAVE ); // grab the slave for reading
205209 $aid = $dbr->selectField( 'revision', 'rev_user', array( 'rev_page' => $id ), __METHOD__ );
206210 // FIXME: weak comparison

Follow-up revisions

RevisionCommit summaryAuthorDate
r82613Fix for r82567: forgot to pass $wgTitle thereialex17:26, 22 February 2011

Status & tagging log