Index: trunk/extensions/BookManager/BookManager.body.php |
— | — | @@ -116,10 +116,10 @@ |
117 | 117 | /** |
118 | 118 | * Get the prefixed title of a page near the given page. |
119 | 119 | * @param $text String Text for title of current page |
120 | | - * @param $n Integer Position of wanted page. Next page is +1; Previous page is -1 |
| 120 | + * @param $p Integer/String Position of wanted page. Next page is +1; Previous page is -1; Random position is 'rand' |
121 | 121 | * @return String The prefixed title or empty string if not found or found but not valid |
122 | 122 | */ |
123 | | - protected static function pageText( &$parser, $text = null, $n = 0 ) { |
| 123 | + protected static function pageText( &$parser, $text = null, $p = 0 ) { |
124 | 124 | $pagetitle = self::newTitleObject( $parser, $text ); |
125 | 125 | $prefixes = self::getBookPagePrefixes(); |
126 | 126 | $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0 ) ); // ...the book name will be 'Foo'. |
— | — | @@ -131,13 +131,18 @@ |
132 | 132 | return ''; |
133 | 133 | } |
134 | 134 | $current = array_search( $pagetitle, self::$chapterList ); |
135 | | - if ( $current === false || !isset( self::$chapterList[ $current + $n ] ) ) { |
| 135 | + if ( $current === false || !isset( self::$chapterList[ $current + $p ] ) ) { |
136 | 136 | return ''; |
137 | 137 | } |
138 | | - $otherpagetitle = Title::newFromText( self::$chapterList[ $current + $n ] ); |
| 138 | + $otherpagetitle = Title::newFromText( self::$chapterList[ $current + $p ] ); |
139 | 139 | if ( is_null( $otherpagetitle ) ) { |
140 | 140 | return ''; |
141 | 141 | } |
| 142 | + if ( $p == 'rand' ){ |
| 143 | + $limit = count( self::$chapterList ) - 1; |
| 144 | + $randPosition = rand( 0, $limit ); |
| 145 | + return Title::newFromText( self::$chapterList[ $randPosition ] ); |
| 146 | + } |
142 | 147 | return wfEscapeWikiText( $otherpagetitle->getText() ); |
143 | 148 | } |
144 | 149 | } |
— | — | @@ -156,7 +161,8 @@ |
157 | 162 | $parser->setFunctionHook( 'rootpagenamee', array( __CLASS__, 'rootpagenamee' ), SFH_NO_HASH ); |
158 | 163 | $parser->setFunctionHook( 'chaptername', array( __CLASS__, 'chaptername' ), SFH_NO_HASH ); |
159 | 164 | $parser->setFunctionHook( 'chapternamee', array( __CLASS__, 'chapternamee' ), SFH_NO_HASH ); |
160 | | - |
| 165 | + $parser->setFunctionHook( 'randomchapter', array( __CLASS__, 'randomchapter' ), SFH_NO_HASH ); |
| 166 | + $parser->setFunctionHook( 'randomchaptere', array( __CLASS__, 'randomchaptere' ), SFH_NO_HASH ); |
161 | 167 | return true; |
162 | 168 | } |
163 | 169 | # Function to declare magicword id |
— | — | @@ -171,6 +177,9 @@ |
172 | 178 | $aCustomVariableIds[] = 'rootpagenamee'; |
173 | 179 | $aCustomVariableIds[] = 'chaptername'; |
174 | 180 | $aCustomVariableIds[] = 'chapternamee'; |
| 181 | + $aCustomVariableIds[] = 'randomchapter'; |
| 182 | + $aCustomVariableIds[] = 'randomchaptere'; |
| 183 | + |
175 | 184 | return true; |
176 | 185 | } |
177 | 186 | |
— | — | @@ -208,6 +217,14 @@ |
209 | 218 | $t = self::bookparts( $parser, $text, 1 ); |
210 | 219 | return wfUrlEncode( $t ); |
211 | 220 | } |
| 221 | + static function randomchapter( &$parser, $text = null ) { |
| 222 | + $t = self::pageText( $parser, $text, 'rand' ); |
| 223 | + return $t; |
| 224 | + } |
| 225 | + static function randomchaptere( &$parser, $text = null ) { |
| 226 | + $t = self::pageText( $parser, $text, 'rand' ); |
| 227 | + return wfUrlEncode( $t ); |
| 228 | + } |
212 | 229 | |
213 | 230 | # Function for use with MW Variables on the current page |
214 | 231 | static function AssignAValue( &$parser, &$cache, &$magicWordId, &$ret ) { |
— | — | @@ -236,6 +253,13 @@ |
237 | 254 | case 'chapternamee': |
238 | 255 | $ret = BookManagerVariables::chapternamee( $parser ); |
239 | 256 | return true; |
| 257 | + case 'randomchapter': |
| 258 | + $ret = BookManagerVariables::randomchapter( $parser ); |
| 259 | + return true; |
| 260 | + case 'randomchaptere': |
| 261 | + $ret = BookManagerVariables::randomchaptere( $parser ); |
| 262 | + return true; |
| 263 | + |
240 | 264 | } |
241 | 265 | return false; |
242 | 266 | } |
— | — | @@ -360,6 +384,3 @@ |
361 | 385 | } |
362 | 386 | |
363 | 387 | } |
364 | | - |
365 | | - |
366 | | - |
Index: trunk/extensions/BookManager/BookManager.i18n.magic.php |
— | — | @@ -14,4 +14,6 @@ |
15 | 15 | 'rootpagenamee' => array( 0, 'ROOTPAGENAMEE', 'BOOKNAMEE' ), |
16 | 16 | 'chaptername' => array( 0, 'CHAPTERNAME' ), |
17 | 17 | 'chapternamee' => array( 0, 'CHAPTERNAMEE' ), |
| 18 | + 'randomchapter' => array( 0, 'RANDOMCHAPTER' ), |
| 19 | + 'randomchaptere' => array( 0, 'RANDOMCHAPTERE' ), |
18 | 20 | ); |
Index: trunk/extensions/BookManager/BookManager.php |
— | — | @@ -9,8 +9,10 @@ |
10 | 10 | * - NEXTPAGENAMEE (get next page encode) |
11 | 11 | * - ROOTPAGENAME (get root page) |
12 | 12 | * - ROOTPAGENAMEE (get root page encode) |
13 | | - * - CHAPTERNAME (get root page) |
14 | | - * - CHAPTERNAMEE (get root page encode) |
| 13 | + * - CHAPTERNAME (get chapter) |
| 14 | + * - CHAPTERNAMEE (get chapter encode) |
| 15 | + * - RANDOMCHAPTER (get random page) |
| 16 | + * - RANDOMCHAPTERE (get random page encode) |
15 | 17 | * @addtogroup Extensions |
16 | 18 | * @author Raylton P. Sousa <raylton.sousa@gmail.com> |
17 | 19 | * @author Helder.wiki |