r53440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53439‎ | r53440 | r53441 >
Date:13:47, 18 July 2009
Author:minuteelectron
Status:deferred
Tags:
Comment:
CategoryOnUpload:
* Add variable for manually overriding the category list.
Modified paths:
  • /trunk/extensions/CategoryOnUpload/CategoryOnUpload.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryOnUpload/CategoryOnUpload.php
@@ -11,8 +11,8 @@
1212 *
1313 * @link http://www.mediawiki.org/wiki/Extension:CategoryOnUpload
1414 *
15 - * @author MinuteElectron <minuteelectron@googlemail.com>
16 - * @copyright Copyright © 2008 MinuteElectron.
 15+ * @author Robert Leverington <robert@rhl.me.uk>
 16+ * @copyright Copyright © 2008 - 2009 Robert Leverington.
1717 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1818 */
1919
@@ -24,8 +24,8 @@
2525 'path' => __FILE__,
2626 'name' => 'CategoryOnUpload',
2727 'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryOnUpload',
28 - 'author' => 'MinuteElectron',
29 - 'version' => '1.0',
 28+ 'author' => 'Robert Leverington',
 29+ 'version' => '1.1.0',
3030 'description' => 'Prompts a user to select a category when uploading a file.',
3131 'decriptionmsg' => 'categoryonupload-desc'
3232 );
@@ -40,6 +40,7 @@
4141 // Initialize configuration variables.
4242 $wgCategoryOnUploadDefault = null;
4343 $wgCategoryOnUploadAllowNone = true;
 44+$wgCategoryOnUploadList = null;
4445
4546 /**
4647 * Adds a category selection box to the end of the default UploadForm table.
@@ -80,48 +81,62 @@
8182
8283 }
8384
84 - /* Get a database read object.
85 - */
86 - $dbr = wfGetDB( DB_SLAVE );
87 -
88 - /* Perform a query on the categorylinks table to retreieve a list of all
89 - * cateogries, this probably shouldn't be installed on wikis with more than
90 - * a few hundred categories as the list would be very long. If anyone ever
91 - * feels the need to put this extension on such a wiki, a dynamic AJAX
92 - * interface could be created; but when it was developed only a few needed
93 - * to be displayed so this was not an issue. Fallback to the select box is
94 - * essential no matter what improvements are made.
95 - *
96 - * It would be nice to use the category table to avoid having to do a
97 - * manual query and perhaps improve performance, but it appears to not
98 - * descriminate between existing and non-existing categories, this would be
99 - * essential; probably needs more looking in to however. Also it would be
100 - * nice not to use it until 1.13 is released so that it works on at least
101 - * the latest release.
102 - */
103 - $res = $dbr->query( 'SELECT DISTINCT cl_to FROM ' . $wgDBprefix . 'categorylinks' );
104 -
10585 /* Get deault category, to compare with category option being output, so the
10686 * default category can be selected.
10787 */
108 - global $wgCategoryOnUploadDefault;
 88+ global $wgCategoryOnUploadDefault, $wgCategoryOnUploadList;
10989
110 - /* Generate an option for each of the categories in the wiki and add. A
111 - * title object could be generated for each of the categories so that the
112 - * hacky replacement of '_' to ' ' could be removed, but it seams a waste
113 - * of resources. If this becomes an issue simply remove the # comments and
114 - * comment out the first line.
115 - */
116 - while( $row = $dbr->fetchObject( $res ) ) {
 90+ if( !is_array( $wgCategoryOnUploadList ) ) {
11791
118 - $text = str_replace( '_', ' ', $row->cl_to );
119 - #$title = Title::newFromText( $row->cl_to, NS_CATEGORY );
120 - #$text = $title->getText();
 92+ /* Get a database read object.
 93+ */
 94+ $dbr = wfGetDB( DB_SLAVE );
12195
122 - /* Add option to output, if it is the default then make it selected too.
 96+ /* Perform a query on the categorylinks table to retreieve a list of all
 97+ * cateogries, this probably shouldn't be installed on wikis with more than
 98+ * a few hundred categories as the list would be very long. If anyone ever
 99+ * feels the need to put this extension on such a wiki, a dynamic AJAX
 100+ * interface could be created; but when it was developed only a few needed
 101+ * to be displayed so this was not an issue. Fallback to the select box is
 102+ * essential no matter what improvements are made.
 103+ *
 104+ * It would be nice to use the category table to avoid having to do a
 105+ * manual query and perhaps improve performance, but it appears to not
 106+ * descriminate between existing and non-existing categories, this would be
 107+ * essential; probably needs more looking in to however. Also it would be
 108+ * nice not to use it until 1.13 is released so that it works on at least
 109+ * the latest release.
123110 */
124 - $cat .= Xml::option( $text, $row->cl_to, ( $text == $wgCategoryOnUploadDefault ) );
 111+ $res = $dbr->query( 'SELECT DISTINCT cl_to FROM ' . $wgDBprefix . 'categorylinks' );
125112
 113+ /* Generate an option for each of the categories in the wiki and add. A
 114+ * title object could be generated for each of the categories so that the
 115+ * hacky replacement of '_' to ' ' could be removed, but it seams a waste
 116+ * of resources. If this becomes an issue simply remove the # comments and
 117+ * comment out the first line.
 118+ */
 119+ while( $row = $dbr->fetchObject( $res ) ) {
 120+
 121+ $text = str_replace( '_', ' ', $row->cl_to );
 122+ #$title = Title::newFromText( $row->cl_to, NS_CATEGORY );
 123+ #$text = $title->getText();
 124+
 125+ /* Add option to output, if it is the default then make it selected too.
 126+ */
 127+ $cat .= Xml::option( $text, $row->cl_to, ( $text == $wgCategoryOnUploadDefault ) );
 128+
 129+ }
 130+
 131+ } else {
 132+ foreach( $wgCategoryOnUploadList as $category ) {
 133+ $text = str_replace( '_', ' ', $category );
 134+ #$title = Title::newFromText( $row->cl_to, NS_CATEGORY );
 135+ #$text = $title->getText();
 136+
 137+ /* Add option to output, if it is the default then make it selected too.
 138+ */
 139+ $cat .= Xml::option( $text, $category, ( $text == $wgCategoryOnUploadDefault ) );
 140+ }
126141 }
127142
128143 /* Close all the open elements, finished generation.

Status & tagging log