Index: trunk/extensions/WatchSubpages/WatchSubpages_body.php |
— | — | @@ -1,23 +1,32 @@ |
2 | 2 | <?php |
3 | 3 | #restrict to subpages |
4 | 4 | class WatchSubpages extends SpecialPage { |
5 | | - function WatchSubpages() { |
6 | | - SpecialPage::SpecialPage( 'Watchsubpages', 'watchsubpages' ); |
| 5 | + |
| 6 | + /** |
| 7 | + * Constructor - set up the new special page |
| 8 | + */ |
| 9 | + public function __construct() { |
| 10 | + parent::__construct( 'Watchsubpages', 'watchsubpages' ); |
7 | 11 | } |
8 | 12 | |
9 | | - function execute( $par ) { |
| 13 | + /** |
| 14 | + * Show the special page |
| 15 | + * |
| 16 | + * @param $subpage Mixed: parameter passed to the page or null |
| 17 | + */ |
| 18 | + public function execute( $par ) { |
10 | 19 | global $wgRequest, $wgOut, $wgUser; |
11 | 20 | |
12 | | - if( !$wgUser->isAllowed('watchsubpages') ) { |
13 | | - $wgOut->permissionRequired('watchsubpages'); |
| 21 | + if( !$wgUser->isAllowed( 'watchsubpages' ) ) { |
| 22 | + $wgOut->permissionRequired( 'watchsubpages' ); |
14 | 23 | return; |
15 | 24 | } |
16 | | - |
| 25 | + |
17 | 26 | if ( wfReadOnly() ) { |
18 | 27 | $wgOut->readOnlyPage(); |
19 | 28 | return; |
20 | 29 | } |
21 | | - |
| 30 | + |
22 | 31 | wfLoadExtensionMessages( 'WatchSubpages' ); |
23 | 32 | |
24 | 33 | $namespace = $wgRequest->getInt( 'namespace' ); |
— | — | @@ -38,10 +47,10 @@ |
39 | 48 | $toWatch = array_diff( $titles, $current ); |
40 | 49 | $this->watchTitles( $toWatch, $wgUser ); |
41 | 50 | $wgUser->invalidateCache(); |
42 | | - $wgOut->addHTML( wfMsg('watchsubpages-addedtowatchlist') ); |
| 51 | + $wgOut->addHTML( wfMsg( 'watchsubpages-addedtowatchlist' ) ); |
43 | 52 | $this->showTitles( $toWatch, $wgOut, $wgUser->getSkin() ); |
44 | 53 | } |
45 | | - $this->showForm( $wgOut, $wgUser, $namespace, trim($guidename, "/") ); |
| 54 | + $this->showForm( $wgOut, $wgUser, $namespace, trim( $guidename, '/' ) ); |
46 | 55 | } |
47 | 56 | |
48 | 57 | /** |
— | — | @@ -160,7 +169,7 @@ |
161 | 170 | if( !$title instanceof Title ) |
162 | 171 | $title = Title::newFromText( $title ); |
163 | 172 | if( $title instanceof Title ) { |
164 | | - $output->addHTML( "<li>" . $skin->makeLinkObj( $title ) |
| 173 | + $output->addHTML( '<li>' . $skin->makeLinkObj( $title ) |
165 | 174 | . ' (' . $skin->makeLinkObj( $title->getTalkPage(), $talk ) . ")</li>\n" ); |
166 | 175 | } |
167 | 176 | } |
— | — | @@ -172,6 +181,7 @@ |
173 | 182 | * |
174 | 183 | * @param $output OutputPage |
175 | 184 | * @param $user User |
| 185 | + * @param $namespace A namespace constant, such as NS_MAIN |
176 | 186 | * @param $guide GuideName |
177 | 187 | */ |
178 | 188 | private function showForm( $output, $user, $namespace, $guide ) { |
— | — | @@ -183,33 +193,33 @@ |
184 | 194 | $form .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); |
185 | 195 | $form .= Xml::hidden( 'title', $self->getPrefixedText() ); |
186 | 196 | $form .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) ); |
187 | | - $form .= "<tr> |
188 | | - <td>" . |
| 197 | + $form .= '<tr> |
| 198 | + <td>' . |
189 | 199 | Xml::label( 'Guide name:', 'nsfrom' ) . |
190 | | - "</td> |
191 | | - <td>" . |
192 | | - Xml::input( 'guide', 20, htmlspecialchars ( $guide . '/' ), array( 'id' => 'nsfrom' ) ) . |
193 | | - "</td> |
| 200 | + '</td> |
| 201 | + <td>' . |
| 202 | + Xml::input( 'guide', 20, htmlspecialchars( $guide . '/' ), array( 'id' => 'nsfrom' ) ) . |
| 203 | + '</td> |
194 | 204 | </tr> |
195 | 205 | <tr> |
196 | | - <td>" . |
| 206 | + <td>' . |
197 | 207 | Xml::label( wfMsg( 'namespace' ), 'namespace' ) . |
198 | | - "</td> |
199 | | - <td>" . |
| 208 | + '</td> |
| 209 | + <td>' . |
200 | 210 | Xml::namespaceSelector( $namespace, null ) . |
201 | 211 | Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . |
202 | | - "</td> |
203 | | - </tr>"; |
| 212 | + '</td> |
| 213 | + </tr>'; |
204 | 214 | $form .= Xml::closeElement( 'table' ); |
205 | 215 | $form .= Xml::closeElement( 'form' ); |
206 | 216 | $form .= Xml::closeElement( 'div' ); |
207 | 217 | |
208 | | - if($guide !== '') { |
| 218 | + if( $guide !== '' ) { |
209 | 219 | $form .= Xml::openElement( 'form', array( 'method' => 'post', |
210 | 220 | 'action' => $self->getLocalUrl( 'guide=' . $guide ) ) ); |
211 | 221 | $form .= Xml::hidden( 'token', $user->editToken( 'watchsubpages' ) ); |
212 | | - $form .= '<fieldset><legend>'.wfMsg('watchsubpages-addtitles').'</legend>'; |
213 | | - $form .= wfMsg('watchsubpages-form'); |
| 222 | + $form .= '<fieldset><legend>' . wfMsg( 'watchsubpages-addtitles' ) . '</legend>'; |
| 223 | + $form .= wfMsg( 'watchsubpages-form' ); |
214 | 224 | foreach( $this->getPrefixlistInfo( $namespace, $guide . '/' ) as $namespace => $pages ) { |
215 | 225 | $form .= '<h2>' . $this->getNamespaceHeading( $namespace ) . '</h2>'; |
216 | 226 | $form .= '<ul>'; |
— | — | @@ -219,7 +229,7 @@ |
220 | 230 | } |
221 | 231 | $form .= '</ul>'; |
222 | 232 | } |
223 | | - $form .= '<p>' . Xml::submitButton( wfMsg('watchsubpages-addtitles') ) . '</p>'; |
| 233 | + $form .= '<p>' . Xml::submitButton( wfMsg( 'watchsubpages-addtitles' ) ) . '</p>'; |
224 | 234 | $form .= '</fieldset></form>'; |
225 | 235 | } |
226 | 236 | $output->addHTML( $form ); |
— | — | @@ -230,11 +240,12 @@ |
231 | 241 | * and return as a two-dimensional array with namespace, title and |
232 | 242 | * redirect status |
233 | 243 | * |
| 244 | + * @param $namespace Namespace constant, defaults to NS_MAIN |
234 | 245 | * @param $guide GuideName |
235 | 246 | * @return array |
236 | 247 | */ |
237 | 248 | private function getPrefixlistInfo( $namespace = NS_MAIN, $guide ) { |
238 | | - $prefixList = $this->getNamespaceKeyAndText($namespace, $guide); |
| 249 | + $prefixList = $this->getNamespaceKeyAndText( $namespace, $guide ); |
239 | 250 | |
240 | 251 | $titles = array(); |
241 | 252 | list( $prefixNS, $prefixKey, $guide ) = $prefixList; |
— | — | @@ -286,28 +297,27 @@ |
287 | 298 | /** |
288 | 299 | * @param $ns int: the namespace of the article |
289 | 300 | * @param $text string: the name of the article |
290 | | - * @return array( int namespace, string dbkey, string pagename ) or NULL on error |
| 301 | + * @return array( int namespace, string dbkey, string pagename ) or null on error |
291 | 302 | * @static (sort of) |
292 | | - * @access private |
293 | 303 | */ |
294 | | - function getNamespaceKeyAndText ($ns, $text) { |
| 304 | + private function getNamespaceKeyAndText( $ns, $text ) { |
295 | 305 | if ( $text == '' ) |
296 | 306 | return array( $ns, '', '' ); # shortcut for common case |
297 | 307 | |
298 | | - $t = Title::makeTitleSafe($ns, $text); |
| 308 | + $t = Title::makeTitleSafe( $ns, $text ); |
299 | 309 | if ( $t && $t->isLocal() ) { |
300 | 310 | return array( $t->getNamespace(), $t->getDBkey(), $t->getText() ); |
301 | | - } else if ( $t ) { |
302 | | - return NULL; |
| 311 | + } elseif ( $t ) { |
| 312 | + return null; |
303 | 313 | } |
304 | 314 | |
305 | 315 | # try again, in case the problem was an empty pagename |
306 | | - $text = preg_replace('/(#|$)/', 'X$1', $text); |
307 | | - $t = Title::makeTitleSafe($ns, $text); |
| 316 | + $text = preg_replace( '/(#|$)/', 'X$1', $text ); |
| 317 | + $t = Title::makeTitleSafe( $ns, $text ); |
308 | 318 | if ( $t && $t->isLocal() ) { |
309 | 319 | return array( $t->getNamespace(), '', '' ); |
310 | 320 | } else { |
311 | | - return NULL; |
| 321 | + return null; |
312 | 322 | } |
313 | 323 | } |
314 | 324 | |
Index: trunk/extensions/WatchSubpages/WatchSubpages.i18n.php |
— | — | @@ -1,23 +1,23 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Internationalisation file for extension WatchSubPages. |
| 4 | + * Internationalisation file for WatchSubpages extension. |
5 | 5 | * |
6 | | - * @addtogroup Extensions |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
7 | 8 | */ |
8 | 9 | |
9 | 10 | $messages = array(); |
10 | 11 | |
11 | | -/** |
12 | | - * English |
| 12 | +/** English |
13 | 13 | * @author http://www.strategywiki.org/wiki/User:Prod |
14 | 14 | */ |
15 | 15 | $messages['en'] = array( |
16 | | - 'watchsubpages' => 'Watch subpages', |
17 | | - 'watchsubpages-addedtowatchlist' => 'The following has been added to your watchlist.', |
18 | | - 'watchsubpages-addtitles' => 'Add pages', |
| 16 | + 'watchsubpages' => 'Watch subpages', |
| 17 | + 'watchsubpages-addedtowatchlist' => 'The following has been added to your watchlist.', |
| 18 | + 'watchsubpages-addtitles' => 'Add pages', |
19 | 19 | 'watchsubpages-addtitlestowatchlist' => 'Add pages to watchlist', |
20 | | - 'watchsubpages-desc' => 'Quickly [[Special:WatchSubpages|add all subpages]] of a page to the watchlist', |
21 | | - 'watchsubpages-form' => 'Select the pages to add to your watchlist below. |
| 20 | + 'watchsubpages-desc' => 'Quickly [[Special:WatchSubpages|add all subpages]] of a page to the watchlist', |
| 21 | + 'watchsubpages-form' => 'Select the pages to add to your watchlist below. |
22 | 22 | To add a page, check the box next to it, and click "Add pages". |
23 | 23 | |
24 | 24 | When checking or unchecking multiple pages, holding the shift key allows you to select consecutive checkboxes by clicking each end of the range to be checked.', |
Index: trunk/extensions/WatchSubpages/WatchSubpages.php |
— | — | @@ -3,28 +3,33 @@ |
4 | 4 | * Watch Guide Subpages - an extension for |
5 | 5 | * adding all subpages of a guide to the users watchlist |
6 | 6 | * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
7 | 9 | * @author Prod (http://www.strategywiki.org/wiki/User:Prod) |
| 10 | + * @link http://www.mediawiki.org/wiki/Extension:WatchSubpages Documentation |
8 | 11 | */ |
9 | 12 | |
10 | 13 | # Not a valid entry point, skip unless MEDIAWIKI is defined |
11 | | -if (!defined('MEDIAWIKI')) { |
12 | | - echo <<<EOT |
13 | | -To install my extension, put the following line in LocalSettings.php: |
| 14 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 15 | + echo <<<EOT |
| 16 | +To install WatchSubpages extension, put the following line in LocalSettings.php: |
14 | 17 | require_once( "\$IP/extensions/WatchSubpages/WatchSubpages.php" ); |
15 | 18 | EOT; |
16 | | - exit( 1 ); |
| 19 | + exit( 1 ); |
17 | 20 | } |
18 | 21 | |
| 22 | +// Extension credits for Special:Version |
19 | 23 | $wgExtensionCredits['specialpage'][] = array( |
20 | | - 'path' => __FILE__, |
21 | | - 'author' => '[http://www.strategywiki.org/wiki/User:Prod User:Prod]', |
22 | | - 'name' => 'Watch Guide Subpages', |
23 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:WatchSubpages', |
24 | | - 'description' => 'Quickly add all subpages of a guide to the users watchlist', |
| 24 | + 'path' => __FILE__, |
| 25 | + 'author' => '[http://www.strategywiki.org/wiki/User:Prod User:Prod]', |
| 26 | + 'name' => 'Watch Guide Subpages', |
| 27 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:WatchSubpages', |
| 28 | + 'description' => 'Quickly add all subpages of a guide to the users watchlist', |
25 | 29 | 'descriptionmsg' => 'watchsubpages-desc', |
26 | 30 | ); |
27 | 31 | |
28 | | -$dir = dirname(__FILE__) . '/'; |
| 32 | +// Set up the new special page |
| 33 | +$dir = dirname( __FILE__ ) . '/'; |
29 | 34 | $wgExtensionMessagesFiles['WatchSubpages'] = $dir . 'WatchSubpages.i18n.php'; |
30 | 35 | $wgExtensionAliasesFiles['WatchSubpages'] = $dir . 'WatchSubpages.alias.php'; |
31 | 36 | $wgAutoloadClasses['WatchSubpages'] = $dir . 'WatchSubpages_body.php'; |
Index: trunk/extensions/WatchSubpages/WatchSubpages.alias.php |
— | — | @@ -1,11 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Aliases for special pages |
| 4 | + * Aliases for Special:WatchSubpages. |
5 | 5 | * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
6 | 8 | */ |
7 | 9 | |
8 | 10 | $aliases = array(); |
9 | 11 | |
| 12 | +/** English */ |
10 | 13 | $aliases['en'] = array( |
11 | 14 | 'WatchSubpages' => array( 'WatchSubpages' ), |
12 | 15 | ); |