Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php |
— | — | @@ -22,48 +22,24 @@ |
23 | 23 | |
24 | 24 | class ProofreadPage { |
25 | 25 | |
26 | | - /* Page and Index namespaces */ |
27 | | - var $page_namespace = null; |
28 | | - var $index_namespace = null; |
29 | | - |
30 | 26 | /* Parser object for index pages */ |
31 | | - var $index_parser = null; |
| 27 | + private static $index_parser = null; |
32 | 28 | |
33 | | - /** |
34 | | - * Constructor |
35 | | - */ |
36 | | - function __construct() { |
37 | | - global $wgHooks, $wgExtensionAssetsPath; |
38 | | - $wgHooks['ParserFirstCallInit'][] = array( $this, 'parserFirstCallInit' ); |
39 | | - $wgHooks['BeforePageDisplay'][] = array( &$this, 'beforePageDisplay' ); |
40 | | - $wgHooks['GetLinkColours'][] = array( &$this, 'getLinkColoursHook' ); |
41 | | - $wgHooks['ImageOpenShowImageInlineBefore'][] = array( &$this, 'imageMessage' ); |
42 | | - $wgHooks['EditPage::attemptSave'][] = array( &$this, 'attemptSave' ); |
43 | | - $wgHooks['ArticleSaveComplete'][] = array( &$this, 'articleSaveComplete' ); |
44 | | - $wgHooks['ArticleDelete'][] = array( &$this, 'articleDelete' ); |
45 | | - $wgHooks['EditFormPreloadText'][] = array( &$this, 'preloadText' ); |
46 | | - $wgHooks['ArticlePurge'][] = array( &$this, 'articlePurge' ); |
47 | | - $wgHooks['SpecialMovepageAfterMove'][] = array( &$this, 'movePage' ); |
48 | | - $wgHooks['LoadExtensionSchemaUpdates'][] = array( &$this, 'schema_update' ); |
49 | | - $wgHooks['EditPage::importFormData'][] = array( &$this, 'importFormData' ); |
50 | | - $wgHooks['OutputPageParserOutput'][] = array( &$this, 'OutputPageParserOutput' ); |
| 29 | + private static function getPageAndIndexNamespace() { |
| 30 | + static $res = null; |
| 31 | + if ( $res === null ) { |
| 32 | + $res = array( |
| 33 | + preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ), |
| 34 | + preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ), |
| 35 | + ); |
| 36 | + } |
| 37 | + return $res; |
| 38 | + } |
51 | 39 | |
52 | | - /* Namespaces */ |
53 | | - $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
54 | | - $this->index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
55 | | - |
56 | | - /* Navigation icons */ |
57 | | - $path = $wgExtensionAssetsPath . '/ProofreadPage'; |
58 | | - $this->prev_icon = Html::element( 'img', array( 'src' => $path . '/leftarrow.png', |
59 | | - 'alt' => wfMsg( 'proofreadpage_prevpage' ), |
60 | | - 'width' => 15, 'height' => 15 ) ); |
61 | | - $this->next_icon = Html::element( 'img', array( 'src' => $path . '/rightarrow.png', |
62 | | - 'alt' => wfMsg( 'proofreadpage_nextpage' ), |
63 | | - 'width' => 15, 'height' => 15 ) ); |
64 | | - $this->up_icon = Html::element( 'img', array( 'src' => $path . '/uparrow.png', |
65 | | - 'alt' => wfMsg( 'proofreadpage_index' ), |
66 | | - 'width' => 15, 'height' => 15 ) ); |
67 | | - |
| 40 | + public static function onwgQueryPages( &$queryPages ) { |
| 41 | + $queryPages[] = array( 'ProofreadPages', 'IndexPages' ); |
| 42 | + $queryPages[] = array( 'PagesWithoutScans', 'PagesWithoutScans' ); |
| 43 | + return true; |
68 | 44 | } |
69 | 45 | |
70 | 46 | /** |
— | — | @@ -72,14 +48,14 @@ |
73 | 49 | * @param Parser $parser |
74 | 50 | * @return boolean hook return value |
75 | 51 | */ |
76 | | - public function parserFirstCallInit( $parser ) { |
77 | | - $parser->setHook( 'pagelist', array( $this, 'renderPageList' ) ); |
78 | | - $parser->setHook( 'pages', array( $this, 'renderPages' ) ); |
79 | | - $parser->setHook( 'pagequality', array( $this, 'pageQuality' ) ); |
| 52 | + public static function onParserFirstCallInit( $parser ) { |
| 53 | + $parser->setHook( 'pagelist', array( __CLASS__, 'renderPageList' ) ); |
| 54 | + $parser->setHook( 'pages', array( __CLASS__, 'renderPages' ) ); |
| 55 | + $parser->setHook( 'pagequality', array( __CLASS__, 'pageQuality' ) ); |
80 | 56 | return true; |
81 | 57 | } |
82 | 58 | |
83 | | - function schema_update( $updater = null ) { |
| 59 | + public static function onLoadExtensionSchemaUpdates( $updater = null ) { |
84 | 60 | $base = dirname( __FILE__ ); |
85 | 61 | if ( $updater === null ) { |
86 | 62 | global $wgExtNewTables; |
— | — | @@ -94,9 +70,8 @@ |
95 | 71 | /** |
96 | 72 | * Query the database to find if the current page is referred in an Index page. |
97 | 73 | */ |
98 | | - function load_index( $title ) { |
99 | | - $page_namespace = $this->page_namespace; |
100 | | - $index_namespace = $this->index_namespace; |
| 74 | + private static function load_index( $title ) { |
| 75 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
101 | 76 | |
102 | 77 | $title->pr_index_title = null; |
103 | 78 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -149,8 +124,8 @@ |
150 | 125 | /** |
151 | 126 | * return the URLs of the index, previous and next pages. |
152 | 127 | */ |
153 | | - function navigation( $title ) { |
154 | | - $page_namespace = $this->page_namespace; |
| 128 | + private static function navigation( $title ) { |
| 129 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
155 | 130 | $default_header = wfMsgForContentNoTrans( 'proofreadpage_default_header' ); |
156 | 131 | $default_footer = wfMsgForContentNoTrans( 'proofreadpage_default_footer' ); |
157 | 132 | |
— | — | @@ -189,10 +164,10 @@ |
190 | 165 | } |
191 | 166 | |
192 | 167 | // if the index page exists, find current page number, previous and next pages |
193 | | - list( $links, $params, $attributes ) = $this->parse_index( $index_title ); |
| 168 | + list( $links, $params, $attributes ) = self::parse_index( $index_title ); |
194 | 169 | |
195 | 170 | if( $links == null ) { |
196 | | - list( $pagenum, $links, $mode ) = $this->pageNumber( $pagenr, $params ); |
| 171 | + list( $pagenum, $links, $mode ) = self::pageNumber( $pagenr, $params ); |
197 | 172 | $attributes['pagenum'] = $pagenum; |
198 | 173 | } else { |
199 | 174 | for( $i = 0; $i < count( $links[1] ); $i++ ) { |
— | — | @@ -233,7 +208,7 @@ |
234 | 209 | * it will return either a list of links or a list |
235 | 210 | * of parameters to pagelist, and a list of attributes. |
236 | 211 | */ |
237 | | - function parse_index( $index_title ) { |
| 212 | + private static function parse_index( $index_title ) { |
238 | 213 | $err = array( false, false, array() ); |
239 | 214 | if ( !$index_title ) { |
240 | 215 | return $err; |
— | — | @@ -243,12 +218,12 @@ |
244 | 219 | } |
245 | 220 | |
246 | 221 | $rev = Revision::newFromTitle( $index_title ); |
247 | | - $text = $rev->getText(); |
248 | | - return $this->parse_index_text( $text ); |
| 222 | + $text = $rev->getText(); |
| 223 | + return self::parse_index_text( $text ); |
249 | 224 | } |
250 | 225 | |
251 | | - function parse_index_text( $text ) { |
252 | | - $page_namespace = $this->page_namespace; |
| 226 | + private static function parse_index_text( $text ) { |
| 227 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
253 | 228 | //check if it is using pagelist |
254 | 229 | preg_match_all( "/<pagelist([^<]*?)\/>/is", $text, $m, PREG_PATTERN_ORDER ); |
255 | 230 | if( $m[1] ) { |
— | — | @@ -284,15 +259,15 @@ |
285 | 260 | /** |
286 | 261 | * Return the ordered list of links to ns-0 from an index page |
287 | 262 | */ |
288 | | - function parse_index_links( $index_title ) { |
| 263 | + private static function parse_index_links( $index_title ) { |
289 | 264 | // Instanciate a new parser object to avoid side effects of $parser->replaceVariables |
290 | | - if( is_null( $this->index_parser ) ) { |
291 | | - $this->index_parser = new Parser; |
| 265 | + if( is_null( self::$index_parser ) ) { |
| 266 | + self::$index_parser = new Parser; |
292 | 267 | } |
293 | 268 | $rev = Revision::newFromTitle( $index_title ); |
294 | 269 | $text = $rev->getText(); |
295 | 270 | $options = new ParserOptions(); |
296 | | - $rtext = $this->index_parser->preprocess( $text, $index_title, $options ); |
| 271 | + $rtext = self::$index_parser->preprocess( $text, $index_title, $options ); |
297 | 272 | $text_links_pattern = "/\[\[\s*([^:\|]*?)\s*(\|(.*?)|)\]\]/i"; |
298 | 273 | preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER ); |
299 | 274 | return $text_links; |
— | — | @@ -301,37 +276,37 @@ |
302 | 277 | /** |
303 | 278 | * Append javascript variables and code to the page. |
304 | 279 | */ |
305 | | - function beforePageDisplay( &$out ) { |
306 | | - global $wgTitle, $wgRequest; |
| 280 | + public static function onBeforePageDisplay( $out ) { |
| 281 | + global $wgRequest; |
307 | 282 | |
308 | 283 | $action = $wgRequest->getVal( 'action' ); |
309 | 284 | $isEdit = ( $action == 'submit' || $action == 'edit' ) ? 1 : 0; |
310 | | - if ( !isset( $wgTitle ) || ( !$out->isArticle() && !$isEdit ) || isset( $out->proofreadPageDone ) ) { |
| 285 | + if ( ( !$out->isArticle() && !$isEdit ) || isset( $out->proofreadPageDone ) ) { |
311 | 286 | return true; |
312 | 287 | } |
313 | 288 | $out->proofreadPageDone = true; |
314 | 289 | |
315 | | - $page_namespace = $this->page_namespace; |
316 | | - if ( preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) { |
317 | | - $this->preparePage( $out, $m, $isEdit ); |
| 290 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
| 291 | + |
| 292 | + if ( preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $out->getTitle()->getPrefixedText(), $m ) ) { |
| 293 | + self::preparePage( $out, $m, $isEdit ); |
318 | 294 | return true; |
319 | 295 | } |
320 | 296 | |
321 | | - $index_namespace = $this->index_namespace; |
322 | | - if ( $isEdit && ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) ) { |
323 | | - $this->prepareIndex( $out ); |
| 297 | + if ( $isEdit && ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $out->getTitle()->getPrefixedText(), $m ) ) ) { |
| 298 | + self::prepareIndex( $out ); |
324 | 299 | return true; |
325 | 300 | } |
326 | 301 | |
327 | | - if( $wgTitle->getNamespace() == NS_MAIN ) { |
328 | | - $this->prepareArticle( $out ); |
| 302 | + if( $out->getTitle()->getNamespace() == NS_MAIN ) { |
| 303 | + self::prepareArticle( $out ); |
329 | 304 | return true; |
330 | 305 | } |
331 | 306 | |
332 | 307 | return true; |
333 | 308 | } |
334 | 309 | |
335 | | - function prepareIndex( $out ) { |
| 310 | + private static function prepareIndex( $out ) { |
336 | 311 | $out->addModules( 'ext.proofreadpage.index' ); |
337 | 312 | $out->addInlineScript(" |
338 | 313 | var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\"; |
— | — | @@ -339,11 +314,11 @@ |
340 | 315 | var prp_default_footer = \"" . Xml::escapeJsString( wfMsgForContentNoTrans( 'proofreadpage_default_footer' ) ) . "\";" ); |
341 | 316 | } |
342 | 317 | |
343 | | - function preparePage( $out, $m, $isEdit ) { |
344 | | - global $wgTitle, $wgUser; |
| 318 | + private static function preparePage( $out, $m, $isEdit ) { |
| 319 | + global $wgUser, $wgExtensionAssetsPath; |
345 | 320 | |
346 | | - if ( !isset( $wgTitle->pr_index_title ) ) { |
347 | | - $this->load_index( $wgTitle ); |
| 321 | + if ( !isset( $out->getTitle()->pr_index_title ) ) { |
| 322 | + self::load_index( $out->getTitle() ); |
348 | 323 | } |
349 | 324 | |
350 | 325 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] ); |
— | — | @@ -378,16 +353,26 @@ |
379 | 354 | $scan_link = ''; |
380 | 355 | } |
381 | 356 | |
382 | | - list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle ); |
| 357 | + list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = self::navigation( $out->getTitle() ); |
383 | 358 | |
384 | 359 | $sk = $wgUser->getSkin(); |
385 | | - $next_link = $next_title ? $sk->link( $next_title, $this->next_icon, |
386 | | - array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : ''; |
387 | | - $prev_link = $prev_title ? $sk->link( $prev_title, $this->prev_icon, |
388 | | - array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): ''; |
389 | | - $index_link = $index_title ? $sk->link( $index_title, $this->up_icon, |
390 | | - array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : ''; |
| 360 | + $path = $wgExtensionAssetsPath . '/ProofreadPage'; |
391 | 361 | |
| 362 | + $next_link = $next_title ? $sk->link( $next_title, |
| 363 | + Html::element( 'img', array( 'src' => $path . '/rightarrow.png', |
| 364 | + 'alt' => wfMsg( 'proofreadpage_nextpage' ), 'width' => 15, 'height' => 15 ) ), |
| 365 | + array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : ''; |
| 366 | + |
| 367 | + $prev_link = $prev_title ? $sk->link( $prev_title, |
| 368 | + Html::element( 'img', array( 'src' => $path . '/leftarrow.png', |
| 369 | + 'alt' => wfMsg( 'proofreadpage_prevpage' ), 'width' => 15, 'height' => 15 ) ), |
| 370 | + array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): ''; |
| 371 | + |
| 372 | + $index_link = $index_title ? $sk->link( $index_title, |
| 373 | + Html::element( 'img', array( 'src' => $path . '/uparrow.png', |
| 374 | + 'alt' => wfMsg( 'proofreadpage_index' ), 'width' => 15, 'height' => 15 ) ), |
| 375 | + array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : ''; |
| 376 | + |
392 | 377 | $jsVars = array( |
393 | 378 | 'proofreadPageWidth' => intval( $width ), |
394 | 379 | 'proofreadPageHeight' => intval( $height ), |
— | — | @@ -415,25 +400,25 @@ |
416 | 401 | /** |
417 | 402 | * Hook function |
418 | 403 | */ |
419 | | - function getLinkColoursHook( $page_ids, &$colours ) { |
| 404 | + public static function onGetLinkColours( $page_ids, &$colours ) { |
420 | 405 | global $wgTitle; |
421 | 406 | if ( !isset( $wgTitle ) ) { |
422 | 407 | return true; |
423 | 408 | } |
424 | 409 | // abort if we are not an index page |
425 | | - $index_namespace = $this->index_namespace; |
| 410 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
426 | 411 | if ( !preg_match( "/^$index_namespace:(.*?)$/", $wgTitle->getPrefixedText(), $m ) ) { |
427 | | - return true; |
| 412 | + #return true; |
428 | 413 | } |
429 | | - $this->getLinkColours( $page_ids, $colours ); |
| 414 | + self::getLinkColours( $page_ids, $colours ); |
430 | 415 | return true; |
431 | 416 | } |
432 | 417 | |
433 | 418 | /** |
434 | 419 | * Return the quality colour codes to pages linked from an index page |
435 | 420 | */ |
436 | | - function getLinkColours( $page_ids, &$colours ) { |
437 | | - $page_namespace = $this->page_namespace; |
| 421 | + private static function getLinkColours( $page_ids, &$colours ) { |
| 422 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
438 | 423 | $dbr = wfGetDB( DB_SLAVE ); |
439 | 424 | $catlinks = $dbr->tableName( 'categorylinks' ); |
440 | 425 | |
— | — | @@ -477,8 +462,8 @@ |
478 | 463 | * @param $out OutputPage: |
479 | 464 | * @return bool |
480 | 465 | */ |
481 | | - function imageMessage( &$imgpage, &$out ) { |
482 | | - $index_namespace = $this->index_namespace; |
| 466 | + public static function onImageOpenShowImageInlineBefore( &$imgpage, &$out ) { |
| 467 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
483 | 468 | $image = $imgpage->getFile(); |
484 | 469 | if ( !$image->isMultipage() ) { |
485 | 470 | return true; |
— | — | @@ -491,7 +476,7 @@ |
492 | 477 | } |
493 | 478 | |
494 | 479 | // credit : http://www.mediawiki.org/wiki/Extension:RomanNumbers |
495 | | - function toRoman( $num ) { |
| 480 | + private static function toRoman( $num ) { |
496 | 481 | if ( $num < 0 || $num > 9999 ) { |
497 | 482 | return - 1; |
498 | 483 | } |
— | — | @@ -565,7 +550,7 @@ |
566 | 551 | return $romanNum; |
567 | 552 | } |
568 | 553 | |
569 | | - function pageNumber( $i, $args ) { |
| 554 | + private static function pageNumber( $i, $args ) { |
570 | 555 | $mode = 'normal'; // default |
571 | 556 | $offset = 0; |
572 | 557 | $links = true; |
— | — | @@ -605,10 +590,10 @@ |
606 | 591 | $view = ( $i - $offset ); |
607 | 592 | switch( $mode ) { |
608 | 593 | case 'highroman': |
609 | | - $view = $this->toRoman( $view ); |
| 594 | + $view = self::toRoman( $view ); |
610 | 595 | break; |
611 | 596 | case 'roman': |
612 | | - $view = strtolower( $this->toRoman( $view ) ); |
| 597 | + $view = strtolower( self::toRoman( $view ) ); |
613 | 598 | break; |
614 | 599 | case 'normal': |
615 | 600 | $view = '' . $view; |
— | — | @@ -626,8 +611,8 @@ |
627 | 612 | * Add the pagequality category. |
628 | 613 | * @todo FIXME: display whether page has been proofread by the user or by someone else |
629 | 614 | */ |
630 | | - function pageQuality( $input, $args, $parser ) { |
631 | | - $page_namespace = $this->page_namespace; |
| 615 | + public static function pageQuality( $input, $args, $parser ) { |
| 616 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
632 | 617 | if ( !preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText() ) ) { |
633 | 618 | return ''; |
634 | 619 | } |
— | — | @@ -647,9 +632,8 @@ |
648 | 633 | * Parser hook for index pages |
649 | 634 | * Display a list of coloured links to pages |
650 | 635 | */ |
651 | | - function renderPageList( $input, $args, $parser ) { |
652 | | - $page_namespace = $this->page_namespace; |
653 | | - $index_namespace = $this->index_namespace; |
| 636 | + public static function renderPageList( $input, $args, $parser ) { |
| 637 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
654 | 638 | if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText(), $m ) ) { |
655 | 639 | return ''; |
656 | 640 | } |
— | — | @@ -681,7 +665,7 @@ |
682 | 666 | |
683 | 667 | for ( $i = $from; $i < $to + 1; $i++ ) { |
684 | 668 | $pdbk = "$page_namespace:$name" . '/' . $i ; |
685 | | - list( $view, $links, $mode ) = $this->pageNumber( $i, $args ); |
| 669 | + list( $view, $links, $mode ) = self::pageNumber( $i, $args ); |
686 | 670 | |
687 | 671 | if ( $mode == 'highroman' || $mode == 'roman' ) { |
688 | 672 | $view = ' ' . $view; |
— | — | @@ -711,9 +695,8 @@ |
712 | 696 | * Parser hook that includes a list of pages. |
713 | 697 | * parameters : index, from, to, header |
714 | 698 | */ |
715 | | - function renderPages( $input, $args, $parser ) { |
716 | | - $page_namespace = $this->page_namespace; |
717 | | - $index_namespace = $this->index_namespace; |
| 699 | + public static function renderPages( $input, $args, $parser ) { |
| 700 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
718 | 701 | |
719 | 702 | $index = array_key_exists( 'index', $args ) ? $args['index'] : null; |
720 | 703 | $from = array_key_exists( 'from', $args ) ? $args['from'] : null; |
— | — | @@ -740,7 +723,7 @@ |
741 | 724 | |
742 | 725 | $out = ''; |
743 | 726 | |
744 | | - list( $links, $params, $attributes ) = $this->parse_index( $index_title ); |
| 727 | + list( $links, $params, $attributes ) = self::parse_index( $index_title ); |
745 | 728 | |
746 | 729 | if( $from || $to ) { |
747 | 730 | $pages = array(); |
— | — | @@ -773,7 +756,7 @@ |
774 | 757 | } |
775 | 758 | |
776 | 759 | for( $i = $from; $i <= $to; $i++ ) { |
777 | | - list( $pagenum, $links, $mode ) = $this->pageNumber( $i, $params ); |
| 760 | + list( $pagenum, $links, $mode ) = self::pageNumber( $i, $params ); |
778 | 761 | $page = str_replace( ' ' , '_', "$index/" . $i ); |
779 | 762 | if( $i == $from ) { |
780 | 763 | $from_page = $page; |
— | — | @@ -889,7 +872,7 @@ |
890 | 873 | if( $header == 'toc') { |
891 | 874 | $parser->getOutput()->is_toc = true; |
892 | 875 | } |
893 | | - $text_links = $this->parse_index_links( $index_title ); |
| 876 | + $text_links = self::parse_index_links( $index_title ); |
894 | 877 | $h_out = '{{:MediaWiki:Proofreadpage_header_template'; |
895 | 878 | $h_out .= "|value=$header"; |
896 | 879 | // find next and previous pages in list |
— | — | @@ -948,7 +931,7 @@ |
949 | 932 | /** |
950 | 933 | * Set is_toc flag (true if page is a table of contents) |
951 | 934 | */ |
952 | | - function OutputPageParserOutput( $outputPage, $parserOutput ) { |
| 935 | + public static function onOutputPageParserOutput( $outputPage, $parserOutput ) { |
953 | 936 | if( isset( $parserOutput->is_toc ) ) { |
954 | 937 | $outputPage->is_toc = $parserOutput->is_toc; |
955 | 938 | } else { |
— | — | @@ -962,14 +945,14 @@ |
963 | 946 | * Return quality status of the page and username of the proofreader |
964 | 947 | * Return -1 if the page cannot be parsed |
965 | 948 | */ |
966 | | - function parse_page( $text ) { |
967 | | - global $wgTitle, $wgUser; |
| 949 | + private static function parse_page( $text, $title ) { |
| 950 | + global $wgUser; |
968 | 951 | |
969 | 952 | $username = $wgUser->getName(); |
970 | 953 | $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s"; |
971 | 954 | if( !preg_match( $page_regexp, $text, $m ) ) { |
972 | | - $this->load_index( $wgTitle ); |
973 | | - list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle ); |
| 955 | + self::load_index( $title ); |
| 956 | + list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = self::navigation( $title ); |
974 | 957 | $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" /><div class=\"pagetext\">" |
975 | 958 | ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</div></noinclude>"; |
976 | 959 | return array( -1, null, $new_text ); |
— | — | @@ -994,12 +977,11 @@ |
995 | 978 | return array( -1, null, $new_text ); |
996 | 979 | } |
997 | 980 | |
998 | | - function importFormData( $editpage, $request ) { |
999 | | - global $wgTitle; |
1000 | | - |
1001 | | - $page_namespace = $this->page_namespace; |
| 981 | + public static function onEditPageImportFormData( $editpage, $request ) { |
| 982 | + $title = $editpage->mTitle; |
| 983 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1002 | 984 | // abort if we are not a page |
1003 | | - if ( !preg_match( "/^$page_namespace:(.*)$/", $wgTitle->getPrefixedText() ) ) { |
| 985 | + if ( !preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
1004 | 986 | return true; |
1005 | 987 | } |
1006 | 988 | if ( !$request->wasPosted() ) { |
— | — | @@ -1042,17 +1024,16 @@ |
1043 | 1025 | * @param $editpage Object: EditPage object |
1044 | 1026 | * @return Boolean |
1045 | 1027 | */ |
1046 | | - function attemptSave( $editpage ) { |
| 1028 | + public static function onEditPageAttemptSave( $editpage ) { |
1047 | 1029 | global $wgOut, $wgUser; |
1048 | 1030 | |
1049 | | - $page_namespace = $this->page_namespace; |
1050 | | - $index_namespace = $this->index_namespace; |
| 1031 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1051 | 1032 | $title = $editpage->mTitle; |
1052 | 1033 | |
1053 | 1034 | // check that pages listed on an index are unique. |
1054 | 1035 | if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
1055 | 1036 | $text = $editpage->textbox1; |
1056 | | - list( $links, $params, $attributes ) = $this->parse_index_text( $text ); |
| 1037 | + list( $links, $params, $attributes ) = self::parse_index_text( $text ); |
1057 | 1038 | if( $links != null && count( $links[1] ) != count( array_unique( $links[1] ) ) ) { |
1058 | 1039 | $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' ); |
1059 | 1040 | return false; |
— | — | @@ -1067,7 +1048,7 @@ |
1068 | 1049 | |
1069 | 1050 | $text = $editpage->textbox1; |
1070 | 1051 | // parse the page |
1071 | | - list( $q, $username, $ptext ) = $this->parse_page( $text ); |
| 1052 | + list( $q, $username, $ptext ) = self::parse_page( $text, $title ); |
1072 | 1053 | if( $q == -1 ) { |
1073 | 1054 | $editpage->textbox1 = $ptext; |
1074 | 1055 | $q = 1; |
— | — | @@ -1077,7 +1058,7 @@ |
1078 | 1059 | $rev = Revision::newFromTitle( $title ); |
1079 | 1060 | if( $rev ) { |
1080 | 1061 | $old_text = $rev->getText(); |
1081 | | - list( $old_q, $old_username, $old_ptext ) = $this->parse_page( $old_text ); |
| 1062 | + list( $old_q, $old_username, $old_ptext ) = self::parse_page( $old_text, $title ); |
1082 | 1063 | if( $old_q != -1 ) { |
1083 | 1064 | // check usernames |
1084 | 1065 | if( ( $old_q != $q ) && !$wgUser->isAllowed( 'pagequality' ) ) { |
— | — | @@ -1116,10 +1097,9 @@ |
1117 | 1098 | * @param $article Object: Article object |
1118 | 1099 | * @return Boolean: true |
1119 | 1100 | */ |
1120 | | - function articleDelete( $article ) { |
1121 | | - $page_namespace = $this->page_namespace; |
1122 | | - $index_namespace = $this->index_namespace; |
1123 | | - $title = $article->mTitle; |
| 1101 | + public static function onArticleDelete( $article ) { |
| 1102 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
| 1103 | + $title = $article->getTitle(); |
1124 | 1104 | |
1125 | 1105 | if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
1126 | 1106 | $id = $article->getID(); |
— | — | @@ -1131,13 +1111,13 @@ |
1132 | 1112 | } |
1133 | 1113 | |
1134 | 1114 | if ( preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
1135 | | - $this->load_index( $title ); |
| 1115 | + self::load_index( $title ); |
1136 | 1116 | if( $title->pr_index_title ) { |
1137 | 1117 | $index_title = Title::newFromText( $title->pr_index_title ); |
1138 | 1118 | $index_title->invalidateCache(); |
1139 | 1119 | $index = new Article( $index_title ); |
1140 | 1120 | if( $index ) { |
1141 | | - $this->update_pr_index( $index, $title->getDBKey() ); |
| 1121 | + self::update_pr_index( $index, $title->getDBKey() ); |
1142 | 1122 | } |
1143 | 1123 | } |
1144 | 1124 | return true; |
— | — | @@ -1146,14 +1126,13 @@ |
1147 | 1127 | return true; |
1148 | 1128 | } |
1149 | 1129 | |
1150 | | - function articleSaveComplete( $article ) { |
1151 | | - $page_namespace = $this->page_namespace; |
1152 | | - $index_namespace = $this->index_namespace; |
| 1130 | + public static function onArticleSaveComplete( $article ) { |
| 1131 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1153 | 1132 | $title = $article->mTitle; |
1154 | 1133 | |
1155 | 1134 | // if it's an index, update pr_index table |
1156 | 1135 | if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText(), $m ) ) { |
1157 | | - $this->update_pr_index( $article ); |
| 1136 | + self::update_pr_index( $article ); |
1158 | 1137 | return true; |
1159 | 1138 | } |
1160 | 1139 | |
— | — | @@ -1166,7 +1145,7 @@ |
1167 | 1146 | |
1168 | 1147 | /* check if there is an index */ |
1169 | 1148 | if ( !isset( $title->pr_index_title ) ) { |
1170 | | - $this->load_index( $title ); |
| 1149 | + self::load_index( $title ); |
1171 | 1150 | } |
1172 | 1151 | if( ! $title->pr_index_title ) { |
1173 | 1152 | return true; |
— | — | @@ -1245,8 +1224,8 @@ |
1246 | 1225 | } |
1247 | 1226 | |
1248 | 1227 | /* Preload text layer from multipage formats */ |
1249 | | - function preloadText( $textbox1, $mTitle ) { |
1250 | | - $page_namespace = $this->page_namespace; |
| 1228 | + public static function onEditFormPreloadText( $textbox1, $mTitle ) { |
| 1229 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1251 | 1230 | if ( preg_match( "/^$page_namespace:(.*?)\/([0-9]*)$/", $mTitle->getPrefixedText(), $m ) ) { |
1252 | 1231 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] ); |
1253 | 1232 | if ( !$imageTitle ) { |
— | — | @@ -1266,29 +1245,29 @@ |
1267 | 1246 | return true; |
1268 | 1247 | } |
1269 | 1248 | |
1270 | | - function movePage( $form, $ot, $nt ) { |
1271 | | - $page_namespace = $this->page_namespace; |
| 1249 | + public static function onSpecialMovepageAfterMove( $form, $ot, $nt ) { |
| 1250 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1272 | 1251 | if ( preg_match( "/^$page_namespace:(.*)$/", $ot->getPrefixedText() ) ) { |
1273 | | - $this->load_index( $ot ); |
| 1252 | + self::load_index( $ot ); |
1274 | 1253 | if( $ot->pr_index_title ) { |
1275 | 1254 | $index_title = Title::newFromText( $ot->pr_index_title ); |
1276 | 1255 | $index_title->invalidateCache(); |
1277 | 1256 | $index = new Article( $index_title ); |
1278 | 1257 | if( $index ) { |
1279 | | - $this->update_pr_index( $index ); |
| 1258 | + self::update_pr_index( $index ); |
1280 | 1259 | } |
1281 | 1260 | } |
1282 | 1261 | return true; |
1283 | 1262 | } |
1284 | 1263 | |
1285 | 1264 | if ( preg_match( "/^$page_namespace:(.*)$/", $nt->getPrefixedText() ) ) { |
1286 | | - $this->load_index( $nt ); |
| 1265 | + self::load_index( $nt ); |
1287 | 1266 | if( $nt->pr_index_title && ( $nt->pr_index_title != $ot->pr_index_title ) ) { |
1288 | 1267 | $index_title = Title::newFromText( $nt->pr_index_title ); |
1289 | 1268 | $index_title->invalidateCache(); |
1290 | 1269 | $index = new Article( $index_title ); |
1291 | 1270 | if( $index ) { |
1292 | | - $this->update_pr_index( $index ); |
| 1271 | + self::update_pr_index( $index ); |
1293 | 1272 | } |
1294 | 1273 | } |
1295 | 1274 | return true; |
— | — | @@ -1299,11 +1278,11 @@ |
1300 | 1279 | /** |
1301 | 1280 | * When an index page is created or purged, recompute pr_index values |
1302 | 1281 | */ |
1303 | | - function articlePurge( $article ) { |
1304 | | - $index_namespace = $this->index_namespace; |
1305 | | - $title = $article->mTitle; |
| 1282 | + public static function onArticlePurge( $article ) { |
| 1283 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
| 1284 | + $title = $article->getTitle(); |
1306 | 1285 | if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
1307 | | - $this->update_pr_index( $article ); |
| 1286 | + self::update_pr_index( $article ); |
1308 | 1287 | return true; |
1309 | 1288 | } |
1310 | 1289 | return true; |
— | — | @@ -1315,7 +1294,7 @@ |
1316 | 1295 | * @param $cat |
1317 | 1296 | * @return int |
1318 | 1297 | */ |
1319 | | - function query_count( $dbr, $query, $cat ) { |
| 1298 | + private static function query_count( $dbr, $query, $cat ) { |
1320 | 1299 | $query['conds']['cl_to'] = str_replace( ' ' , '_' , wfMsgForContent( $cat ) ); |
1321 | 1300 | $res = $dbr->select( $query['tables'], $query['fields'], $query['conds'], __METHOD__, array(), $query['joins'] ); |
1322 | 1301 | |
— | — | @@ -1331,8 +1310,8 @@ |
1332 | 1311 | /** |
1333 | 1312 | * Update the pr_index entry of an article |
1334 | 1313 | */ |
1335 | | - function update_pr_index( $index, $deletedpage = null ) { |
1336 | | - $page_namespace = $this->page_namespace; |
| 1314 | + private static function update_pr_index( $index, $deletedpage = null ) { |
| 1315 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1337 | 1316 | $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
1338 | 1317 | if ( $page_ns_index == null ) { |
1339 | 1318 | return; |
— | — | @@ -1346,7 +1325,7 @@ |
1347 | 1326 | |
1348 | 1327 | // read the list of pages |
1349 | 1328 | $pages = array(); |
1350 | | - list( $links, $params, $attributes ) = $this->parse_index( $index_title ); |
| 1329 | + list( $links, $params, $attributes ) = self::parse_index( $index_title ); |
1351 | 1330 | if( $links == null ) { |
1352 | 1331 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index_title->getText() ); |
1353 | 1332 | if ( $imageTitle ) { |
— | — | @@ -1398,10 +1377,10 @@ |
1399 | 1378 | 'joins' => array( 'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ) ) |
1400 | 1379 | ); |
1401 | 1380 | |
1402 | | - $n0 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' ); |
1403 | | - $n2 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' ); |
1404 | | - $n3 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' ); |
1405 | | - $n4 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' ); |
| 1381 | + $n0 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' ); |
| 1382 | + $n2 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' ); |
| 1383 | + $n3 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' ); |
| 1384 | + $n4 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' ); |
1406 | 1385 | $n1 = $total - $n0 - $n2 - $n3 - $n4; |
1407 | 1386 | |
1408 | 1387 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -1416,15 +1395,14 @@ |
1417 | 1396 | * |
1418 | 1397 | * @param $out Object: OutputPage object |
1419 | 1398 | */ |
1420 | | - function prepareArticle( $out ) { |
1421 | | - global $wgTitle, $wgUser; |
| 1399 | + private static function prepareArticle( $out ) { |
| 1400 | + global $wgUser; |
1422 | 1401 | |
1423 | | - $id = $wgTitle->mArticleID; |
| 1402 | + $id = $out->getTitle()->mArticleID; |
1424 | 1403 | if( $id == -1 ) { |
1425 | 1404 | return true; |
1426 | 1405 | } |
1427 | | - $page_namespace = $this->page_namespace; |
1428 | | - $index_namespace = $this->index_namespace; |
| 1406 | + list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace(); |
1429 | 1407 | $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
1430 | 1408 | $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) ); |
1431 | 1409 | if( $page_ns_index == null || $index_ns_index == null ) { |
— | — | @@ -1512,10 +1490,10 @@ |
1513 | 1491 | ) |
1514 | 1492 | ); |
1515 | 1493 | |
1516 | | - $n0 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' ); |
1517 | | - $n2 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' ); |
1518 | | - $n3 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' ); |
1519 | | - $n4 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' ); |
| 1494 | + $n0 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' ); |
| 1495 | + $n2 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' ); |
| 1496 | + $n3 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' ); |
| 1497 | + $n4 = self::query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' ); |
1520 | 1498 | // quality1 is the default value |
1521 | 1499 | $n1 = $n - $n0 - $n2 - $n3 - $n4; |
1522 | 1500 | $ne = 0; |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -19,9 +19,6 @@ |
20 | 20 | die( "ProofreadPage extension\n" ); |
21 | 21 | } |
22 | 22 | |
23 | | -$wgExtensionFunctions[] = 'wfProofreadPage'; |
24 | | -$wgRunHooks['wgQueryPages'][] = 'wfProofreadPageAddQueryPages'; |
25 | | - |
26 | 23 | $dir = dirname( __FILE__ ) . '/'; |
27 | 24 | $wgExtensionMessagesFiles['ProofreadPage'] = $dir . 'ProofreadPage.i18n.php'; |
28 | 25 | $wgExtensionAliasesFiles['ProofreadPage'] = $dir . 'ProofreadPage.alias.php'; |
— | — | @@ -46,15 +43,6 @@ |
47 | 44 | $wgAutoloadClasses['PagesWithoutScans'] = $dir . 'SpecialPagesWithoutScans.php'; |
48 | 45 | $wgSpecialPages['PagesWithoutScans'] = 'PagesWithoutScans'; |
49 | 46 | $wgSpecialPageGroups['PagesWithoutScans'] = 'maintenance'; |
50 | | -# for maintenance/updateSpecialPages.php |
51 | | -$wgHooks['wgQueryPages'][] = 'wfPagesWithoutScan'; |
52 | | -function wfPagesWithoutScan( &$QueryPages ) { |
53 | | - $QueryPages[] = array( |
54 | | - 'PagesWithoutScans', |
55 | | - 'PagesWithoutScans' |
56 | | - ); |
57 | | - return true; |
58 | | -} |
59 | 47 | |
60 | 48 | # Group allowed to modify pagequality |
61 | 49 | $wgGroupPermissions['user']['pagequality'] = true; |
— | — | @@ -96,13 +84,18 @@ |
97 | 85 | ), |
98 | 86 | ); |
99 | 87 | |
100 | | -function wfProofreadPage() { |
101 | | - new ProofreadPage; |
102 | | - return true; |
103 | | -} |
| 88 | +$wgHooks['ParserFirstCallInit'][] = 'ProofreadPage::onParserFirstCallInit'; |
| 89 | +$wgHooks['BeforePageDisplay'][] = 'ProofreadPage::onBeforePageDisplay'; |
| 90 | +$wgHooks['GetLinkColours'][] = 'ProofreadPage::onGetLinkColours'; |
| 91 | +$wgHooks['ImageOpenShowImageInlineBefore'][] = 'ProofreadPage::onImageOpenShowImageInlineBefore'; |
| 92 | +$wgHooks['EditPage::attemptSave'][] = 'ProofreadPage::onEditPageAttemptSave'; |
| 93 | +$wgHooks['ArticleSaveComplete'][] = 'ProofreadPage::onArticleSaveComplete'; |
| 94 | +$wgHooks['ArticleDelete'][] = 'ProofreadPage::onArticleDelete'; |
| 95 | +$wgHooks['EditFormPreloadText'][] = 'ProofreadPage::onEditFormPreloadText'; |
| 96 | +$wgHooks['ArticlePurge'][] = 'ProofreadPage::onArticlePurge'; |
| 97 | +$wgHooks['SpecialMovepageAfterMove'][] = 'ProofreadPage::onSpecialMovepageAfterMove'; |
| 98 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'ProofreadPage::onLoadExtensionSchemaUpdates'; |
| 99 | +$wgHooks['EditPage::importFormData'][] = 'ProofreadPage::onEditPageImportFormData'; |
| 100 | +$wgHooks['OutputPageParserOutput'][] = 'ProofreadPage::onOutputPageParserOutput'; |
| 101 | +$wgHooks['wgQueryPages'][] = 'ProofreadPage::onwgQueryPages'; |
104 | 102 | |
105 | | -function wfProofreadPageAddQueryPages( &$wgQueryPages ) { |
106 | | - $wgQueryPages[] = array( 'ProofreadPages', 'IndexPages' ); |
107 | | - $wgQueryPages[] = array( 'PagesWithoutScans', 'PagesWithoutScans' ); |
108 | | - return true; |
109 | | -} |