r69502 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69501‎ | r69502 | r69503 >
Date:12:10, 18 July 2010
Author:ialex
Status:ok
Tags:
Comment:
* Modified Special:Log to extend SpecialPage
* Use FormOptions
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLog.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -591,6 +591,7 @@
592592 'SpecialImport' => 'includes/specials/SpecialImport.php',
593593 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
594594 'SpecialLockdb' => 'includes/specials/SpecialLockdb.php',
 595+ 'SpecialLog' => 'includes/specials/SpecialLog.php',
595596 'SpecialMergeHistory' => 'includes/specials/SpecialMergeHistory.php',
596597 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php',
597598 'SpecialPreferences' => 'includes/specials/SpecialPreferences.php',
Index: trunk/phase3/includes/specials/SpecialLog.php
@@ -19,69 +19,103 @@
2020 */
2121
2222 /**
23 - * @file
 23+ * Implements Special:Log
2424 * @ingroup SpecialPage
2525 */
 26+class SpecialLog extends SpecialPage {
2627
27 -/**
28 - * constructor
29 - */
30 -function wfSpecialLog( $par = '' ) {
31 - global $wgRequest, $wgOut, $wgUser, $wgLogTypes;
 28+ public function __construct() {
 29+ parent::__construct( 'Log' );
 30+ }
3231
33 - # Get parameters
34 - $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
35 - $symsForAll = array( '*', 'all' );
36 - if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) ) ) {
37 - $type = $par;
38 - $user = $wgRequest->getText( 'user' );
39 - } else if ( count( $parms ) == 2 ) {
40 - $type = $parms[0];
41 - $user = $parms[1];
42 - } else {
43 - $type = $wgRequest->getVal( 'type' );
44 - $user = ( $par != '' ) ? $par : $wgRequest->getText( 'user' );
 32+ public function execute( $par ) {
 33+ global $wgRequest;
 34+
 35+ $this->setHeaders();
 36+ $this->outputHeader();
 37+
 38+ $opts = new FormOptions;
 39+ $opts->add( 'type', '' );
 40+ $opts->add( 'user', '' );
 41+ $opts->add( 'page', '' );
 42+ $opts->add( 'pattern', false );
 43+ $opts->add( 'year', null, FormOptions::INTNULL );
 44+ $opts->add( 'month', null, FormOptions::INTNULL );
 45+ $opts->add( 'tagfilter', '' );
 46+ $opts->add( 'offset', '' );
 47+ $opts->add( 'dir', '' );
 48+ $opts->add( 'offender', '' );
 49+
 50+ // Set values
 51+ $opts->fetchValuesFromRequest( $wgRequest );
 52+ if ( $par ) {
 53+ $this->parseParams( $opts, (string)$par );
 54+ }
 55+
 56+ # Don't let the user get stuck with a certain date
 57+ if ( $opts->getValue( 'offset' ) || $opts->getValue( 'dir' ) == 'prev' ) {
 58+ $opts->setValue( 'year', '' );
 59+ $opts->setValue( 'month', '' );
 60+ }
 61+
 62+ # Handle type-specific inputs
 63+ $qc = array();
 64+ if ( $opts->getValue( 'type' ) == 'suppress' ) {
 65+ $offender = User::newFromName( $opts->getValue( 'offender' ), false );
 66+ if ( $offender && $offender->getId() > 0 ) {
 67+ $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
 68+ } elseif ( $offender && IP::isIPAddress( $offender->getName() ) ) {
 69+ $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
 70+ }
 71+ }
 72+
 73+ $this->show( $opts, $qc );
4574 }
46 - $title = $wgRequest->getText( 'page' );
47 - $pattern = $wgRequest->getBool( 'pattern' );
48 - $y = $wgRequest->getIntOrNull( 'year' );
49 - $m = $wgRequest->getIntOrNull( 'month' );
50 - $tagFilter = $wgRequest->getVal( 'tagfilter' );
51 - # Don't let the user get stuck with a certain date
52 - $skip = $wgRequest->getText( 'offset' ) || $wgRequest->getText( 'dir' ) == 'prev';
53 - if( $skip ) {
54 - $y = '';
55 - $m = '';
 75+
 76+ private function parseParams( FormOptions $opts, $par ) {
 77+ global $wgLogTypes;
 78+
 79+ # Get parameters
 80+ $parms = explode( '/', ($par = ( $par !== null ) ? $par : '' ) );
 81+ $symsForAll = array( '*', 'all' );
 82+ if ( $parms[0] != '' && ( in_array( $par, $wgLogTypes ) || in_array( $par, $symsForAll ) ) ) {
 83+ $opts->setValue( 'type', $par );
 84+ } elseif ( count( $parms ) == 2 ) {
 85+ $opts->setValue( 'type', $parms[0] );
 86+ $opts->setValue( 'user', $parms[1] );
 87+ } elseif ( $par != '' ) {
 88+ $opts->setValue( 'user', $par );
 89+ }
5690 }
57 - # Handle type-specific inputs
58 - $qc = array();
59 - if( $type == 'suppress' ) {
60 - $offender = User::newFromName( $wgRequest->getVal('offender'), false );
61 - if( $offender && $offender->getId() > 0 ) {
62 - $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() );
63 - } else if( $offender && IP::isIPAddress( $offender->getName() ) ) {
64 - $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() );
 91+
 92+ private function show( FormOptions $opts, array $extraConds ) {
 93+ global $wgOut, $wgUser;
 94+
 95+ # Create a LogPager item to get the results and a LogEventsList item to format them...
 96+ $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
 97+ $pager = new LogPager( $loglist, $opts->getValue( 'type' ), $opts->getValue( 'user' ),
 98+ $opts->getValue( 'page' ), $opts->getValue( 'pattern' ), $extraConds, $opts->getValue( 'year' ),
 99+ $opts->getValue( 'month' ), $opts->getValue( 'tagfilter' ) );
 100+
 101+ # Set title and add header
 102+ $loglist->showHeader( $pager->getType() );
 103+
 104+ # Show form options
 105+ $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
 106+ $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $opts->getValue( 'tagfilter' ) );
 107+
 108+ # Insert list
 109+ $logBody = $pager->getBody();
 110+ if ( $logBody ) {
 111+ $wgOut->addHTML(
 112+ $pager->getNavigationBar() .
 113+ $loglist->beginLogEventsList() .
 114+ $logBody .
 115+ $loglist->endLogEventsList() .
 116+ $pager->getNavigationBar()
 117+ );
 118+ } else {
 119+ $wgOut->addWikiMsg( 'logempty' );
65120 }
66121 }
67 - # Create a LogPager item to get the results and a LogEventsList item to format them...
68 - $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
69 - $pager = new LogPager( $loglist, $type, $user, $title, $pattern, $qc, $y, $m, $tagFilter );
70 - # Set title and add header
71 - $loglist->showHeader( $pager->getType() );
72 - # Show form options
73 - $loglist->showOptions( $pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(),
74 - $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $tagFilter );
75 - # Insert list
76 - $logBody = $pager->getBody();
77 - if( $logBody ) {
78 - $wgOut->addHTML(
79 - $pager->getNavigationBar() .
80 - $loglist->beginLogEventsList() .
81 - $logBody .
82 - $loglist->endLogEventsList() .
83 - $pager->getNavigationBar()
84 - );
85 - } else {
86 - $wgOut->addWikiMsg( 'logempty' );
87 - }
88122 }
Index: trunk/phase3/includes/SpecialPage.php
@@ -134,7 +134,7 @@
135135
136136 # Recent changes and logs
137137 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
138 - 'Log' => array( 'SpecialPage', 'Log' ),
 138+ 'Log' => 'SpecialLog',
139139 'Watchlist' => array( 'SpecialPage', 'Watchlist' ),
140140 'Newpages' => 'SpecialNewpages',
141141 'Recentchanges' => 'SpecialRecentchanges',

Status & tagging log