Index: trunk/extensions/CategoryOnUpload/CategoryOnUpload.php |
— | — | @@ -11,8 +11,8 @@ |
12 | 12 | * |
13 | 13 | * @link http://www.mediawiki.org/wiki/Extension:CategoryOnUpload |
14 | 14 | * |
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. |
17 | 17 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
18 | 18 | */ |
19 | 19 | |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | 'path' => __FILE__, |
26 | 26 | 'name' => 'CategoryOnUpload', |
27 | 27 | 'url' => 'http://www.mediawiki.org/wiki/Extension:CategoryOnUpload', |
28 | | - 'author' => 'MinuteElectron', |
29 | | - 'version' => '1.0', |
| 28 | + 'author' => 'Robert Leverington', |
| 29 | + 'version' => '1.1.0', |
30 | 30 | 'description' => 'Prompts a user to select a category when uploading a file.', |
31 | 31 | 'decriptionmsg' => 'categoryonupload-desc' |
32 | 32 | ); |
— | — | @@ -40,6 +40,7 @@ |
41 | 41 | // Initialize configuration variables. |
42 | 42 | $wgCategoryOnUploadDefault = null; |
43 | 43 | $wgCategoryOnUploadAllowNone = true; |
| 44 | +$wgCategoryOnUploadList = null; |
44 | 45 | |
45 | 46 | /** |
46 | 47 | * Adds a category selection box to the end of the default UploadForm table. |
— | — | @@ -80,48 +81,62 @@ |
81 | 82 | |
82 | 83 | } |
83 | 84 | |
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 | | - |
105 | 85 | /* Get deault category, to compare with category option being output, so the |
106 | 86 | * default category can be selected. |
107 | 87 | */ |
108 | | - global $wgCategoryOnUploadDefault; |
| 88 | + global $wgCategoryOnUploadDefault, $wgCategoryOnUploadList; |
109 | 89 | |
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 ) ) { |
117 | 91 | |
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 ); |
121 | 95 | |
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. |
123 | 110 | */ |
124 | | - $cat .= Xml::option( $text, $row->cl_to, ( $text == $wgCategoryOnUploadDefault ) ); |
| 111 | + $res = $dbr->query( 'SELECT DISTINCT cl_to FROM ' . $wgDBprefix . 'categorylinks' ); |
125 | 112 | |
| 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 | + } |
126 | 141 | } |
127 | 142 | |
128 | 143 | /* Close all the open elements, finished generation. |