r60967 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60966‎ | r60967 | r60968 >
Date:13:27, 12 January 2010
Author:jojo
Status:ok
Tags:
Comment:
new method for specifying titles for saved books

* added 2 sysmgs coll-user_book_prefix and coll-community_book_prefix
* fallback to old behavior (this is the default for empty sysmsgs)

This allows us to use e.g. a custom namespace Book for community books.
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.templates.php (modified) (history)
  • /trunk/extensions/Collection/CollectionCore.i18n.php (modified) (history)
  • /trunk/extensions/Collection/README.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/CollectionCore.i18n.php
@@ -60,6 +60,8 @@
6161 'coll-make_suggestions_tooltip' => 'Show suggestions based on the pages in your book',
6262 'coll-suggest_enabled' => '1',
6363 'coll-suggest_empty' => 'empty',
 64+ 'coll-user_book_prefix' => '-',
 65+ 'coll-community_book_prefix' => '-',
6466 );
6567
6668 /** Message documentation (Message documentation)
Index: trunk/extensions/Collection/README.txt
@@ -150,6 +150,9 @@
151151 Namespace for "community collections", i.e. the namespace where non-personal
152152 article collection pages are saved.
153153
 154+ Note: This configuration setting is only used if the system message
 155+ Coll-community_book_prefix has not been set (see below).
 156+
154157 Default is ``NS_PROJECT``.
155158
156159 *$wgCollectionMaxArticles (integer)*
@@ -243,6 +246,23 @@
244247 The default for English language is "Help:Books", and there exist translations
245248 for lots of different languages.
246249
 250+* Coll-user_book_prefix: Prefix for titles of "user books" (i.e. books for
 251+ personal use, as opposed to "community books"). If the system message is empty
 252+ or '-' (the default), the title of user book pages is constructed
 253+ as User:USERNAME/Books/BOOKTITLE. If the system message is set and its content
 254+ is PREFIX, the title of user book pages is constructed by directly concatenating
 255+ PREFIX and the BOOKTITLE, i.e. there's no implicitly inserted '/' inbetween!
 256+
 257+* Coll-community_book_prefix: Prefix for titles of "community books" (cf. "user
 258+ books" above). If the system message is empty or '-' (the default), the title
 259+ of community pages is constructed as NAMESPACE:Books/BOOKTITLE, where
 260+ NAMESPACE depends on the value of $wgCommunityCollectionNamespace (see above).
 261+ If the system message is set and its content is PREFIX, the title of community
 262+ book pages is constructed by directly concatenating PREFIX and BOOKTITLE,
 263+ i.e. there's no implicitly inserted '/' inbetween. Thus it's possible to
 264+ define a custom namespace 'Book' and set the system message to 'Book:' to
 265+ produce community book page titles Book:BOOKTITLE.
 266+
247267 * Coll-savedbook_template: The name of the template (w/out the Template: prefix)
248268 included at the top of saved book pages (see above).
249269 The default is: 'saved_book', and there exist translations for lots of
Index: trunk/extensions/Collection/Collection.body.php
@@ -210,24 +210,19 @@
211211 return;
212212 }
213213 $colltype = $wgRequest->getVal( 'colltype' );
 214+ $prefixes = self::getBookPagePrefixes();
214215 if ( $colltype == 'personal' ) {
215216 $collname = $wgRequest->getVal( 'pcollname' );
216217 if ( !$wgUser->isAllowed( 'collectionsaveasuserpage' ) || empty( $collname ) ) {
217218 return;
218219 }
219 - $userPageTitle = $wgUser->getUserPage()->getPrefixedText();
220 - $title = Title::newFromText(
221 - $userPageTitle . '/' . wfMsgForContent( 'coll-collections' ) . '/' . $collname
222 - );
 220+ $title = Title::newFromText( $prefixes['user-prefix'] . $collname );
223221 } elseif ( $colltype == 'community' ) {
224222 $collname = $wgRequest->getVal( 'ccollname' );
225223 if ( !$wgUser->isAllowed( 'collectionsaveascommunitypage' ) || empty( $collname ) ) {
226224 return;
227225 }
228 - $title = Title::makeTitle(
229 - $wgCommunityCollectionNamespace,
230 - wfMsgForContent( 'coll-collections' ) . '/' . $collname
231 - );
 226+ $title = Title::newFromText( $prefixes['community-prefix'] . $collname );
232227 }
233228 if ( !$title ) {
234229 return;
@@ -467,7 +462,36 @@
468463 );
469464 }
470465
 466+ static function getBookPagePrefixes() {
 467+ global $wgUser;
 468+ global $wgCommunityCollectionNamespace;
471469
 470+ wfLoadExtensionMessages( 'CollectionCore' );
 471+
 472+ $result = array();
 473+
 474+ $t = wfMsgForContent( 'coll-user_book_prefix', $wgUser->getName() );
 475+ if ( wfEmptyMsg( 'coll-user_book_prefix', $t ) || $t == '-' ) {
 476+ $userPageTitle = $wgUser->getUserPage()->getPrefixedText();
 477+ $result['user-prefix'] = $userPageTitle . '/'
 478+ . wfMsgForContent( 'coll-collections' ) . '/';
 479+ } else {
 480+ $result['user-prefix'] = $t;
 481+ }
 482+
 483+ $t = wfMsgForContent( 'coll-community_book_prefix' );
 484+ if ( wfEmptyMsg( 'coll-community_book_prefix', $t) || $t == '-' ) {
 485+ $title = Title::makeTitle(
 486+ $wgCommunityCollectionNamespace,
 487+ wfMsgForContent( 'coll-collections' )
 488+ );
 489+ $result['community-prefix'] = $title->getPrefixedText() . '/';
 490+ } else {
 491+ $result['community-prefix'] = $t;
 492+ }
 493+ return $result;
 494+ }
 495+
472496 function renderSpecialPage() {
473497 global $wgCollectionFormats;
474498 global $wgCollectionVersion;
@@ -494,6 +518,9 @@
495519 $template->set( 'collection', $_SESSION['wsCollection'] );
496520 $template->set( 'podpartners', $this->mPODPartners );
497521 $template->set( 'formats', $wgCollectionFormats);
 522+ $prefixes = self::getBookPagePrefixes();
 523+ $template->set( 'user-book-prefix', $prefixes['user-prefix'] );
 524+ $template->set( 'community-book-prefix', $prefixes['community-prefix'] );
498525 $wgOut->addTemplate( $template );
499526 }
500527
Index: trunk/extensions/Collection/Collection.templates.php
@@ -151,7 +151,7 @@
152152 <?php } else { ?>
153153 <input type="hidden" name="colltype" value="personal" />
154154 <?php } ?>
155 - <label for="personalCollTitle"><a href="<?php echo htmlspecialchars(SkinTemplate::makeSpecialUrl('Prefixindex', 'prefix=' . wfUrlencode($GLOBALS['wgUser']->getName()) . '/' . wfUrlencode($bookname) . '/&namespace=2')) ?>"><?php echo htmlspecialchars($GLOBALS['wgUser']->getUserPage()->getPrefixedText() . '/' . $bookname . '/') ?></a></label>
 155+ <label for="personalCollTitle"><a href="<?php echo htmlspecialchars(SkinTemplate::makeSpecialUrl('Prefixindex', 'prefix=' . wfUrlencode($this->data['user-book-prefix']))) ?>"><?php echo htmlspecialchars($this->data['user-book-prefix']) ?></a></label>
156156 </td>
157157 <td style="text-align:right;">
158158 <input id="personalCollTitle" type="text" name="pcollname" />
@@ -164,7 +164,7 @@
165165 <?php } else { ?>
166166 <input type="hidden" name="colltype" value="community" />
167167 <?php } ?>
168 - <label for="communityCollTitle"><a href="<?php echo htmlspecialchars(SkinTemplate::makeSpecialUrl('Prefixindex', 'prefix=' . wfUrlencode($bookname) . '/&namespace=' . $communityCollNS)) ?>"><?php echo htmlspecialchars(Title::makeTitle($communityCollNS, $bookname)->getPrefixedText() . '/') ?></a></label>
 168+ <label for="communityCollTitle"><a href="<?php echo htmlspecialchars(SkinTemplate::makeSpecialUrl('Prefixindex', 'prefix=' . wfUrlencode($this->data['community-book-prefix']))) ?>"><?php echo htmlspecialchars($this->data['community-book-prefix']) ?></a></label>
169169 </td>
170170 <td style="text-align:right;">
171171 <input id="communityCollTitle" type="text" name="ccollname" disabled="disabled" />

Follow-up revisions

RevisionCommit summaryAuthorDate
r60972Follow-up r60967: Ignore new messages for translatewikiraymond16:57, 12 January 2010

Status & tagging log