r31320 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31319‎ | r31320 | r31321 >
Date:20:29, 26 February 2008
Author:minuteelectron
Status:old
Tags:
Comment:
* Further clean up of MultiBoilerplate and CategoryStepper extensions.
* Added README files for both.
* CategoryStepper now has a default CSS style.
* Replace regular expression in favour of ltrim().
Modified paths:
  • /trunk/extensions/CategoryStepper/CategoryStepper.css (added) (history)
  • /trunk/extensions/CategoryStepper/CategoryStepper.i18n.php (modified) (history)
  • /trunk/extensions/CategoryStepper/CategoryStepper.php (modified) (history)
  • /trunk/extensions/CategoryStepper/README (added) (history)
  • /trunk/extensions/MultiBoilerplate/MultiBoilerplate.i18n.php (modified) (history)
  • /trunk/extensions/MultiBoilerplate/MultiBoilerplate.php (modified) (history)
  • /trunk/extensions/MultiBoilerplate/README (added) (history)

Diff [purge]

Index: trunk/extensions/MultiBoilerplate/MultiBoilerplate.i18n.php
@@ -13,7 +13,7 @@
1414 */
1515 $messages['en'] = array(
1616 'multiboilerplate' => '',
17 - 'multiboilerplate-desc' => 'Displays a box at the top of the edit page to select and load a boilerplate',
 17+ 'multiboilerplate-desc' => 'Allows a boilerplate to be selected from a drop down box located above the edit form when editing pages',
1818 'multiboilerplate-label' => '',
1919 'multiboilerplate-legend' => 'Select boilerplate',
2020 'multiboilerplate-submit' => 'Load',
Index: trunk/extensions/MultiBoilerplate/MultiBoilerplate.php
@@ -1,8 +1,11 @@
22 <?php
33
44 /**
5 - * Extension for allowing a boilerplate to be selected from a drop down box at
6 - * the top of the article edit page.
 5+ * Allows a boilerplate to be selected from a drop down box located above the
 6+ * edit form when editing non-exstant pages or, optionally (based upon
 7+ * configuration variable $wgMultiBoilerplateOverwrite), load the template
 8+ * over the current contents.
 9+ *
710 *
811 * @addtogroup Extensions
912 *
@@ -19,15 +22,15 @@
2023 // Extension credits.
2124 $wgExtensionCredits[ 'other' ][] = array(
2225 'name' => 'MultiBoilerplate',
23 - 'description' => 'Displays a box at the top of the edit page to select and load a boilerplate.',
 26+ 'description' => 'Allows a boilerplate to be selected from a drop down box located above the edit form when editing pages.',
2427 'descriptionmsg' => 'multiboilerplate-desc',
2528 'author' => 'MinuteElectron',
2629 'url' => 'http://www.mediawiki.org/wiki/Extension:MultiBoilerplate',
27 - 'version' => '1.5',
 30+ 'version' => '1.6',
2831 );
2932
3033 // Hook into EditPage::showEditForm:initial to modify the edit page header.
31 -$wgHooks[ 'EditPage::showEditForm:initial' ][] = 'wfMultiBoilerplate';
 34+$wgHooks[ 'EditPage::showEditForm:initial' ][] = 'efMultiBoilerplate';
3235
3336 // Set extension messages file.
3437 $wgExtensionMessagesFiles[ 'MultiBoilerplate' ] = dirname( __FILE__ ) . '/MultiBoilerplate.i18n.php';
@@ -44,11 +47,11 @@
4548 $wgMultiBoilerplateOverwrite = false;
4649
4750 /**
48 - * Generate the form to be displayed at the top of the edit page and insert it into the page.
 51+ * Generate the form to be displayed at the top of the edit page and insert it.
4952 * @param $form EditPage object.
5053 * @return true
5154 */
52 -function wfMultiBoilerplate( $form ) {
 55+function efMultiBoilerplate( $form ) {
5356
5457 // Get various variables needed for this extension.
5558 global $wgMultiBoilerplateOptions, $wgMultiBoilerplateOverwrite, $wgArticle, $wgTitle, $wgRequest;
@@ -76,7 +79,7 @@
7780 $options = '';
7881 $things = explode( "\n", str_replace( "\r", "\n", str_replace( "\r\n", "\n", $things ) ) ); // Ensure line-endings are \n
7982 foreach( $things as $row ) {
80 - $row = preg_replace( '#^\*( *)#', '', $row ); // Remove the asterix (and a space if found) from the start of the line.
 83+ $row = ltrim( $row, '* ' ); // Remove the asterix (and a space if found) from the start of the line.
8184 $row = explode( '|', $row );
8285 if( !isset( $row[ 1 ] ) ) return true; // Invalid syntax, abort.
8386 $selected = false;
@@ -84,9 +87,10 @@
8588 $options .= Xml::option( $row[ 0 ], $row[ 1 ], $selected );
8689 }
8790 }
88 -
89 - if( $options == '' ) return true; // No options found in either configuration file, abort.
9091
 92+ // No options found in either configuration file, abort.
 93+ if( $options == '' ) return true;
 94+
9195 // Append the selection form to the top of the edit page.
9296 $form->editFormPageTop .=
9397 Xml::openElement( 'form', array( 'id' => 'multiboilerplateform', 'name' => 'multiboilerplateform', 'method' => 'get', 'action' => $wgTitle->getEditURL() ) ) .
Index: trunk/extensions/MultiBoilerplate/README
@@ -0,0 +1,97 @@
 2+MultiBoilerplate
 3+
 4+ Version 1.6
 5+ Copyright © 2007-2008 MinuteElectron.
 6+ Licensed under the GNU General Public License 2.0 or later.
 7+
 8+The MultiBoilerplate extension allows a boilerplate to be selected from a drop
 9+down box located above the edit form when editing non-exstant pages or
 10+optionally (based upon configuration variable $wgMultiBoilerplateOverwrite),
 11+load the template over the current contents.
 12+
 13+== Requirements ==
 14+
 15+The MultiBoilerplate extension requires MediaWiki 1.11.0 or later.
 16+
 17+== Installation ==
 18+
 19+1. Place the MultiBoilerplater.php source code into
 20+ extensions/MultiBoilerplate/MultiBoilerplate.php.
 21+2. Place the MultiBoilerplater.i18n.php source code into
 22+ extensions/MultiBoilerplate/MultiBoilerplate.i18n.php.
 23+3. Add require_once( "$IP/extensions/MultiBoilerplate/MultiBoilerplate.php" );
 24+ to LocalSettings.php.
 25+4. Enjoy!
 26+
 27+Installation can be verified through the [[Special:Version]] page on the wiki.
 28+
 29+== Using the extension ==
 30+
 31+MultiBoilerplate adds a box to the edit page above the edit form
 32+allowing users to load a boilerplate into the edit window.
 33+
 34+Fill the $wgMultiBoilerplateOptions variable with a list of boilerplate names
 35+to templates; e.g.
 36+$wgMultiBoilerplateOptions[ "My Boilerplate" ] = "Template:My Boilerplate";
 37+
 38+Alternatively set the variable to false and use the MediaWiki:Multiboilerplate
 39+page to set options
 40+
 41+LocalSettings.php:
 42+ $wgMultiBoilerplateOptions = false;
 43+MediaWiki:Multiboilerplate:
 44+ * My Boilerplate|Template:My Boilerplate
 45+
 46+Optionally set whether or not the selection box is displayed on pages that
 47+already exist (defaults to false) using $wgMultiBoilerplateOverwrite.
 48+$wgMultiBoilerplateOverwrite = true;
 49+
 50+== Change log ==
 51+
 52+Version 1.1
 53+2007-12-18
 54+ Original version.
 55+
 56+Version 1.2
 57+2008-01-07
 58+ Refactor code, fix major bug that made the extension useless and add
 59+ comments.
 60+
 61+Version 1.3
 62+2008-01-19
 63+ Use Xml:: instead of manually created HTML, converted all double-quotes to
 64+ single-quotes.
 65+ Added an optional message multiboilerplate-label to display a label before
 66+ the drop-down box, and rename multiboilerplate-select to
 67+ multiboilerplate-legend and multiboilerplate-load to
 68+ multiboilerplate-submit to be less ambiguous.
 69+
 70+Version 1.4
 71+2008-02-06
 72+ It is now (optionally) possible to specify boilerplates in a MediaWiki
 73+ namespace message instead of a LocalSettings.php configuration variable.
 74+ The extension now uses descriptionmsg (allowing description
 75+ internationalisation).
 76+ Part of the code that used direct database interfacing to check for article
 77+ existence has been replaced with a call to the $wgTitle global.
 78+ The $wgMultiBoilerplateThings global has been renamed to
 79+ $wgMultiBoilerplateOptions for a greater level of self-explanation.
 80+ The boilerplate selection box is no longer displayed if there are no
 81+ options.
 82+
 83+Version 1.5
 84+2008-02-06
 85+ Now handles <noinclude> and<includeonly> tags.
 86+
 87+Version 1.6
 88+2008-02-26
 89+ Added README.
 90+ ltrim() now used instead of preg_replace().
 91+
 92+== Feedback ==
 93+
 94+Bugs and feature requests should be reported via MediaZilla
 95+<http://bugzilla.wikimedia.org/> and placed in the 'MediaWiki extensions'
 96+product under the 'MultiBoilerplate' component. Alternatively send an e-mail to
 97+<minuteelectron@googlemail.com> with any comments or suggestions, all are
 98+welcome.
\ No newline at end of file
Index: trunk/extensions/CategoryStepper/CategoryStepper.i18n.php
@@ -13,7 +13,7 @@
1414 */
1515 $messages['en'] = array(
1616 'categorystepper' => '',
17 - 'categorystepper-desc' => 'Display a category stepper box on pages that are in a set of categories.',
 17+ 'categorystepper-desc' => 'Displays a category stepper box allowing one to navigate forward and backwards alphabetically through one or more categories a page is in',
1818 'categorystepper-end' => '(End of category)',
1919 'categorystepper-start' => '(Start of category)',
2020 );
@@ -36,7 +36,6 @@
3737 );
3838
3939 /** Bengali (বাংলা)
40 - * @author Zaheen
4140 */
4241 $messages['bn'] = array(
4342 'categorystepper-desc' => 'যেসব পাতা বিষয়শ্রেণীসমূহের একটি সেটে আছে, সেসব পাতাতে একটি বিষয়শ্রেণী স্টেপার বক্স দেখানো হোক।',
Index: trunk/extensions/CategoryStepper/CategoryStepper.php
@@ -1,7 +1,10 @@
22 <?php
33
44 /**
5 - * Display a category stepper box on pages that are in a set set of categories.
 5+ * Displays a category stepper box allowing one to navigate forward and
 6+ * backwards alphabetically through one or more categories a page is in,
 7+ * as specified via a MediaWiki: namespace page or the $wgCategoryStepper
 8+ * configuration variable.
69 *
710 * @addtogroup Extensions
811 *
@@ -18,15 +21,15 @@
1922 // Extension credits.
2023 $wgExtensionCredits[ 'other' ][] = array(
2124 'name' => 'CategoryStepper',
22 - 'description' => 'Display a category stepper box on pages that are in a set of categories.',
 25+ 'description' => 'Displays a category stepper box allowing one to navigate forward and backwards alphabetically through one or more categories a page is in.',
2326 'descriptionmsg' => 'categorystepper-desc',
2427 'author' => 'MinuteElectron',
2528 'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryStepper',
26 - 'version' => '1.4',
 29+ 'version' => '1.5',
2730 );
2831
29 -// Hook into OutputPageBeforeHTML to add content to the end of the content.
30 -$wgHooks[ 'OutputPageBeforeHTML' ][] = 'wfCategoryStepper';
 32+// Hook into OutputPageBeforeHTML to add code to the end of the content area.
 33+$wgHooks[ 'OutputPageBeforeHTML' ][] = 'efCategoryStepper';
3134
3235 // Set extension messages file.
3336 $wgExtensionMessagesFiles[ 'CategoryStepper' ] = dirname( __FILE__ ) . '/CategoryStepper.i18n.php';
@@ -51,10 +54,10 @@
5255 *
5356 * @return true
5457 */
55 -function wfCategoryStepper( &$out, &$text ) {
 58+function efCategoryStepper( $out, $text ) {
5659
5760 // Get various variables needed for this extension.
58 - global $wgCategoryStepper, $wgTitle, $wgArticlePath, $wgRequest;
 61+ global $wgCategoryStepper, $wgTitle, $wgArticlePath, $wgRequest, $IP, $wgOut;
5962
6063 // Only render on the actual view page; not edit, delete etc.
6164 if( $wgRequest->getBool( 'action' ) ) return true;
@@ -71,7 +74,7 @@
7275 $things = wfMsg( 'categorystepper' );
7376 $things = explode( "\n", str_replace( "\r", "\n", str_replace( "\r\n", "\n", $things ) ) ); // Ensure line-endings are \n
7477 foreach( $things as $row ) {
75 - $row = preg_replace( '#^\*( *)#', '', $row ); // Remove the asterix (and a space if found) from the start of the line.
 78+ $row = ltrim( $row, '* ' ); // Remove the asterix (and a space if found) from the start of the line.
7679 $row = explode( '|', $row );
7780 if( !isset( $row[ 1 ] ) ) $row[ 1 ] = $row[ 0 ];
7881 $wgCategoryStepper[ $row[ 0 ] ] = $row[ 1 ];
@@ -116,7 +119,8 @@
117120 $next = Xml::element( "span", array( "style" => "font-style:italic;" ), wfMsg( "categorystepper-end" ) );
118121 }
119122
120 - // Generate the table at the bottom of the page and add it to the page text.
 123+ // Generate the table at the bottom of the page and add it to the
 124+ // page text.
121125 $text .=
122126 Xml::openElement( "table", array( "class" => 'categorystepper', 'style' => 'margin-left:auto;margin-right:auto;' ) ) .
123127 Xml::openElement( "tr" ) .
@@ -135,6 +139,9 @@
136140
137141 }
138142
 143+ // Add style file to the output headers if it exists.
 144+ if( file_exists( "$IP/skins/CategoryStepper.css" ) ) $wgOut->addStyle( 'CategoryStepper.css' );
 145+
139146 // Return true so things don't break.
140147 return true;
141148
Index: trunk/extensions/CategoryStepper/CategoryStepper.css
@@ -0,0 +1,32 @@
 2+/**
 3+ * Style file for the CategoryStepper extension.
 4+ *
 5+ * @addtogroup Extensions
 6+ */
 7+
 8+table.categorystepper {
 9+ margin: 1em 1em 1em 0;
 10+ background: #f9f9f9;
 11+ border: 1px #aaa solid;
 12+ border-collapse: collapse;
 13+}
 14+
 15+table.categorystepper th, table.categorystepper td {
 16+ border: 1px #aaa solid;
 17+ padding: 0.2em;
 18+}
 19+
 20+table.categorystepper th {
 21+ background: #f2f2f2;
 22+ text-align: center;
 23+}
 24+
 25+table.categorystepper caption {
 26+ margin-left: inherit;
 27+ margin-right: inherit;
 28+ font-weight: bold;
 29+}
 30+
 31+table.categorystepper {
 32+ background-color: transparent;
 33+}
Index: trunk/extensions/CategoryStepper/README
@@ -0,0 +1,85 @@
 2+CategoryStepper
 3+
 4+ Version 1.5
 5+ Copyright © 2007-2008 MinuteElectron.
 6+ Licensed under the GNU General Public License 2.0 or later.
 7+
 8+The CategoryStepper extension displays a category stepper box allowing one to
 9+navigate forward and backwards alphabetically through one or more categories a
 10+page is in, as specified via a MediaWiki: namespace page or the
 11+$wgCategoryStepper configuration variable.
 12+
 13+== Requirements ==
 14+
 15+The CategoryStepper extension requires MediaWiki 1.11.0 or later.
 16+
 17+== Installation ==
 18+
 19+1. Place the CategoryStepper.php source code into
 20+ extensions/CategoryStepper/CategoryStepper.php.
 21+2. Place the CategoryStepper.i18n.php source code into
 22+ extensions/CategoryStepper/CategoryStepper.i18n.php.
 23+3. If desired place the CategoryStepper.css source code into
 24+ skins/CategoryStepper.css.
 25+4. Add require_once( "$IP/extensions/CategoryStepper/CategoryStepper.php" ); to
 26+ LocalSettings.php.
 27+5. Enjoy!
 28+
 29+Installation can be verified through the [[Special:Version]] page on the wiki.
 30+
 31+== Using the extension ==
 32+
 33+CategoryStepper adds a box to the bottom of the content area on pages which are
 34+in a specified category. Categories can be configured either via using the
 35+$wgCategoryStepper configuration variable or by mofifying the page
 36+MediaWiki:categorystepper.
 37+
 38+Fill the $wgCategoryStepper variable with a list of category names to stepper
 39+box titles; e.g.
 40+$wgCategoryStepper[ "Astronauts" ] = "Astronauts Box Title";
 41+
 42+Alternatively set the $wgCategoryStepper variable to false and use the
 43+MediaWiki:Categorystepper page to set options; e.g.
 44+
 45+LocalSettings.php:
 46+ $wgCategoryStepper = false;
 47+MediaWiki:Categorystepper:
 48+ * Astronauts|Astronauts Box Title
 49+
 50+== Change log ==
 51+
 52+Version 1.1
 53+2008-01-19
 54+ Original version.
 55+
 56+Version 1.2
 57+2008-01-20
 58+ Added missing space in i18n file.
 59+
 60+Version 1.3
 61+2008-02-16
 62+ No longer render on edit, protect or delete pages.
 63+ Allow modification of categories and title via the
 64+ MediaWiki:categorystepper page.
 65+
 66+Version 1.4
 67+2008-02-17
 68+ The second parameter of each row on the MediaWiki:categorystepper page is
 69+ now optional and defaults to the first parameter.
 70+
 71+Version 1.5
 72+2008-02-26
 73+ Default wikitable-like styling is now included and can optionally be used,
 74+ or overridden via MediaWiki:Common.css or the individual skins CSS
 75+ MediaWiki namespace pages.
 76+ README added.
 77+ Function wfCategoryStepper renamed to efCategoryStepper.
 78+ ltrim() now used instead of preg_replace().
 79+
 80+== Feedback ==
 81+
 82+Bugs and feature requests should be reported via MediaZilla
 83+<http://bugzilla.wikimedia.org/> and placed in the 'MediaWiki extensions'
 84+product under the CategoryStepper component. Alternatively send an e-mail to
 85+<minuteelectron@googlemail.com> with any comments or suggestions, all are
 86+welcome.

Status & tagging log