X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialEditWatchlist.php;h=4d1933f27566251ffcb8f76faa0f801e8cb9c524;hb=803515148a676af3018219887124ea949371b782;hp=68e8703f6d754e850163a4f46296023a25b67b23;hpb=84b6c78550fb9f871f8e3e466ff679b04c3f2a0d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index 68e8703f6d..4d1933f275 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -56,7 +56,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { /** * Main execution point * - * @param $mode int + * @param int $mode */ public function execute( $mode ) { $this->setHeaders(); @@ -93,6 +93,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) ); } break; + case self::EDIT_CLEAR: + $out->setPageTitle( $this->msg( 'watchlistedit-clear-title' ) ); + $form = $this->getClearForm(); + if ( $form->show() ) { + $out->addHTML( $this->successMessage ); + $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) ); + } + break; case self::EDIT_NORMAL: default: @@ -103,6 +111,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) ); } elseif ( $this->toc !== false ) { $out->prependHTML( $this->toc ); + $out->addModules( 'mediawiki.toc' ); } break; } @@ -112,7 +121,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * Extract a list of titles from a blob of text, returning * (prefixed) strings; unwatchable titles are ignored * - * @param $list String + * @param string $list * @return array */ private function extractTitles( $list ) { @@ -190,19 +199,35 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { return true; } + public function submitClear( $data ) { + $current = $this->getWatchlist(); + $this->clearWatchlist(); + $this->getUser()->invalidateCache(); + $this->successMessage = $this->msg( 'watchlistedit-clear-done' )->parse(); + $this->successMessage .= ' ' . $this->msg( 'watchlistedit-clear-removed' ) + ->numParams( count( $current ) )->parse(); + $this->showTitles( $current, $this->successMessage ); + + return true; +} + /** * Print out a list of linked titles * * $titles can be an array of strings or Title objects; the former * is preferred, since Titles are very memory-heavy * - * @param array $titles of strings, or Title objects - * @param $output String + * @param array $titles Array of strings, or Title objects + * @param string $output */ private function showTitles( $titles, &$output ) { $talk = $this->msg( 'talkpagelinktext' )->escaped(); // Do a batch existence check $batch = new LinkBatch(); + if (count($titles) >= 100) { + $output = wfMessage( 'watchlistedit-too-many' )->parse(); + return; + } foreach ( $titles as $title ) { if ( !$title instanceof Title ) { $title = Title::newFromText( $title ); @@ -318,7 +343,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * @param Title $title * @param int $namespace * @param string $dbKey - * @return bool: Whether this item is valid + * @return bool Whether this item is valid */ private function checkTitle( $title, $namespace, $dbKey ) { if ( $title @@ -389,7 +414,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * $titles can be an array of strings or Title objects; the former * is preferred, since Titles are very memory-heavy * - * @param array $titles of strings, or Title objects + * @param array $titles Array of strings, or Title objects */ private function watchTitles( $titles ) { $dbw = wfGetDB( DB_MASTER ); @@ -425,7 +450,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * $titles can be an array of strings or Title objects; the former * is preferred, since Titles are very memory-heavy * - * @param array $titles of strings, or Title objects + * @param array $titles Array of strings, or Title objects */ private function unwatchTitles( $titles ) { $dbw = wfGetDB( DB_MASTER ); @@ -549,7 +574,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { /** * Build the label for a checkbox, with a link to the title, and various additional bits * - * @param $title Title + * @param Title $title * @return string */ private function buildRemoveLine( $title ) { @@ -610,12 +635,31 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { return $form; } + /** + * Get a form for clearing the watchlist + * + * @return HTMLForm + */ + protected function getClearForm() { + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage + $form = new HTMLForm( array(), $context ); + $form->setSubmitTextMsg( 'watchlistedit-clear-submit' ); + # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit' + $form->setSubmitTooltip( 'watchlistedit-clear-submit' ); + $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' ); + $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() ); + $form->setSubmitCallback( array( $this, 'submitClear' ) ); + + return $form; + } + /** * Determine whether we are editing the watchlist, and if so, what * kind of editing operation * - * @param $request WebRequest - * @param $par mixed + * @param WebRequest $request + * @param string $par * @return int */ public static function getMode( $request, $par ) { @@ -624,6 +668,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { switch ( $mode ) { case 'clear': case self::EDIT_CLEAR: + return self::EDIT_CLEAR; case 'raw': case self::EDIT_RAW: return self::EDIT_RAW; @@ -639,7 +684,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { * Build a set of links for convenient navigation * between watchlist viewing and editing modes * - * @param $unused + * @param null $unused * @return string */ public static function buildTools( $unused ) { @@ -650,6 +695,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { 'view' => array( 'Watchlist', false ), 'edit' => array( 'EditWatchlist', false ), 'raw' => array( 'EditWatchlist', 'raw' ), + 'clear' => array( 'EditWatchlist', 'clear' ), ); foreach ( $modes as $mode => $arr ) { @@ -668,10 +714,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } } -# B/C since 1.18 -class WatchlistEditor extends SpecialEditWatchlist { -} - /** * Extend HTMLForm purely so we can have a more sane way of getting the section headers */ @@ -699,7 +741,7 @@ class EditWatchlistCheckboxSeriesField extends HTMLMultiSelectField { * * @param string $value the value the field was submitted with * @param array $alldata the data collected from the form - * @return Mixed Bool true on success, or String error to display. + * @return bool|string Bool true on success, or String error to display. */ function validate( $value, $alldata ) { // Need to call into grandparent to be a good citizen. :)