Index: trunk/extensions/BackAndForth/BackAndForth.class.php |
— | — | @@ -0,0 +1,97 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class file for the BackAndForth extension |
| 6 | + * |
| 7 | + * @addtogroup Extensions |
| 8 | + * @author Rob Church <robchur@gmail.com> |
| 9 | + */ |
| 10 | +class BackAndForth { |
| 11 | + |
| 12 | + /** |
| 13 | + * Article::view() hook |
| 14 | + * |
| 15 | + * @param Article $article |
| 16 | + * @return bool |
| 17 | + */ |
| 18 | + public static function viewHook( $article ) { |
| 19 | + global $wgOut, $wgUser; |
| 20 | + $title = $article->getTitle(); |
| 21 | + if( Namespace::isContent( $title->getNamespace() ) ) { |
| 22 | + $wgOut->addHtml( self::buildLinks( $title ) ); |
| 23 | + $wgOut->addHeadItem( 'backandforth', self::buildHeadItem() ); |
| 24 | + } |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Build a set of next/previous links for a given title |
| 30 | + * |
| 31 | + * @param Title $title |
| 32 | + * @return string |
| 33 | + */ |
| 34 | + private static function buildLinks( $title ) { |
| 35 | + $links = ''; |
| 36 | + foreach( array( 'prev' => '<', 'next' => '>' ) as $kind => $op ) { |
| 37 | + if( ( $link = self::buildLink( $title, $op, $kind ) ) !== false ) |
| 38 | + $links .= "<div class=\"mw-backforth-{$kind}\">{$link}</div>"; |
| 39 | + } |
| 40 | + return "{$links}<div style=\"clear: both;\"></div>"; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Build a single link for a given title |
| 45 | + * |
| 46 | + * @param Title $title |
| 47 | + * @param string $op |
| 48 | + * @param string $label |
| 49 | + * @return mixed |
| 50 | + */ |
| 51 | + private static function buildLink( $title, $op, $label ) { |
| 52 | + wfProfileIn( __METHOD__ ); |
| 53 | + $dbr = wfGetDB( DB_SLAVE ); |
| 54 | + $res = $dbr->select( |
| 55 | + 'page', |
| 56 | + array( 'page_namespace', 'page_title' ), |
| 57 | + array( |
| 58 | + 'page_is_redirect' => 0, |
| 59 | + 'page_namespace' => $title->getNamespace(), |
| 60 | + "page_title {$op} " . $dbr->addQuotes( $title->getDBkey() ), |
| 61 | + ), |
| 62 | + __METHOD__, |
| 63 | + array( |
| 64 | + 'ORDER BY' => 'page_title' . ( $op == '<' ? ' DESC' : '' ), |
| 65 | + 'LIMIT' => 1, |
| 66 | + ) |
| 67 | + ); |
| 68 | + if( $res->numRows() > 0 ) { |
| 69 | + $row = $res->fetchObject(); |
| 70 | + $target = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
| 71 | + if( $target instanceof Title ) { |
| 72 | + $label = htmlspecialchars( wfMsg( "backforth-{$label}", $target->getPrefixedText() ) ); |
| 73 | + wfProfileOut( __METHOD__ ); |
| 74 | + return $GLOBALS['wgUser']->getSkin()->makeKnownLinkObj( $target, $label ); |
| 75 | + } |
| 76 | + } |
| 77 | + wfProfileOut( __METHOD__ ); |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Generate a CSS fragment for inclusion on the page |
| 83 | + * |
| 84 | + * @return string |
| 85 | + */ |
| 86 | + private static function buildHeadItem() { |
| 87 | + $css = file_get_contents( dirname( __FILE__ ) . '/BackAndForth.css' ); |
| 88 | + return <<<EOT |
| 89 | +<style type="text/css"> |
| 90 | +/*<![CDATA[*/ |
| 91 | +{$css} |
| 92 | +/*]]>*/ |
| 93 | +</style> |
| 94 | +EOT |
| 95 | + ; |
| 96 | + } |
| 97 | + |
| 98 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/BackAndForth.class.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 99 | + native |
Index: trunk/extensions/BackAndForth/LICENSE |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +Copyright © 2007 Rob Church. |
| 3 | +All rights reserved. |
| 4 | + |
| 5 | +Redistribution and use in source and binary forms, with or without |
| 6 | +modification, are permitted provided that the following conditions |
| 7 | +are met: |
| 8 | + |
| 9 | + 1. Redistributions of source code must retain the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer. |
| 11 | + |
| 12 | + 2. Redistributions in binary form must reproduce the above |
| 13 | + copyright notice, this list of conditions and the following |
| 14 | + disclaimer in the documentation and/or other materials provided |
| 15 | + with the distribution. |
| 16 | + |
| 17 | +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | +DISCLAIMED. |
| 21 | + |
| 22 | +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 25 | +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 27 | +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 28 | +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/LICENSE |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: trunk/extensions/BackAndForth/BackAndForth.i18n.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Internationalisation file for the BackAndForth extension |
| 6 | + * |
| 7 | + * @author Rob Church <robchur@gmail.com> |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Fetch extension messages indexed per language |
| 12 | + * |
| 13 | + * @return array |
| 14 | + */ |
| 15 | +function efBackAndForthMessages() { |
| 16 | + $messages = array( |
| 17 | + |
| 18 | +/** |
| 19 | + * English |
| 20 | + */ |
| 21 | +'en' => array( |
| 22 | + 'backforth-next' => 'Next ($1)', |
| 23 | + 'backforth-prev' => 'Previous ($1)', |
| 24 | +), |
| 25 | + |
| 26 | + ); |
| 27 | + return $messages; |
| 28 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/BackAndForth.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: trunk/extensions/BackAndForth/BackAndForth.php |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Extension adds "next" and "previous" alphabetic paging links to |
| 6 | + * the top of articles |
| 7 | + * |
| 8 | + * @addtogroup Extensions |
| 9 | + * @author Rob Church <robchur@gmail.com> |
| 10 | + */ |
| 11 | +if( defined( 'MEDIAWIKI' ) ) { |
| 12 | + |
| 13 | + $wgAutoloadClasses['BackAndForth'] = dirname( __FILE__ ) . '/BackAndForth.class.php'; |
| 14 | + $wgExtensionFunctions[] = 'efBackAndForth'; |
| 15 | + $wgExtensionCredits['other'][] = array( |
| 16 | + 'name' => 'Back and Forth', |
| 17 | + 'author' => 'Rob Church', |
| 18 | + ); |
| 19 | + |
| 20 | + /** |
| 21 | + * Extension setup function |
| 22 | + */ |
| 23 | + function efBackAndForth() { |
| 24 | + global $wgMessageCache, $wgHooks; |
| 25 | + require_once( dirname( __FILE__ ) . '/BackAndForth.i18n.php' ); |
| 26 | + foreach( efBackAndForthMessages() as $lang => $messages ) |
| 27 | + $wgMessageCache->addMessages( $messages, $lang ); |
| 28 | + $wgHooks['ArticleViewHeader'][] = 'BackAndForth::viewHook'; |
| 29 | + } |
| 30 | + |
| 31 | +} else { |
| 32 | + echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); |
| 33 | + exit( 1 ); |
| 34 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/BackAndForth.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: trunk/extensions/BackAndForth/BackAndForth.css |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +/** |
| 3 | + * CSS for the BackAndForth extension |
| 4 | + */ |
| 5 | +div.mw-backforth-prev, |
| 6 | +div.mw-backforth-next { |
| 7 | + font-size: 80%; |
| 8 | +} |
| 9 | +div.mw-backforth-prev { |
| 10 | + float: left; |
| 11 | +} |
| 12 | +div.mw-backforth-next { |
| 13 | + float: right; |
| 14 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/BackAndForth.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 15 | + native |
Index: trunk/extensions/BackAndForth/README |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +Back-And-Forth Extension |
| 3 | +© 2007 Rob Church |
| 4 | +See LICENSE file for full licencing information |
| 5 | + |
| 6 | +The Back-And-Forth extension adds "previous" and "next" links at the top |
| 7 | +of the page when viewing articles, which point to the pages which |
| 8 | +alphabetically precede and follow the current one. |
| 9 | + |
| 10 | +== Requirements == |
| 11 | + |
| 12 | +The Back-And-Forth extension requires MediaWiki 1.11.0 or above. |
| 13 | + |
| 14 | +== Installation == |
| 15 | + |
| 16 | +1. Place extension files into a "BackAndForth" directory in your |
| 17 | + MediaWiki "extensions/" directory |
| 18 | + |
| 19 | +2. Add the line |
| 20 | + `require_once( "{$IP}/extensions/BackAndForth/BackAndForth.php" );` |
| 21 | + to LocalSettings.php. |
| 22 | + |
| 23 | +Installation can be verified through the Special:Version page on the wiki. |
| 24 | + |
| 25 | +Links may not show up immediately due to client-side or other caches. |
\ No newline at end of file |
Property changes on: trunk/extensions/BackAndForth/README |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |