r93993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93992‎ | r93993 | r93994 >
Date:20:10, 5 August 2011
Author:ialex
Status:ok (Comments)
Tags:todo 
Comment:
* Removed useless extension function; made all ProofreadPage members static and defined hook directly while including the file
* Removed duplicate declaration of wgQueryPages hook (one with the wrong variable name) and moved the callback to the ProofreadPage class as for other hooks
* Removed usage of $wgTitle where possible
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -22,48 +22,24 @@
2323
2424 class ProofreadPage {
2525
26 - /* Page and Index namespaces */
27 - var $page_namespace = null;
28 - var $index_namespace = null;
29 -
3026 /* Parser object for index pages */
31 - var $index_parser = null;
 27+ private static $index_parser = null;
3228
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+ }
5139
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;
6844 }
6945
7046 /**
@@ -72,14 +48,14 @@
7349 * @param Parser $parser
7450 * @return boolean hook return value
7551 */
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' ) );
8056 return true;
8157 }
8258
83 - function schema_update( $updater = null ) {
 59+ public static function onLoadExtensionSchemaUpdates( $updater = null ) {
8460 $base = dirname( __FILE__ );
8561 if ( $updater === null ) {
8662 global $wgExtNewTables;
@@ -94,9 +70,8 @@
9571 /**
9672 * Query the database to find if the current page is referred in an Index page.
9773 */
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();
10176
10277 $title->pr_index_title = null;
10378 $dbr = wfGetDB( DB_SLAVE );
@@ -149,8 +124,8 @@
150125 /**
151126 * return the URLs of the index, previous and next pages.
152127 */
153 - function navigation( $title ) {
154 - $page_namespace = $this->page_namespace;
 128+ private static function navigation( $title ) {
 129+ list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace();
155130 $default_header = wfMsgForContentNoTrans( 'proofreadpage_default_header' );
156131 $default_footer = wfMsgForContentNoTrans( 'proofreadpage_default_footer' );
157132
@@ -189,10 +164,10 @@
190165 }
191166
192167 // 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 );
194169
195170 if( $links == null ) {
196 - list( $pagenum, $links, $mode ) = $this->pageNumber( $pagenr, $params );
 171+ list( $pagenum, $links, $mode ) = self::pageNumber( $pagenr, $params );
197172 $attributes['pagenum'] = $pagenum;
198173 } else {
199174 for( $i = 0; $i < count( $links[1] ); $i++ ) {
@@ -233,7 +208,7 @@
234209 * it will return either a list of links or a list
235210 * of parameters to pagelist, and a list of attributes.
236211 */
237 - function parse_index( $index_title ) {
 212+ private static function parse_index( $index_title ) {
238213 $err = array( false, false, array() );
239214 if ( !$index_title ) {
240215 return $err;
@@ -243,12 +218,12 @@
244219 }
245220
246221 $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 );
249224 }
250225
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();
253228 //check if it is using pagelist
254229 preg_match_all( "/<pagelist([^<]*?)\/>/is", $text, $m, PREG_PATTERN_ORDER );
255230 if( $m[1] ) {
@@ -284,15 +259,15 @@
285260 /**
286261 * Return the ordered list of links to ns-0 from an index page
287262 */
288 - function parse_index_links( $index_title ) {
 263+ private static function parse_index_links( $index_title ) {
289264 // 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;
292267 }
293268 $rev = Revision::newFromTitle( $index_title );
294269 $text = $rev->getText();
295270 $options = new ParserOptions();
296 - $rtext = $this->index_parser->preprocess( $text, $index_title, $options );
 271+ $rtext = self::$index_parser->preprocess( $text, $index_title, $options );
297272 $text_links_pattern = "/\[\[\s*([^:\|]*?)\s*(\|(.*?)|)\]\]/i";
298273 preg_match_all( $text_links_pattern, $rtext, $text_links, PREG_PATTERN_ORDER );
299274 return $text_links;
@@ -301,37 +276,37 @@
302277 /**
303278 * Append javascript variables and code to the page.
304279 */
305 - function beforePageDisplay( &$out ) {
306 - global $wgTitle, $wgRequest;
 280+ public static function onBeforePageDisplay( $out ) {
 281+ global $wgRequest;
307282
308283 $action = $wgRequest->getVal( 'action' );
309284 $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 ) ) {
311286 return true;
312287 }
313288 $out->proofreadPageDone = true;
314289
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 );
318294 return true;
319295 }
320296
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 );
324299 return true;
325300 }
326301
327 - if( $wgTitle->getNamespace() == NS_MAIN ) {
328 - $this->prepareArticle( $out );
 302+ if( $out->getTitle()->getNamespace() == NS_MAIN ) {
 303+ self::prepareArticle( $out );
329304 return true;
330305 }
331306
332307 return true;
333308 }
334309
335 - function prepareIndex( $out ) {
 310+ private static function prepareIndex( $out ) {
336311 $out->addModules( 'ext.proofreadpage.index' );
337312 $out->addInlineScript("
338313 var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\";
@@ -339,11 +314,11 @@
340315 var prp_default_footer = \"" . Xml::escapeJsString( wfMsgForContentNoTrans( 'proofreadpage_default_footer' ) ) . "\";" );
341316 }
342317
343 - function preparePage( $out, $m, $isEdit ) {
344 - global $wgTitle, $wgUser;
 318+ private static function preparePage( $out, $m, $isEdit ) {
 319+ global $wgUser, $wgExtensionAssetsPath;
345320
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() );
348323 }
349324
350325 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
@@ -378,16 +353,26 @@
379354 $scan_link = '';
380355 }
381356
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() );
383358
384359 $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';
391361
 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+
392377 $jsVars = array(
393378 'proofreadPageWidth' => intval( $width ),
394379 'proofreadPageHeight' => intval( $height ),
@@ -415,25 +400,25 @@
416401 /**
417402 * Hook function
418403 */
419 - function getLinkColoursHook( $page_ids, &$colours ) {
 404+ public static function onGetLinkColours( $page_ids, &$colours ) {
420405 global $wgTitle;
421406 if ( !isset( $wgTitle ) ) {
422407 return true;
423408 }
424409 // abort if we are not an index page
425 - $index_namespace = $this->index_namespace;
 410+ list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace();
426411 if ( !preg_match( "/^$index_namespace:(.*?)$/", $wgTitle->getPrefixedText(), $m ) ) {
427 - return true;
 412+ #return true;
428413 }
429 - $this->getLinkColours( $page_ids, $colours );
 414+ self::getLinkColours( $page_ids, $colours );
430415 return true;
431416 }
432417
433418 /**
434419 * Return the quality colour codes to pages linked from an index page
435420 */
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();
438423 $dbr = wfGetDB( DB_SLAVE );
439424 $catlinks = $dbr->tableName( 'categorylinks' );
440425
@@ -477,8 +462,8 @@
478463 * @param $out OutputPage:
479464 * @return bool
480465 */
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();
483468 $image = $imgpage->getFile();
484469 if ( !$image->isMultipage() ) {
485470 return true;
@@ -491,7 +476,7 @@
492477 }
493478
494479 // credit : http://www.mediawiki.org/wiki/Extension:RomanNumbers
495 - function toRoman( $num ) {
 480+ private static function toRoman( $num ) {
496481 if ( $num < 0 || $num > 9999 ) {
497482 return - 1;
498483 }
@@ -565,7 +550,7 @@
566551 return $romanNum;
567552 }
568553
569 - function pageNumber( $i, $args ) {
 554+ private static function pageNumber( $i, $args ) {
570555 $mode = 'normal'; // default
571556 $offset = 0;
572557 $links = true;
@@ -605,10 +590,10 @@
606591 $view = ( $i - $offset );
607592 switch( $mode ) {
608593 case 'highroman':
609 - $view = $this->toRoman( $view );
 594+ $view = self::toRoman( $view );
610595 break;
611596 case 'roman':
612 - $view = strtolower( $this->toRoman( $view ) );
 597+ $view = strtolower( self::toRoman( $view ) );
613598 break;
614599 case 'normal':
615600 $view = '' . $view;
@@ -626,8 +611,8 @@
627612 * Add the pagequality category.
628613 * @todo FIXME: display whether page has been proofread by the user or by someone else
629614 */
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();
632617 if ( !preg_match( "/^$page_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText() ) ) {
633618 return '';
634619 }
@@ -647,9 +632,8 @@
648633 * Parser hook for index pages
649634 * Display a list of coloured links to pages
650635 */
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();
654638 if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $parser->Title()->getPrefixedText(), $m ) ) {
655639 return '';
656640 }
@@ -681,7 +665,7 @@
682666
683667 for ( $i = $from; $i < $to + 1; $i++ ) {
684668 $pdbk = "$page_namespace:$name" . '/' . $i ;
685 - list( $view, $links, $mode ) = $this->pageNumber( $i, $args );
 669+ list( $view, $links, $mode ) = self::pageNumber( $i, $args );
686670
687671 if ( $mode == 'highroman' || $mode == 'roman' ) {
688672 $view = '&#160;' . $view;
@@ -711,9 +695,8 @@
712696 * Parser hook that includes a list of pages.
713697 * parameters : index, from, to, header
714698 */
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();
718701
719702 $index = array_key_exists( 'index', $args ) ? $args['index'] : null;
720703 $from = array_key_exists( 'from', $args ) ? $args['from'] : null;
@@ -740,7 +723,7 @@
741724
742725 $out = '';
743726
744 - list( $links, $params, $attributes ) = $this->parse_index( $index_title );
 727+ list( $links, $params, $attributes ) = self::parse_index( $index_title );
745728
746729 if( $from || $to ) {
747730 $pages = array();
@@ -773,7 +756,7 @@
774757 }
775758
776759 for( $i = $from; $i <= $to; $i++ ) {
777 - list( $pagenum, $links, $mode ) = $this->pageNumber( $i, $params );
 760+ list( $pagenum, $links, $mode ) = self::pageNumber( $i, $params );
778761 $page = str_replace( ' ' , '_', "$index/" . $i );
779762 if( $i == $from ) {
780763 $from_page = $page;
@@ -889,7 +872,7 @@
890873 if( $header == 'toc') {
891874 $parser->getOutput()->is_toc = true;
892875 }
893 - $text_links = $this->parse_index_links( $index_title );
 876+ $text_links = self::parse_index_links( $index_title );
894877 $h_out = '{{:MediaWiki:Proofreadpage_header_template';
895878 $h_out .= "|value=$header";
896879 // find next and previous pages in list
@@ -948,7 +931,7 @@
949932 /**
950933 * Set is_toc flag (true if page is a table of contents)
951934 */
952 - function OutputPageParserOutput( $outputPage, $parserOutput ) {
 935+ public static function onOutputPageParserOutput( $outputPage, $parserOutput ) {
953936 if( isset( $parserOutput->is_toc ) ) {
954937 $outputPage->is_toc = $parserOutput->is_toc;
955938 } else {
@@ -962,14 +945,14 @@
963946 * Return quality status of the page and username of the proofreader
964947 * Return -1 if the page cannot be parsed
965948 */
966 - function parse_page( $text ) {
967 - global $wgTitle, $wgUser;
 949+ private static function parse_page( $text, $title ) {
 950+ global $wgUser;
968951
969952 $username = $wgUser->getName();
970953 $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s";
971954 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 );
974957 $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" /><div class=\"pagetext\">"
975958 ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</div></noinclude>";
976959 return array( -1, null, $new_text );
@@ -994,12 +977,11 @@
995978 return array( -1, null, $new_text );
996979 }
997980
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();
1002984 // abort if we are not a page
1003 - if ( !preg_match( "/^$page_namespace:(.*)$/", $wgTitle->getPrefixedText() ) ) {
 985+ if ( !preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) {
1004986 return true;
1005987 }
1006988 if ( !$request->wasPosted() ) {
@@ -1042,17 +1024,16 @@
10431025 * @param $editpage Object: EditPage object
10441026 * @return Boolean
10451027 */
1046 - function attemptSave( $editpage ) {
 1028+ public static function onEditPageAttemptSave( $editpage ) {
10471029 global $wgOut, $wgUser;
10481030
1049 - $page_namespace = $this->page_namespace;
1050 - $index_namespace = $this->index_namespace;
 1031+ list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace();
10511032 $title = $editpage->mTitle;
10521033
10531034 // check that pages listed on an index are unique.
10541035 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
10551036 $text = $editpage->textbox1;
1056 - list( $links, $params, $attributes ) = $this->parse_index_text( $text );
 1037+ list( $links, $params, $attributes ) = self::parse_index_text( $text );
10571038 if( $links != null && count( $links[1] ) != count( array_unique( $links[1] ) ) ) {
10581039 $wgOut->showErrorPage( 'proofreadpage_indexdupe', 'proofreadpage_indexdupetext' );
10591040 return false;
@@ -1067,7 +1048,7 @@
10681049
10691050 $text = $editpage->textbox1;
10701051 // parse the page
1071 - list( $q, $username, $ptext ) = $this->parse_page( $text );
 1052+ list( $q, $username, $ptext ) = self::parse_page( $text, $title );
10721053 if( $q == -1 ) {
10731054 $editpage->textbox1 = $ptext;
10741055 $q = 1;
@@ -1077,7 +1058,7 @@
10781059 $rev = Revision::newFromTitle( $title );
10791060 if( $rev ) {
10801061 $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 );
10821063 if( $old_q != -1 ) {
10831064 // check usernames
10841065 if( ( $old_q != $q ) && !$wgUser->isAllowed( 'pagequality' ) ) {
@@ -1116,10 +1097,9 @@
11171098 * @param $article Object: Article object
11181099 * @return Boolean: true
11191100 */
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();
11241104
11251105 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
11261106 $id = $article->getID();
@@ -1131,13 +1111,13 @@
11321112 }
11331113
11341114 if ( preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) {
1135 - $this->load_index( $title );
 1115+ self::load_index( $title );
11361116 if( $title->pr_index_title ) {
11371117 $index_title = Title::newFromText( $title->pr_index_title );
11381118 $index_title->invalidateCache();
11391119 $index = new Article( $index_title );
11401120 if( $index ) {
1141 - $this->update_pr_index( $index, $title->getDBKey() );
 1121+ self::update_pr_index( $index, $title->getDBKey() );
11421122 }
11431123 }
11441124 return true;
@@ -1146,14 +1126,13 @@
11471127 return true;
11481128 }
11491129
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();
11531132 $title = $article->mTitle;
11541133
11551134 // if it's an index, update pr_index table
11561135 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText(), $m ) ) {
1157 - $this->update_pr_index( $article );
 1136+ self::update_pr_index( $article );
11581137 return true;
11591138 }
11601139
@@ -1166,7 +1145,7 @@
11671146
11681147 /* check if there is an index */
11691148 if ( !isset( $title->pr_index_title ) ) {
1170 - $this->load_index( $title );
 1149+ self::load_index( $title );
11711150 }
11721151 if( ! $title->pr_index_title ) {
11731152 return true;
@@ -1245,8 +1224,8 @@
12461225 }
12471226
12481227 /* 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();
12511230 if ( preg_match( "/^$page_namespace:(.*?)\/([0-9]*)$/", $mTitle->getPrefixedText(), $m ) ) {
12521231 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
12531232 if ( !$imageTitle ) {
@@ -1266,29 +1245,29 @@
12671246 return true;
12681247 }
12691248
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();
12721251 if ( preg_match( "/^$page_namespace:(.*)$/", $ot->getPrefixedText() ) ) {
1273 - $this->load_index( $ot );
 1252+ self::load_index( $ot );
12741253 if( $ot->pr_index_title ) {
12751254 $index_title = Title::newFromText( $ot->pr_index_title );
12761255 $index_title->invalidateCache();
12771256 $index = new Article( $index_title );
12781257 if( $index ) {
1279 - $this->update_pr_index( $index );
 1258+ self::update_pr_index( $index );
12801259 }
12811260 }
12821261 return true;
12831262 }
12841263
12851264 if ( preg_match( "/^$page_namespace:(.*)$/", $nt->getPrefixedText() ) ) {
1286 - $this->load_index( $nt );
 1265+ self::load_index( $nt );
12871266 if( $nt->pr_index_title && ( $nt->pr_index_title != $ot->pr_index_title ) ) {
12881267 $index_title = Title::newFromText( $nt->pr_index_title );
12891268 $index_title->invalidateCache();
12901269 $index = new Article( $index_title );
12911270 if( $index ) {
1292 - $this->update_pr_index( $index );
 1271+ self::update_pr_index( $index );
12931272 }
12941273 }
12951274 return true;
@@ -1299,11 +1278,11 @@
13001279 /**
13011280 * When an index page is created or purged, recompute pr_index values
13021281 */
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();
13061285 if ( preg_match( "/^$index_namespace:(.*)$/", $title->getPrefixedText() ) ) {
1307 - $this->update_pr_index( $article );
 1286+ self::update_pr_index( $article );
13081287 return true;
13091288 }
13101289 return true;
@@ -1315,7 +1294,7 @@
13161295 * @param $cat
13171296 * @return int
13181297 */
1319 - function query_count( $dbr, $query, $cat ) {
 1298+ private static function query_count( $dbr, $query, $cat ) {
13201299 $query['conds']['cl_to'] = str_replace( ' ' , '_' , wfMsgForContent( $cat ) );
13211300 $res = $dbr->select( $query['tables'], $query['fields'], $query['conds'], __METHOD__, array(), $query['joins'] );
13221301
@@ -1331,8 +1310,8 @@
13321311 /**
13331312 * Update the pr_index entry of an article
13341313 */
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();
13371316 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) );
13381317 if ( $page_ns_index == null ) {
13391318 return;
@@ -1346,7 +1325,7 @@
13471326
13481327 // read the list of pages
13491328 $pages = array();
1350 - list( $links, $params, $attributes ) = $this->parse_index( $index_title );
 1329+ list( $links, $params, $attributes ) = self::parse_index( $index_title );
13511330 if( $links == null ) {
13521331 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index_title->getText() );
13531332 if ( $imageTitle ) {
@@ -1398,10 +1377,10 @@
13991378 'joins' => array( 'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ) )
14001379 );
14011380
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' );
14061385 $n1 = $total - $n0 - $n2 - $n3 - $n4;
14071386
14081387 $dbw = wfGetDB( DB_MASTER );
@@ -1416,15 +1395,14 @@
14171396 *
14181397 * @param $out Object: OutputPage object
14191398 */
1420 - function prepareArticle( $out ) {
1421 - global $wgTitle, $wgUser;
 1399+ private static function prepareArticle( $out ) {
 1400+ global $wgUser;
14221401
1423 - $id = $wgTitle->mArticleID;
 1402+ $id = $out->getTitle()->mArticleID;
14241403 if( $id == -1 ) {
14251404 return true;
14261405 }
1427 - $page_namespace = $this->page_namespace;
1428 - $index_namespace = $this->index_namespace;
 1406+ list( $page_namespace, $index_namespace ) = self::getPageAndIndexNamespace();
14291407 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) );
14301408 $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) );
14311409 if( $page_ns_index == null || $index_ns_index == null ) {
@@ -1512,10 +1490,10 @@
15131491 )
15141492 );
15151493
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' );
15201498 // quality1 is the default value
15211499 $n1 = $n - $n0 - $n2 - $n3 - $n4;
15221500 $ne = 0;
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -19,9 +19,6 @@
2020 die( "ProofreadPage extension\n" );
2121 }
2222
23 -$wgExtensionFunctions[] = 'wfProofreadPage';
24 -$wgRunHooks['wgQueryPages'][] = 'wfProofreadPageAddQueryPages';
25 -
2623 $dir = dirname( __FILE__ ) . '/';
2724 $wgExtensionMessagesFiles['ProofreadPage'] = $dir . 'ProofreadPage.i18n.php';
2825 $wgExtensionAliasesFiles['ProofreadPage'] = $dir . 'ProofreadPage.alias.php';
@@ -46,15 +43,6 @@
4744 $wgAutoloadClasses['PagesWithoutScans'] = $dir . 'SpecialPagesWithoutScans.php';
4845 $wgSpecialPages['PagesWithoutScans'] = 'PagesWithoutScans';
4946 $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 -}
5947
6048 # Group allowed to modify pagequality
6149 $wgGroupPermissions['user']['pagequality'] = true;
@@ -96,13 +84,18 @@
9785 ),
9886 );
9987
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';
104102
105 -function wfProofreadPageAddQueryPages( &$wgQueryPages ) {
106 - $wgQueryPages[] = array( 'ProofreadPages', 'IndexPages' );
107 - $wgQueryPages[] = array( 'PagesWithoutScans', 'PagesWithoutScans' );
108 - return true;
109 -}

Sign-offs

UserFlagDate
Aaron Schulzinspected22:15, 29 September 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   22:15, 29 September 2011

I'm not sure I like things becoming static. This mess should probably get more OOP not less.

#Comment by Aaron Schulz (talk | contribs)   20:23, 16 December 2011

This is too hard to revert, so OK'ing and todo tagging since it does work afaik.

Status & tagging log