Page MenuHomePhabricator

Patch for CategoryPage.php: allows resetting limit
Closed, DeclinedPublic

Description

Author: dherding

Description:
Hallo!

The PyWikipedia bot which can be used to handle categories doesn't work anymore
since beta4 because categories are now split up into lists of 200 articles each.

I created this is patch which allows calling URLs like this:

http://en.wikipedia.org/wiki/Category:American_actors?limit=500

to get more articles per page, allowing the bot to work again.

I have tested it on my local wiki, but it's the first patch I submitted for
MediaWiki, and it's the first time I did something with PHP, hope everything is OK.

Daniel

daniel@athene:/tmp/mediawiki/phase3> cvs diff -bud includes/CategoryPage.php

Index: includes/CategoryPage.php

RCS file: /cvsroot/wikipedia/phase3/includes/CategoryPage.php,v
retrieving revision 1.16
diff -b -u -d -r1.16 CategoryPage.php

  • includes/CategoryPage.php 3 Feb 2005 08:44:59 -0000 1.16

+++ includes/CategoryPage.php 16 Feb 2005 18:59:26 -0000
@@ -10,7 +10,6 @@

die();

if( $wgCategoryMagicGallery )

  • /** */ require_once('ImageGallery.php');

    /**

@@ -49,7 +48,8 @@

$pageConditions = array();
$from = $wgRequest->getVal( 'from' );
$until = $wgRequest->getVal( 'until' );
  • $wgOut->addHTML( $this->doCategoryMagic( $from, $until ) );

+ $limit = $wgRequest->getVal( 'limit' );
+ $wgOut->addHTML( $this->doCategoryMagic( $from, $until, $limit ) );

}

/**

@@ -60,7 +60,7 @@

    • @return string HTML output
    • @access private */
  • function doCategoryMagic( $from = '', $until = '' ) {

+ function doCategoryMagic( $from = '', $until = '', $limit = '') {

global $wgContLang,$wgUser, $wgCategoryMagicGallery;
$fname = 'CategoryPage::doCategoryMagic';
wfProfileIn( $fname );

@@ -85,14 +85,16 @@

        $pageCondition = '1';
        $flip = false;
}

+ if ($limit == '') {

$limit = 200;

+ }

$res = $dbr->select(
  • array( 'page', 'categorylinks' ),
  • array( 'page_title', 'page_namespace', 'cl_sortkey' ),

+ array( 'cur', 'categorylinks' ),
+ array( 'cur_title', 'cur_namespace', 'cl_sortkey' ),

array( $pageCondition,
  • 'cl_from = page_id',

+ 'cl_from = cur_id',

'cl_to'           => $this->mTitle->getDBKey(),
  • 'page_is_redirect' => 0),

+ 'cur_is_redirect' => 0),

#+ $pageCondition,
$fname,
array( 'ORDER BY' => $flip ? 'cl_sortkey DESC' :

'cl_sortkey',
@@ -110,7 +112,7 @@

        break;
}
  • $title = Title::makeTitle( $x->page_namespace,

$x->page_title );
+ $title = Title::makeTitle( $x->cur_namespace,
$x->cur_title );

if( $title->getNamespace() == NS_CATEGORY ) {
        // Subcategory; strip the 'Category' namespace

from the link text.
@@ -121,7 +123,7 @@

// Workaround: If sortkey == "Category:".$title,

than use $title for sorting,

// else use sortkey...
if( $title->getPrefixedText() == $x->cl_sortkey ) {
  • array_push( $children_start_char,

$wgContLang->firstChar( $x->page_title ) );
+ array_push( $children_start_char,
$wgContLang->firstChar( $x->cur_title ) );

} else {
        array_push( $children_start_char,

$wgContLang->firstChar( $x->cl_sortkey ) ) ;

}

@@ -311,12 +313,12 @@

$prevLink = htmlspecialchars( wfMsg( 'prevn', $limitText ) );
if( $first != '' ) {
        $prevLink = $sk->makeLinkObj( $title, $prevLink,
  • wfArrayToCGI( $query + array( 'until' => $first

) ) );
+ wfArrayToCGI( $query + array( 'until' => $first,
'limit' => $limit ) ) );

}
$nextLink = htmlspecialchars( wfMsg( 'nextn', $limitText ) );
if( $last != '' ) {
        $nextLink = $sk->makeLinkObj( $title, $nextLink,
  • wfArrayToCGI( $query + array( 'from' => $last ) ) );

+ wfArrayToCGI( $query + array( 'from' => $last,
'limit' => $limit ) ) );

}

return "($prevLink) ($nextLink)";

Version: 1.4.x
Severity: normal
OS: Linux
Platform: PC

Details

Reference
bz1547
TitleReferenceAuthorSource BranchDest Branch
.gitlab-ci.yml: Run terraform plan before running helm-check.pyrepos/releng/gitlab-cloud-runner!363dancymain-Ide1d7e496520cd3855833cede11045801d73edbemain
Pass $ARGS to helm-check.py in .gitlab-ci.ymlrepos/releng/gitlab-cloud-runner!361dancymain-I75caf636ae02c9c3b62428b631b4f05ea6e9c55fmain
helm-check.py: Terraform refresh before collecting outputsrepos/releng/gitlab-cloud-runner!360dancymain-I08897ed57b5036edab0629642ba5952a9054ac64main
Rewrite helm-check in python and Improve handling of helm release status in scriptrepos/releng/gitlab-cloud-runner!359sandeepsmain-I9fdfc32376eb32d4e572328f9247be1628494c39main
Improve handling of helm release status in scriptrepos/releng/gitlab-cloud-runner!357sandeepsmain-Id6e3321224bbd55646da54906b09ff517bc43dbamain
update cluster version prefix to 1.29.repos/releng/gitlab-cloud-runner!347sandeepsmain-I33d916e34956a605583454c64f1ab747772cd5a4main
Return IPs in format user usesrepos/mediawiki/services/ipoid!237stranmain-I1c722ed3a8af28912c035a9fbf86a5596d966548main
Normalize IPv6 IPs to match IPs used by mediawikirepos/mediawiki/services/ipoid!236stranmain-Ic93dab9e6366d822192713c69dab79e2dd53c56emain
Stop running normalize-ipv6 maintenance script during importrepos/mediawiki/services/ipoid!234tchandersremove-maint-scriptmain
Normalize IPv6 IPs already in the database before importsrepos/mediawiki/services/ipoid!231stranmain-Ie4f026f6c0bcffd955a2f069a02e0d00eac4d348main
added function to check cluster exists and validateTerraformState function.repos/releng/gitlab-cloud-runner!342sandeepsmain-I8c5dd376f69a1fdc7d209b620ae16ab19442ee0amain
builds-api: bump to 0.0.130-20240221160838-03b2a120repos/cloud/toolforge/toolforge-deploy!205project_1317_bot_df3177307bed93c3f34e421e26c86e38bump_builds-apimain
envvars-api: bump to 0.0.39-20240221153320-e6de38fdrepos/cloud/toolforge/toolforge-deploy!204project_1317_bot_df3177307bed93c3f34e421e26c86e38bump_envvars-apimain
main.go: fix base urlrepos/cloud/toolforge/envvars-api!24dcarofix_v1_prefixmain
envvars-api: bump to 0.0.38-20240221140654-e441981frepos/cloud/toolforge/toolforge-deploy!202project_1317_bot_df3177307bed93c3f34e421e26c86e38bump_envvars-apimain
api: move the prefix to each endpointrepos/cloud/toolforge/builds-api!79dcaromove_v1_to_urlmain
update output messagerepos/releng/gitlab-cloud-runner!340sandeepsmain-I97956b6e0a545e50c56858adae80c7f7330591bamain
set kubeconfig file permissions to restrict accessrepos/releng/gitlab-cloud-runner!339sandeepsmain-I538990edb491c83fa78b33b878e1ed0dd15ba588main
update base image reference to include helmrepos/releng/gitlab-cloud-runner!338sandeepsmain-Ife6f8bd550d890f24e950d3e1151f21439c14096main
updating gitlab terraform image reference to include helmrepos/releng/gitlab-cloud-runner!337sandeepsmain-I6528e3fdd1fc3080de75e40245dfed6c4a2af82cmain
Show related patches Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 8:15 PM
bzimport set Reference to bz1547.
bzimport added a subscriber: Unknown Object (MLST).

The limit is there for a reason; letting clients arbitrarily increase it would create an abuse vector unnecessarily. You also
should be validating input if you do do something like this.

The bot should be fixed to page correctly, or work in some other way.

Changing all WONTFIX high priority bugs to lowest priority (no mail should be generated since I turned it off for this.)