http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60967

Revision: 60967
Author:   jojo
Date:     2010-01-12 13:27:39 +0000 (Tue, 12 Jan 2010)

Log Message:
-----------
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
    trunk/extensions/Collection/Collection.templates.php
    trunk/extensions/Collection/CollectionCore.i18n.php
    trunk/extensions/Collection/README.txt

Modified: trunk/extensions/Collection/Collection.body.php
===================================================================
--- trunk/extensions/Collection/Collection.body.php     2010-01-12 12:24:47 UTC 
(rev 60966)
+++ trunk/extensions/Collection/Collection.body.php     2010-01-12 13:27:39 UTC 
(rev 60967)
@@ -210,24 +210,19 @@
                                        return;
                                }
                                $colltype = $wgRequest->getVal( 'colltype' );
+                               $prefixes = self::getBookPagePrefixes();
                                if ( $colltype == 'personal' ) {
                                        $collname = $wgRequest->getVal( 
'pcollname' );
                                        if ( !$wgUser->isAllowed( 
'collectionsaveasuserpage' ) || empty( $collname ) ) {
                                                return;
                                        }
-                                       $userPageTitle = 
$wgUser->getUserPage()->getPrefixedText();
-                                       $title = Title::newFromText(
-                                               $userPageTitle . '/' . 
wfMsgForContent( 'coll-collections' ) . '/' . $collname
-                                       );
+                                       $title = Title::newFromText( 
$prefixes['user-prefix'] . $collname );
                                } elseif ( $colltype == 'community' ) {
                                        $collname = $wgRequest->getVal( 
'ccollname' );
                                        if ( !$wgUser->isAllowed( 
'collectionsaveascommunitypage' ) || empty( $collname ) ) {
                                                return;
                                        }
-                                       $title = Title::makeTitle(
-                                               $wgCommunityCollectionNamespace,
-                                               wfMsgForContent( 
'coll-collections' ) . '/' . $collname
-                                       );
+                                       $title = Title::newFromText( 
$prefixes['community-prefix'] . $collname );
                                }
                                if ( !$title ) {
                                        return;
@@ -467,7 +462,36 @@
                );
        }
 
+       static function getBookPagePrefixes() {
+               global $wgUser;
+               global $wgCommunityCollectionNamespace;
 
+               wfLoadExtensionMessages( 'CollectionCore' );
+
+               $result = array();
+
+               $t = wfMsgForContent( 'coll-user_book_prefix', 
$wgUser->getName() );
+               if ( wfEmptyMsg( 'coll-user_book_prefix', $t ) || $t == '-' ) {
+                       $userPageTitle = 
$wgUser->getUserPage()->getPrefixedText();
+                       $result['user-prefix'] = $userPageTitle . '/'
+                               . wfMsgForContent( 'coll-collections' ) . '/';
+               } else {
+                       $result['user-prefix'] = $t;
+               }
+
+               $t = wfMsgForContent( 'coll-community_book_prefix' );
+               if ( wfEmptyMsg( 'coll-community_book_prefix', $t) || $t == '-' 
) {
+                       $title = Title::makeTitle(
+                               $wgCommunityCollectionNamespace,
+                               wfMsgForContent( 'coll-collections' )
+                       );
+                       $result['community-prefix'] = $title->getPrefixedText() 
. '/';
+               } else {
+                       $result['community-prefix'] = $t;
+               }
+               return $result;
+       }
+
        function renderSpecialPage() {
                global $wgCollectionFormats;
                global $wgCollectionVersion;
@@ -494,6 +518,9 @@
                $template->set( 'collection', $_SESSION['wsCollection'] );
                $template->set( 'podpartners', $this->mPODPartners );
                $template->set( 'formats', $wgCollectionFormats);
+               $prefixes = self::getBookPagePrefixes();
+               $template->set( 'user-book-prefix', $prefixes['user-prefix'] );
+               $template->set( 'community-book-prefix', 
$prefixes['community-prefix'] );
                $wgOut->addTemplate( $template );
        }
 

Modified: trunk/extensions/Collection/Collection.templates.php
===================================================================
--- trunk/extensions/Collection/Collection.templates.php        2010-01-12 
12:24:47 UTC (rev 60966)
+++ trunk/extensions/Collection/Collection.templates.php        2010-01-12 
13:27:39 UTC (rev 60967)
@@ -151,7 +151,7 @@
                                <?php } else { ?>
                                <input type="hidden" name="colltype" 
value="personal" />
                                <?php } ?>
-                               <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>
+                               <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>
                                </td>
                                <td style="text-align:right;">
                                <input id="personalCollTitle" type="text" 
name="pcollname" />
@@ -164,7 +164,7 @@
                                <?php } else { ?>
                                <input type="hidden" name="colltype" 
value="community" />
                                <?php } ?>
-                               <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>
+                               <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>
                                </td>
                                <td style="text-align:right;">
                                <input id="communityCollTitle" type="text" 
name="ccollname" disabled="disabled" />

Modified: trunk/extensions/Collection/CollectionCore.i18n.php
===================================================================
--- trunk/extensions/Collection/CollectionCore.i18n.php 2010-01-12 12:24:47 UTC 
(rev 60966)
+++ trunk/extensions/Collection/CollectionCore.i18n.php 2010-01-12 13:27:39 UTC 
(rev 60967)
@@ -60,6 +60,8 @@
        'coll-make_suggestions_tooltip' => 'Show suggestions based on the pages 
in your book',
        'coll-suggest_enabled'          => '1',
        'coll-suggest_empty'            => 'empty',
+       'coll-user_book_prefix'         => '-',
+       'coll-community_book_prefix'    => '-',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/Collection/README.txt
===================================================================
--- trunk/extensions/Collection/README.txt      2010-01-12 12:24:47 UTC (rev 
60966)
+++ trunk/extensions/Collection/README.txt      2010-01-12 13:27:39 UTC (rev 
60967)
@@ -150,6 +150,9 @@
    Namespace for "community collections", i.e. the namespace where non-personal
    article collection pages are saved.
 
+        Note: This configuration setting is only used if the system message
+        Coll-community_book_prefix has not been set (see below).
+
    Default is ``NS_PROJECT``.
 
   *$wgCollectionMaxArticles (integer)*
@@ -243,6 +246,23 @@
   The default for English language is "Help:Books", and there exist 
translations
        for lots of different languages.
 
+* Coll-user_book_prefix: Prefix for titles of "user books" (i.e. books for
+  personal use, as opposed to "community books"). If the system message is 
empty
+       or '-' (the default), the title of user book pages is constructed
+       as User:USERNAME/Books/BOOKTITLE. If the system message is set and its 
content
+       is PREFIX, the title of user book pages is constructed by directly 
concatenating
+       PREFIX and the BOOKTITLE, i.e. there's no implicitly inserted '/' 
inbetween!
+
+* Coll-community_book_prefix: Prefix for titles of "community books" (cf. "user
+  books" above). If the system message is empty or '-' (the default), the title
+       of community pages is constructed as NAMESPACE:Books/BOOKTITLE, where
+       NAMESPACE depends on the value of $wgCommunityCollectionNamespace (see 
above).
+       If the system message is set and its content is PREFIX, the title of 
community
+       book pages is constructed by directly concatenating PREFIX and 
BOOKTITLE,
+       i.e. there's no implicitly inserted '/' inbetween. Thus it's possible to
+       define a custom namespace 'Book' and set the system message to 'Book:' 
to
+       produce community book page titles Book:BOOKTITLE.
+
 * Coll-savedbook_template: The name of the template (w/out the Template: 
prefix)
   included at the top of saved book pages (see above).
        The default is: 'saved_book', and there exist translations for lots of



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to