r54296 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54295‎ | r54296 | r54297 >
Date:18:29, 3 August 2009
Author:ashley
Status:deferred
Tags:
Comment:
WatchSubpages: a bit of cleanup
Modified paths:
  • /trunk/extensions/WatchSubpages/WatchSubpages.alias.php (modified) (history)
  • /trunk/extensions/WatchSubpages/WatchSubpages.i18n.php (modified) (history)
  • /trunk/extensions/WatchSubpages/WatchSubpages.php (modified) (history)
  • /trunk/extensions/WatchSubpages/WatchSubpages_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WatchSubpages/WatchSubpages_body.php
@@ -1,23 +1,32 @@
22 <?php
33 #restrict to subpages
44 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' );
711 }
812
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 ) {
1019 global $wgRequest, $wgOut, $wgUser;
1120
12 - if( !$wgUser->isAllowed('watchsubpages') ) {
13 - $wgOut->permissionRequired('watchsubpages');
 21+ if( !$wgUser->isAllowed( 'watchsubpages' ) ) {
 22+ $wgOut->permissionRequired( 'watchsubpages' );
1423 return;
1524 }
16 -
 25+
1726 if ( wfReadOnly() ) {
1827 $wgOut->readOnlyPage();
1928 return;
2029 }
21 -
 30+
2231 wfLoadExtensionMessages( 'WatchSubpages' );
2332
2433 $namespace = $wgRequest->getInt( 'namespace' );
@@ -38,10 +47,10 @@
3948 $toWatch = array_diff( $titles, $current );
4049 $this->watchTitles( $toWatch, $wgUser );
4150 $wgUser->invalidateCache();
42 - $wgOut->addHTML( wfMsg('watchsubpages-addedtowatchlist') );
 51+ $wgOut->addHTML( wfMsg( 'watchsubpages-addedtowatchlist' ) );
4352 $this->showTitles( $toWatch, $wgOut, $wgUser->getSkin() );
4453 }
45 - $this->showForm( $wgOut, $wgUser, $namespace, trim($guidename, "/") );
 54+ $this->showForm( $wgOut, $wgUser, $namespace, trim( $guidename, '/' ) );
4655 }
4756
4857 /**
@@ -160,7 +169,7 @@
161170 if( !$title instanceof Title )
162171 $title = Title::newFromText( $title );
163172 if( $title instanceof Title ) {
164 - $output->addHTML( "<li>" . $skin->makeLinkObj( $title )
 173+ $output->addHTML( '<li>' . $skin->makeLinkObj( $title )
165174 . ' (' . $skin->makeLinkObj( $title->getTalkPage(), $talk ) . ")</li>\n" );
166175 }
167176 }
@@ -172,6 +181,7 @@
173182 *
174183 * @param $output OutputPage
175184 * @param $user User
 185+ * @param $namespace A namespace constant, such as NS_MAIN
176186 * @param $guide GuideName
177187 */
178188 private function showForm( $output, $user, $namespace, $guide ) {
@@ -183,33 +193,33 @@
184194 $form .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
185195 $form .= Xml::hidden( 'title', $self->getPrefixedText() );
186196 $form .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
187 - $form .= "<tr>
188 - <td>" .
 197+ $form .= '<tr>
 198+ <td>' .
189199 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>
194204 </tr>
195205 <tr>
196 - <td>" .
 206+ <td>' .
197207 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
198 - "</td>
199 - <td>" .
 208+ '</td>
 209+ <td>' .
200210 Xml::namespaceSelector( $namespace, null ) .
201211 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
202 - "</td>
203 - </tr>";
 212+ '</td>
 213+ </tr>';
204214 $form .= Xml::closeElement( 'table' );
205215 $form .= Xml::closeElement( 'form' );
206216 $form .= Xml::closeElement( 'div' );
207217
208 - if($guide !== '') {
 218+ if( $guide !== '' ) {
209219 $form .= Xml::openElement( 'form', array( 'method' => 'post',
210220 'action' => $self->getLocalUrl( 'guide=' . $guide ) ) );
211221 $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' );
214224 foreach( $this->getPrefixlistInfo( $namespace, $guide . '/' ) as $namespace => $pages ) {
215225 $form .= '<h2>' . $this->getNamespaceHeading( $namespace ) . '</h2>';
216226 $form .= '<ul>';
@@ -219,7 +229,7 @@
220230 }
221231 $form .= '</ul>';
222232 }
223 - $form .= '<p>' . Xml::submitButton( wfMsg('watchsubpages-addtitles') ) . '</p>';
 233+ $form .= '<p>' . Xml::submitButton( wfMsg( 'watchsubpages-addtitles' ) ) . '</p>';
224234 $form .= '</fieldset></form>';
225235 }
226236 $output->addHTML( $form );
@@ -230,11 +240,12 @@
231241 * and return as a two-dimensional array with namespace, title and
232242 * redirect status
233243 *
 244+ * @param $namespace Namespace constant, defaults to NS_MAIN
234245 * @param $guide GuideName
235246 * @return array
236247 */
237248 private function getPrefixlistInfo( $namespace = NS_MAIN, $guide ) {
238 - $prefixList = $this->getNamespaceKeyAndText($namespace, $guide);
 249+ $prefixList = $this->getNamespaceKeyAndText( $namespace, $guide );
239250
240251 $titles = array();
241252 list( $prefixNS, $prefixKey, $guide ) = $prefixList;
@@ -286,28 +297,27 @@
287298 /**
288299 * @param $ns int: the namespace of the article
289300 * @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
291302 * @static (sort of)
292 - * @access private
293303 */
294 - function getNamespaceKeyAndText ($ns, $text) {
 304+ private function getNamespaceKeyAndText( $ns, $text ) {
295305 if ( $text == '' )
296306 return array( $ns, '', '' ); # shortcut for common case
297307
298 - $t = Title::makeTitleSafe($ns, $text);
 308+ $t = Title::makeTitleSafe( $ns, $text );
299309 if ( $t && $t->isLocal() ) {
300310 return array( $t->getNamespace(), $t->getDBkey(), $t->getText() );
301 - } else if ( $t ) {
302 - return NULL;
 311+ } elseif ( $t ) {
 312+ return null;
303313 }
304314
305315 # 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 );
308318 if ( $t && $t->isLocal() ) {
309319 return array( $t->getNamespace(), '', '' );
310320 } else {
311 - return NULL;
 321+ return null;
312322 }
313323 }
314324
Index: trunk/extensions/WatchSubpages/WatchSubpages.i18n.php
@@ -1,23 +1,23 @@
22 <?php
33 /**
4 - * Internationalisation file for extension WatchSubPages.
 4+ * Internationalisation file for WatchSubpages extension.
55 *
6 - * @addtogroup Extensions
 6+ * @file
 7+ * @ingroup Extensions
78 */
89
910 $messages = array();
1011
11 -/**
12 - * English
 12+/** English
1313 * @author http://www.strategywiki.org/wiki/User:Prod
1414 */
1515 $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',
1919 '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.
2222 To add a page, check the box next to it, and click "Add pages".
2323
2424 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 @@
44 * Watch Guide Subpages - an extension for
55 * adding all subpages of a guide to the users watchlist
66 *
 7+ * @file
 8+ * @ingroup Extensions
79 * @author Prod (http://www.strategywiki.org/wiki/User:Prod)
 10+ * @link http://www.mediawiki.org/wiki/Extension:WatchSubpages Documentation
811 */
912
1013 # 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:
1417 require_once( "\$IP/extensions/WatchSubpages/WatchSubpages.php" );
1518 EOT;
16 - exit( 1 );
 19+ exit( 1 );
1720 }
1821
 22+// Extension credits for Special:Version
1923 $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',
2529 'descriptionmsg' => 'watchsubpages-desc',
2630 );
2731
28 -$dir = dirname(__FILE__) . '/';
 32+// Set up the new special page
 33+$dir = dirname( __FILE__ ) . '/';
2934 $wgExtensionMessagesFiles['WatchSubpages'] = $dir . 'WatchSubpages.i18n.php';
3035 $wgExtensionAliasesFiles['WatchSubpages'] = $dir . 'WatchSubpages.alias.php';
3136 $wgAutoloadClasses['WatchSubpages'] = $dir . 'WatchSubpages_body.php';
Index: trunk/extensions/WatchSubpages/WatchSubpages.alias.php
@@ -1,11 +1,14 @@
22 <?php
33 /**
4 - * Aliases for special pages
 4+ * Aliases for Special:WatchSubpages.
55 *
 6+ * @file
 7+ * @ingroup Extensions
68 */
79
810 $aliases = array();
911
 12+/** English */
1013 $aliases['en'] = array(
1114 'WatchSubpages' => array( 'WatchSubpages' ),
1215 );

Status & tagging log