Index: trunk/extensions/AuthorProtect/AuthorProtect.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | $wgExtensionMessagesFiles['AuthorProtect'] = dirname( __FILE__ ) . '/AuthorProtect.i18n.php'; |
25 | 25 | $wgGroupPermissions['sysop']['author'] = true; // sysops can edit every page despite author protection |
26 | 26 | $wgGroupPermissions['user']['authorprotect'] = true; // registered users can protect pages they author |
27 | | -$wgHooks['SkinTemplateContentActions'][] = 'efMakeContentAction'; |
| 27 | +$wgHooks['SkinTemplateNavigation::Universal'][] = 'efMakeContentAction'; |
28 | 28 | $wgHooks['UnknownAction'][] = 'efAuthorProtectForm'; |
29 | 29 | $wgHooks['userCan'][] = 'efAuthorProtectDelay'; |
30 | 30 | $wgHooks['UserGetRights'][] = 'efAssignAuthor'; |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | $user->getRights(); // delay hook execution for compatibility w/ ConfirmAccount |
46 | 46 | $act = ( $action == '' || $action == 'view' ) ? 'edit' : $action; |
47 | 47 | $wgAuthorProtectDelayRun = false; |
48 | | - if ( userIsAuthor() && isAuthorProtected( $title, $act ) ) { |
| 48 | + if ( userIsAuthor( $title ) && isAuthorProtected( $title, $act ) ) { |
49 | 49 | $result = true; |
50 | 50 | return false; |
51 | 51 | } |
— | — | @@ -83,28 +83,29 @@ |
84 | 84 | $wgUser->getRights(); |
85 | 85 | } |
86 | 86 | |
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' ) ) { |
90 | 92 | $action = $wgRequest->getText( 'action' ); |
91 | | - $cactions['authorprotect'] = array( |
| 93 | + $cactions['actions']['authorprotect'] = array( |
92 | 94 | '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' ), |
95 | 97 | ); |
96 | 98 | } |
97 | 99 | return true; |
98 | 100 | } |
99 | 101 | |
100 | 102 | function efAuthorProtectForm( $action, $article ) { |
101 | | - global $wgTitle, $wgAuthorProtectDoProtect; |
102 | 103 | if ( $action == 'authorprotect' ) { |
103 | 104 | global $wgOut, $wgUser, $wgRequest, $wgRestrictionTypes; |
104 | 105 | if ( $wgUser->isAllowed( 'authorprotect' ) ) { |
105 | | - if ( userIsAuthor() ) { |
| 106 | + if ( userIsAuthor( $article->getTitle() ) ) { |
106 | 107 | $wgOut->setPageTitle( wfMsg( 'authorprotect' ) ); |
107 | 108 | if ( !$wgRequest->wasPosted() ) { |
108 | | - $wgOut->addHTML( efAuthorProtectMakeProtectForm() ); |
| 109 | + $wgOut->addHTML( efAuthorProtectMakeProtectForm( $article->getTitle() ) ); |
109 | 110 | } else { |
110 | 111 | if ( !$wgUser->matchEditToken( $wgRequest->getText( 'wpToken' ) ) ) { |
111 | 112 | $wgOut->setPageTitle( wfMsg( 'errorpagetitle' ) ); |
— | — | @@ -115,7 +116,7 @@ |
116 | 117 | $expiration = array(); |
117 | 118 | $expiry = efAuthorProtectExpiry( $wgRequest->getText( 'wpExpiryTime' ) ); |
118 | 119 | foreach ( $wgRestrictionTypes as $type ) { |
119 | | - $rest = $wgTitle->getRestrictions( $type ); |
| 120 | + $rest = $article->getTitle()->getRestrictions( $type ); |
120 | 121 | if ( $rest !== array() ) { |
121 | 122 | if ( !$wgUser->isAllowed( $rest[0] ) && !in_array( 'author', $rest ) ) { |
122 | 123 | $restrictions[$type] = $rest[0]; // don't let them lower the protection level |
— | — | @@ -164,17 +165,17 @@ |
165 | 166 | return true; // unknown action, so state that the action doesn't exist |
166 | 167 | } |
167 | 168 | |
168 | | -function efAuthorProtectMakeProtectForm() { |
169 | | - global $wgRestrictionTypes, $wgTitle, $wgUser; |
| 169 | +function efAuthorProtectMakeProtectForm( $title ) { |
| 170 | + global $wgRestrictionTypes, $wgUser; |
170 | 171 | $token = $wgUser->editToken(); |
171 | 172 | // FIXME: raw html messages |
172 | 173 | $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' ) ) ); |
174 | 175 | |
175 | 176 | $br = Html::element( 'br' ); |
176 | 177 | |
177 | 178 | foreach ( $wgRestrictionTypes as $type ) { |
178 | | - $rest = $wgTitle->getRestrictions( $type ); |
| 179 | + $rest = $title->getRestrictions( $type ); |
179 | 180 | if ( $rest !== array() ) { |
180 | 181 | if ( !$wgUser->isAllowed( $rest[0] ) && !in_array( 'author', $rest ) ) |
181 | 182 | 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 @@ |
196 | 197 | return $form; |
197 | 198 | } |
198 | 199 | |
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 ) { |
202 | 204 | return false; // quick hack to prevent the API from messing up. |
203 | | - $id = $wgTitle->getArticleId(); |
| 205 | + } |
| 206 | + |
| 207 | + $id = $title->getArticleId(); |
204 | 208 | $dbr = wfGetDB( DB_SLAVE ); // grab the slave for reading |
205 | 209 | $aid = $dbr->selectField( 'revision', 'rev_user', array( 'rev_page' => $id ), __METHOD__ ); |
206 | 210 | // FIXME: weak comparison |